diff --git a/192.168.1.242.crt b/192.168.1.242.crt deleted file mode 100644 index caa6b07a..00000000 --- a/192.168.1.242.crt +++ /dev/null @@ -1,21 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDaDCCAlACCQCMa8dYfX0ohTANBgkqhkiG9w0BAQsFADB2MQswCQYDVQQGEwJZ -RzELMAkGA1UECAwCWUcxCzAJBgNVBAcMAllHMQwwCgYDVQQKDANDMkwxCjAIBgNV -BAsMATMxCzAJBgNVBAMMAlNYMSYwJAYJKoZIhvcNAQkBFhdud2VuaS5hdW5nQGNv -ZGUybGFiLmNvbTAeFw0xOTExMjYwNTM0NTNaFw0yMDExMjUwNTM0NTNaMHYxCzAJ -BgNVBAYTAllHMQswCQYDVQQIDAJZRzELMAkGA1UEBwwCWUcxDDAKBgNVBAoMA0My -TDEKMAgGA1UECwwBMzELMAkGA1UEAwwCU1gxJjAkBgkqhkiG9w0BCQEWF253ZW5p -LmF1bmdAY29kZTJsYWIuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC -AQEAzjshIBw0Dnv4nFxBBtDd6TbcIR9GGndM7aKOr8yZBv7qKiRoFr9vtT/M1JZh -MO2G0DxvH9BjR1oVWNuAOBx7JUf9wweZ0ntaYT+kPen66LqTn5gFfCAJ+EAzIvaq -s2zlWB8Opl1kahW3LDLngmJGQPBTXO5UVfZHcxgyEGa4b+KdG9s8xqIC4HpvEOST -JmtZiuk/f/9tD7TqWhLsm/Aaw851/6kNjwZJYLbb/Trw8p04iLyyFl1yxVGQLfKB -uoT9tZizPJwZpxCPcvfk2aea0tO+tzBGvtC0VxIUGmBtsZyexVKj/dRuxYhYhFiT -m+0LXyBVyBU5tnuSlvTTM6Qy+wIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQBUS4G7 -xFFlR7Jy1pru4sBMJk11r1pXjUU4lW8bgR1GYC/truda9JyIYlsnrpb+AkhKC1wT -cDufZs+mciN9u8K0eBSdwcAE+m1mSxa1AZbRLyXb9JxWEYmY53K/ktocQloBM3id -sNZQpsSsqZ4DEuaIzgc3A8C+bQbKi1/P2vo12quzGqebIryvy5QPXpi47ECmSGqW -mIBLhPoy3gzm6PamdY+0z+nKGTdAPS15tTpYsfRA3u54fiavluJYNRV2cFYlGPsS -6YmcQNV1R+ONfjaPCqH24/NNVgeeaKzb6uGIpgOfB2cb8aXjTDVUT0qVgJ3S9M4p -HflFmRqebVXhDDiE ------END CERTIFICATE----- diff --git a/192.168.1.242.key b/192.168.1.242.key deleted file mode 100644 index f47102c2..00000000 --- a/192.168.1.242.key +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDOOyEgHDQOe/ic -XEEG0N3pNtwhH0Yad0ztoo6vzJkG/uoqJGgWv2+1P8zUlmEw7YbQPG8f0GNHWhVY -24A4HHslR/3DB5nSe1phP6Q96froupOfmAV8IAn4QDMi9qqzbOVYHw6mXWRqFbcs -MueCYkZA8FNc7lRV9kdzGDIQZrhv4p0b2zzGogLgem8Q5JMma1mK6T9//20PtOpa -Euyb8BrDznX/qQ2PBklgttv9OvDynTiIvLIWXXLFUZAt8oG6hP21mLM8nBmnEI9y -9+TZp5rS0763MEa+0LRXEhQaYG2xnJ7FUqP91G7FiFiEWJOb7QtfIFXIFTm2e5KW -9NMzpDL7AgMBAAECggEABCQj0iU+1lue7mTb2WswSZKUcQXTvoxOuybcfqM5H27W -/OmmPW6yq40Qa+RpJzZd0qikApuIotIoQ5SEypunzWPYsKXibNuVQQaqIaQlKa81 -b6r50ThDevyvCjCx1NCG+nIFNUoCzi6JcxXCmFeo2Xz574/JmcBMRv9hYfruETEO -g5KvR+bhymaDGgKPoIgro2ar3DjKYMuWwaHJQClx3laYPIgnyGFvmTG/if5UykF4 -oTDnjVYkWqw8XOvsL5WhDBGbTq/f1jB7IjfIt1+pV51synVsa/zGNe3jQstCNBX0 -LK+7k8ub6v3jg2ZU0xx7z+hPuOIwz9HLjVEMfZWZwQKBgQDrSmJfbb7FMrPMKeaU -TEX6+fJRQkfgUdtfx8MK5PytV4WzkHOyJ2ankkpyh5TQG77MUzubfGPmg5nBT2+I -TEZO8rH83nOvMKLmXoPp0TvyBxGt0OqBb6RE+mc5rQmPk4lEtUq+i0L+/fB4RYMe -CZgn8pjuvBi+4oQOiQPSl+SwuQKBgQDgYffroNTn1i3VYNU3DYp9xjSLor7TPdsv -S2Xi5FXaZr9PcXdviBE9siY9KEBuiWVA5Q9Wv8XdBbA26VmEzyf+k7KzMr4Z6k5H -SlqClr4AFes6KYmvP2DrVaUsxlUeDO0saxahEK8PkMYTWbWDTAv0d2YD/mLcesEr -haeCCpyfUwKBgQCVCUDWgYVdE4ifwcq0FLwfBUNgBUPR6wex267Hr9P9WHrwCoe+ -SQbVDezqLscsKuboNbCEBH6i/KjfsZlMFERUrZXgPme4iG4mzadw63+1BpVELBje -dADxUEsiVWDA+Qrx4oO9vihprCAtjppG5HzkkN4eGjbycjiDnHY3Zs8MwQKBgAqS -kyv3GBEUdnRna6R8btoeTLuHn5Y0g+9mjhZyy9jOnpUPs6D9uFI/4q1fCCotLygv -otljj98qNXNg62bmm+vS6ciny21NLQMO7dTZZXp7jenfqy0mv1pXXsENV1VjJonB -Qf+02YrSN4MR5wuYubd7KMNnaSEaZ5+1XH80IM0hAoGBAJfHi94ZzPW2PDQr1GIm -CS0O0cHjQNI2+5Yde2U+WuXh/U2rMyB9iTyImqw/weTVFXS2AiRmss7CBTpIxhCP -1gVoNcRRfU7kmuiBXthgB/BuhSdeh/OQo7e9pKiNqoieMO+j8ocyvbMi8NSUl7pK -P9O47XLOplsft4lXqG6gkn8C ------END PRIVATE KEY----- diff --git a/Dockerfile b/Dockerfile index a3e46f4d..74c726d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,20 @@ -FROM ruby:2.4.1 -RUN apt-get update -qq && apt-get install -y build-essential libmysqlclient-dev libcups2-dev libpq-dev nodejs +FROM ruby:2.5 +RUN apt-get update -qq && apt-get install -y build-essential libmariadb-dev libcups2-dev libpq-dev nodejs tzdata RUN mkdir /sxrestaurant RUN mkdir -p /sxrestaurant/tmp/puma -ENV RAILS_ENV staging -ENV RACK_ENV staging +ENV RAILS_ENV production +ENV RACK_ENV production WORKDIR /sxrestaurant -COPY Gemfile /sxrestaurant/Gemfile -COPY Gemfile.lock /sxrestaurant/Gemfile.lock -RUN bundle install --without development test +#RUN gem install bundler +#COPY Gemfile /sxrestaurant/Gemfile +#COPY Gemfile.lock /sxrestaurant/Gemfile.lock +#RUN bundle install --without development test RUN echo "Asia/Rangoon" > /etc/timezone RUN dpkg-reconfigure -f noninteractive tzdata +RUN date COPY . /sxrestaurant +RUN gem install bundler +#RUN bundle update --bundler +RUN bundle install --without development test RUN bundle exec rake assets:precompile -CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"] \ No newline at end of file +CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"] diff --git a/Dockerfile.backup b/Dockerfile.backup new file mode 100644 index 00000000..a72a1ae4 --- /dev/null +++ b/Dockerfile.backup @@ -0,0 +1,19 @@ +FROM ruby:2.5 +RUN apt-get update -qq && apt-get install -y build-essential libmysqlclient-dev libcups2-dev libpq-dev nodejs +RUN mkdir /sxrestaurant +RUN mkdir -p /sxrestaurant/tmp/puma +ENV RAILS_ENV production +ENV RACK_ENV production +WORKDIR /sxrestaurant +#RUN gem install bundler +#COPY Gemfile /sxrestaurant/Gemfile +#COPY Gemfile.lock /sxrestaurant/Gemfile.lock +#RUN bundle install --without development test +RUN echo "Asia/Rangoon" > /etc/timezone +RUN dpkg-reconfigure -f noninteractive tzdata +COPY . /sxrestaurant +RUN gem install bundler +#RUN bundle update --bundler +RUN bundle install --without development test +RUN bundle exec rake assets:precompile +CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"] diff --git a/Gemfile b/Gemfile index 8c30c9a9..b423167a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,9 @@ source 'https://rubygems.org' -# ruby '2.4.1' + +#ruby '2.5.0' +#ruby '2.5.7' + git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") @@ -40,6 +43,9 @@ gem 'material_icons' gem 'font-awesome-rails', '~> 4.7', '>= 4.7.0.2' gem 'rack-cors' +# Multi-tenancy for shops +gem 'acts_as_tenant' + # image upload gem 'carrierwave', '~> 1.0' gem 'mini_magick' diff --git a/Gemfile.lock b/Gemfile.lock index 3a70c5bd..50647fba 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,6 +46,9 @@ GEM i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + acts_as_tenant (0.4.4) + rails (>= 4.0) + request_store (>= 1.0.5) aescrypt (1.0.0) airbrussh (1.4.0) sshkit (>= 1.6.1, != 1.7.0) @@ -219,6 +222,8 @@ GEM rb-inotify (0.10.0) ffi (~> 1.0) redis (3.3.5) + request_store (1.4.1) + rack (>= 1.4) roo (1.13.2) nokogiri rubyzip @@ -271,8 +276,7 @@ GEM activemodel (>= 5.0) spreadsheet (1.2.5) ruby-ole (>= 1.0) - spring (2.0.2) - activesupport (>= 4.2) + spring (2.1.0) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) @@ -316,6 +320,7 @@ PLATFORMS ruby DEPENDENCIES + acts_as_tenant aescrypt axlsx (= 2.0.1) axlsx_rails diff --git a/README.md b/README.md index 77a25926..54474f5e 100755 --- a/README.md +++ b/README.md @@ -279,6 +279,15 @@ For Food Court Settings On/Off ** '0' means can not use food court and '1' means can use food court ** => settings/lookups => { type:food_court, name: FoodCourt, value:'{0 or 1}' } +For Number Formats + Precision + => settings/lookups => { lookup_type: number_format, name: precision, value: {0..2} } + Delimiter + => settings/lookups => { lookup_type: number_format, name: delimiter, value: { ',', '\u0020', '', ... } + Strip insignificant zeros + => settings/lookups => { lookup_type: number_format, name: strip_insignificant_zeros, + value: {true: => ['1', 't', 'true', 'on', 'y', 'yes'], false: => ['0', 'f', 'false', 'off', 'n', 'no', ...] } + /* Customer Types in lookups */ 1) settings/lookups => { type:customer_type, name: Dinein, value:Dinein } 2) settings/lookups => { type:customer_type, name: Takeaway, value: Takeaway } diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 04ec5626..d94dddb7 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -623,7 +623,7 @@ $(function() { row = "
"+attributes[field]["type"]+"
"; $(value).each(function(i){ - disabled = "" + disabled = "false"; status =""; if(parseInt(jQuery.inArray(value[i], selected_item)) !== -1){ status = "selected-attribute"; @@ -1041,7 +1041,12 @@ $(function() { }else if(result.data == 'OK'){ window.location.href = '/origami/'+type+'/pending_order/' + $('#sale_id').text(); }else{ - window.location.href = "/origami/sale/"+result.data["sale_id"]+"/"+type+"/payment"; + if(result.current_user_role == 'foodcourt_cashier'){ + window.location.href = "/foodcourt/sale/"+result.data["sale_id"]+"/"+type+"/payment"; + } + else{ + window.location.href = "/origami/sale/"+result.data["sale_id"]+"/"+type+"/payment"; + } } } } diff --git a/app/assets/javascripts/custom.js b/app/assets/javascripts/custom.js index 6aeace1e..26e6c151 100644 --- a/app/assets/javascripts/custom.js +++ b/app/assets/javascripts/custom.js @@ -135,7 +135,7 @@ $(document).ready(function() { // var method = $(this).attr('data-method'); // var url = $(this).attr('data-ref'); // var html_text = $(this).siblings( "#delete_text" ).html(); - // //var page = url.substring(url.lastIndexOf('/') + 1); + // //var page = url.substring(url.lastIndexOf('/') + 1); // swal({ // title: "Confirmation", // text: html_text, @@ -147,11 +147,11 @@ $(document).ready(function() { // if (isConfirm) { // $.ajax({ // type: method, - // url: url , - // success: function(data) { + // url: url , + // success: function(data) { // location.href = data.url; // } - // }); + // }); // } else { // swal("Cancelled", "Your imaginary file is safe :)", "error"); // } @@ -167,7 +167,7 @@ $(document).ready(function() { var text = $("#notify_message").attr('data-message'); if (text != null || colorName != null){ - showNotification(colorName, text, placementFrom, placementAlign, animateEnter, animateExit); + showNotification(colorName, text, placementFrom, placementAlign, animateEnter, animateExit); } function showNotification(colorName, text, placementFrom, placementAlign, animateEnter, animateExit) { @@ -222,8 +222,8 @@ function audioPlayBackground(shop_code,audio){ function getOnlineOrderCount(){ var count = 0; //Start Ajax - $.ajax({ - async: false, + $.ajax({ + async: false, type: "GET", url: "/origami/get_order_info", dataType: "json", @@ -234,8 +234,8 @@ function getOnlineOrderCount(){ } } }); - //end Ajax + //end Ajax // alert(count); return count; } -/* online order count*/ \ No newline at end of file +/* online order count*/ diff --git a/app/assets/javascripts/foodcourt.js b/app/assets/javascripts/foodcourt.js new file mode 100644 index 00000000..4febbe86 --- /dev/null +++ b/app/assets/javascripts/foodcourt.js @@ -0,0 +1,186 @@ +//= require jquery +//= require tether +//= require jquery_ujs +//= require bootstrap/js/popper.min +//= require bootstrap/js/bootstrap-material-design.min +//= require momentjs/moment +//= require bootstrap-material-datetimepicker/js/bootstrap-material-datetimepicker +//= require jquery-slimscroll/jquery.slimscroll.js +//= require bootstrap-notify/bootstrap-notify.js +//= require node-waves/waves.js +//= require sweetalert/sweetalert.min.js +//= require fileinput.min +//= require cable +//= require turbolinks +//= require BSBMaterial/turbolink_admin.js +//= require BSBMaterial/demo.js + +/* Constant Varaibles */ +_CREDIT_PAYMENTS_ = "/   CREDIT PAYMENTS"; +_CUSTOMERS_ = "/   CUSTOMERS"; +_DISCOUNTS_ = "/   DISCOUNTS"; +_IN_DUTIES_ = "/   IN DUTIES"; +_JCB_ = "/   JCB PAYMENT"; +_MASTER_ = "/   MASTER PAYMENT"; +_MPU_ = "/   MPU PAYMENT"; +_ALIPAY_ = "/   Alipay"; +_JUNCTIONPAY_ = "/   JunctionPay"; +_PAYMAL_ = "/   PAYMAL"; +_DINGA_ = "/   DINGA PAYMENT"; +_GIFT_VOUCHER_ = "/   GIFT VOUCHER"; +_OTHER_CHARGES_ = "/   CHARGES"; +_OTHER_PAYMENTS_ = "/   OTHER PAYMENT"; +_PAYMENTS_ = "/   PAYMENT"; +_PAYPAR_PAYMENT_ = "/   PAYPAR PAYMENT"; +_COMMISSIONS_ = "/   COMMISSIONS"; +_REDEEM_PAYMENT_ = "/   REDEEM PAYMENT"; +_SALE_EDIT_ = "/   SALE EDIT"; +_SPLIT_BILL_ = "/   SPLIT BILL"; +_UNION_ = "/   UNION PAYMENT"; +_VISA_ = "/   VISA PAYMENT"; +_VOUCHER_ = "/   VOUCHER"; +_SURVEY_ = "/   SURVEY"; +/* Constant Varaibles */ + +$(document).on('turbolinks:load', function() { + + $("#customer_image_path").fileinput({ + previewFileType: "image", + allowedFileExtensions: ["jpg", "gif", "png"], + browseClass: "btn btn-success", + browseLabel: "Pick Image", + browseIcon: " ", + removeClass: "btn btn-danger", + removeLabel: "Delete", + removeIcon: " ", + showUpload: false, + // uploadClass: "btn btn-info", + // uploadLabel: "Upload", + // uploadIcon: " ", + previewTemplates: { + image: '
\n' + + ' {caption}\n' + + '
\n', + } + }); + + $('.datetimepicker').bootstrapMaterialDatePicker({ + format: 'DD-MM-YYYY - HH:mm', + clearButton: true, + weekStart: 1 + }); + + $('.datepicker').bootstrapMaterialDatePicker({ + format: 'DD-MM-YYYY', + clearButton: true, + weekStart: 1, + time: false + }); + + $('.timepicker').bootstrapMaterialDatePicker({ + format: 'HH:mm', + clearButton: true, + date: false + }); + + // For selected order return + var order_status = ""; + order_status = $(".selected-item").children().find(".orders-order-status").text().substr(0,6).trim(); + + + $(document).on('click', '.access_modal', function(event){ + type = $(this).data("type"); + $(".ok").attr("data-action",type); + $('#AccessCodeModal').modal('show'); + }); + + $(document).on('click', '.access_number', function(event){ + if(event.handled !== true) { + var original_value = $('#access_code').val(); + var input_type = $(this).attr("data-type"); + + switch (input_type) { + case 'num': + var input_value = $(this).attr("data-value"); + if (original_value){ + $('#access_code').val(original_value + input_value); + }else{ + $('#access_code').val(original_value + input_value); + } + break; + case 'ok': + var type = $(this).attr("data-action"); + code = $('#access_code').val(); + check_emp_access_code(code,type) + break; + case 'clr': + $('#access_code').val(""); + break; + } + event.handled = true; + } else { + return false; + } + }); +}); + +function setHeaderBreadCrumb(params){ + $("#others_payment").html(params); +} + +//show hide nav bar for webview +function showHideNavbar(webview,page){ + if(webview){ + $("nav.navbar").addClass("hidden"); + $("section").addClass("section-margin"); + $(".page-loader-wrapper").addClass("hidden"); + if(page!=undefined){ + $("#back").hide(); + } + }else{ + $("nav.navbar").removeClass("hidden"); + $("section").removeClass("section-margin"); + $(".page-loader-wrapper").removeClass("hidden"); + if(page!=undefined){ + $("#back").show(); + } + } +} + +function createAccessCode(code) { + localStorage.setItem("access_code",code); +} +function check_emp_access_code(access_code,type) { + var url = "/foodcourt/check_emp_access_code/" + access_code ; + $.ajax({ + type: 'POST', + url: url, + data: {}, + success: function (result) { + if (result.status == true) { + createAccessCode(code); + if (type == "edit") { + var dining_id = $('#dining').text(); + var sale_id = $('#sale_id').text(); + if (dining_id) { + window.location.href = '/foodcourt/table/' + dining_id + "/sale/" + sale_id + "/food_court/edit"; + }else{ + window.location.href = "/foodcourt/table/sale/" + sale_id + "/food_court/edit"; + } + }else if(type == "void"){ + $('#AccessCodeModal').modal('hide'); + $('#voidModal').modal('show'); + }else if(type == "waste") { + waste_and_spoilage("waste") + }else if(type == "spoile") { + waste_and_spoilage("spoile") + }else if(type == "foc"){ + $('#AccessCodeModal').modal('hide'); + $('#focModal').modal('show'); + } + }else{ + swal("Oops",result.message,"warning"); + } + } + }); +} diff --git a/app/assets/stylesheets/foodcourt.scss b/app/assets/stylesheets/foodcourt.scss new file mode 100644 index 00000000..64cc2937 --- /dev/null +++ b/app/assets/stylesheets/foodcourt.scss @@ -0,0 +1,729 @@ +@import "material_icons"; +@import "tether"; +@import "bootstrap/css/bootstrap-material-design.min"; +@import "node-waves/waves"; +@import "animate-css/animate"; +@import "sweetalert/sweetalert.css"; +@import "multi-select/css/multi-select.css"; +@import "bootstrap-material-datetimepicker/css/bootstrap-material-datetimepicker"; +@import "morrisjs/morris"; +@import "BSBMaterial/style"; +@import "BSBMaterial/themes/all-themes"; +@import "reset"; +@import "fileinput.min"; + + +/* Reset */ +.col, .col-1, .col-2, .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-10, .col-11, .col-12, .col-auto, .col-lg, .col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12, .col-lg-auto, .col-md, .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12, .col-md-auto, .col-sm, .col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12, .col-sm-auto, .col-xl, .col-xl-1, .col-xl-2, .col-xl-3, .col-xl-4, .col-xl-5, .col-xl-6, .col-xl-7, .col-xl-8, .col-xl-9, .col-xl-10, .col-xl-11, .col-xl-12, .col-xl-auto { + padding-left: 5px; + padding-right: 5px; +} + +.col-lg-1, .col-md-1, .col-sm-1,col-xl-1{ + padding-left: 1px ; + padding-right: 1px ; +} + +.ls-closed section.content { + margin-left: 5px; +} + +section.content { + margin: 70px 5px 0 225px; +} + +.table { + margin-bottom: 0px; +} + +select.form-control { + height: inherit !important; +} + +.form-horizontal .form-group { + margin-right: 0px !important; +} + +.card-columns { + font-size: 18px !important; +} + +@media (min-width:769px) and (max-width:1024px) { + .btn-block { + font-size: 11px !important; + } +} + +/* End Reset */ + +#back { + padding: 0px 0px 7px 0px; +} + +/* +.order-info { + min-height:300px; + max-height:500px; + overflow:auto +} +*/ + +.others-payment{ + line-height:100px; + text-align:center; + color:white; + width:300px; + height:100px; + font-size:18px; +} + +.orders-table { + cursor: pointer; +} + +.cashier_number{ + width: 33%; + height:58px; + line-height:58px; + text-align:center; + background:#54A5AF; + // float:left; + // margin:2px; + font-size:20px; + color:white; + // cursor:pointer; +} + +.access_number{ + width: 33%; + height:58px; + line-height:58px; + text-align:center; + background:#54A5AF; + // float:left; + // margin:2px; + font-size:20px; + color:white; + // cursor:pointer; +} + +.del_cashier_number{ + opacity:0.6, +} + +.pay{ + width: 86%; + height:174px; + line-height:174px; + text-align:center; + font-size:20px; + color:white; +} + +.move_table{ + width: 100%; + height:74px; + line-height:74px; + text-align:center; + font-size:20px; + color:white; +} + + +.payment{ + height:50px; + line-height:50px; + align:center; + color:white; + font-size:16px; + margin:5px; +} + +.font-12 { + font-size: 12px; +} + +.cash-color{ + background-color:#2196F3; +} + +.credit-color{ + background-color:#FFA500; +} + +.other-payment-color{ + background-color:#795548; +} + +.others-color{ + background-color:#E1BEE7; + height: 30px !important; + line-height: 30px !important; +} + + +.cashier_number:hover{ + background:#A9F5F2; +} + +.action-btn { + white-space: normal !important; + height: 60px; + margin-bottom: 5px; +} + +.radius-btn { + border-radius:5px; + color:#fff; + background-color:red; +} + +.bottom-5 { + margin-bottom: 5px; +} + +.fluid { + width: 100%; +} + +.style2 { + border-top: 3px double #8c8b8b; +} + +.long{ + width:43%; +} + +.sold { + background-color: red; +} + +.paid { + background-color: green; +} + +.selected-item { + color: #fff !important; + background-color: blue !important; +} + +.selected-account { + color: #fff !important; + background-color: blue !important; +} + +.selected-payment { + color: #fff !important; + background-color: blue !important; +} +.payment_btn { + white-space: normal !important; + margin-bottom: 15px; + margin-right: 15px; + color:#fff !important; + # background-color: green !important; +} + +/* Reciept Style */ +#order-charges-table td { + border-top: none !important; +} + +.charges-name { + width: 80%; + text-align: left; +} + +.item-name { + width: 60%; + text-align: left; +} + +.item-attr { + width: 20%; + text-align: right; +} + +.item-attr-edit{ + width: 10%; + text-align: left; +} + +.display-none{ + display: none; +} + +.text-white{ + color: #fff; +} + +/* Colors */ +.purple { + background-color:#7a62d3; +} + +.orange{ + background-color:#FF7F50; +} + +.red { + background-color:#F44336; +} + +.green{ + background-color: #009900; +} + +.orange{ + background-color: #FF8C00; +} + +.blue{ + background-color: blue; +} + +/* End Colors */ + +.left{ + margin-left:1px; +} + +.dtp-date .left{ + margin-left:0px; +} + +.bottom{ + margin-bottom:1px; +} + +/* Discount */ + +.required abbr{ + color: red !important; +} + +.border-top{ + border-top:1px solid #fff; +} + +.border-right{ + border-right:1px solid #fff; +} + +.border-left{ + border-left:1px solid #fff; +} + +#sxModal { + display: none; + overflow: auto; + width: 100%; + height: 100%; + background-color: #000; + background-color: rgba(0,0,0,0.4); + position: fixed; + top: 0; + right: 0; + bottom: 0; + left: 0; + z-index: 1100; +} + +#sxModal-Content { + position: relative; + left: 42%; + top: 30%; + background-color: #32ad1a; + color: #fff; + text-align: center; + width: 200px; + height: 200px; + padding-top: 5%; + border-radius: 100px; + z-index: 1101; +} + +/*Loading gif for payment*/ + +#loading_wrapper{ + position: fixed; + background-color: #C8C8C8 ; + height: 100%; + width: 100%; + left: 0; + opacity: 0.6; + top: 0; + z-index: 9999999; +} + +#loading{ + position: relative; + height: 100%; + width: 100%; + background-image: url('../../../image/loading-ajax.gif'); + background-position: center center; + background-repeat: no-repeat; + opacity: 1; + filter: alpha(opacity=100); /* ie */ + -moz-opacity: 1; /* mozilla */ + +} + +/* For Payment Page */ + +.payment-long { + width:43%; +} + +.payment-left { + margin-left: 20px; +} + +/* End Payment Page */ + +/* Logout Icon */ + +i.logout_icon{ + position: relative; + top: 5px; +} + +/* End Logout Icon */ + +/* Notify */ + +#notify-wrapper { + position: absolute; + top: 55px; + left: 10px; + z-index: 9999; + opacity: 0.8; +} + +[data-notify="container"] { + margin-bottom: 5px !important; + margin-left:5px !important; + position:relative !important; + top: 25% !important; + width: 100% !important; +} + +/* End Notify */ + +/* selected color for split bills */ +.selected-split-item { + color: #fff !important; + background-color: #5DADE2 !important; +} + +/* Start Is Member Modal */ +#is_memberModal .modal-body { + height: 260px !important; +} + +#is_memberModal .btn { + width: 80%; +} + +#is_paymemberModal .modal-body { + height: 150px !important; +} + +#is_paymemberModal .btn { + width: 80%; +} +/* End Is Member Modal */ + +/* Start iframe */ +iframe { + border: none; + overflow: hidden !important; + width: 400px; + height: 550px; +} + +#pdfModal .btn { + width: 150%; + height: 100%; +} + +#receipt_pdf { + height: 400px; +} +/* End iframe */ + +/* section class for webview */ +.section-margin { + margin-top: -50px; +} + +.tax-btn-box { + width: 230px; + height: 80px; +} + +/*Pagination*/ +nav.pagination { + margin:10px; + +} +nav.pagination .current{ + background-color:#1f91f3; + color:#fff; + padding:4px 10px; + margin-top:-4px; +} +nav.pagination .page a,.next a,.last a,.prev a,.first a{ + padding:6.5px 10px; + margin-left: 3px; +} + +nav.pagination .page a:hover, +a:focus { + background-color: #ccc; + text-decoration: none; + +} +nav.pagination .page a:hover, +.first a:hover,.last a:hover,.prev a:hover,.next a:hover{ + background-color: #ccc; + text-decoration: none; + +} + +#oqs_loading_wrapper{ + position: fixed; + background-color: #C8C8C8 ; + height: 100%; + width: 100%; + left: 0; + opacity: 0.6; + top: 0; + z-index: 100; +} +#oqs_loading{ + position: relative; + height: 100%; + width: 100%; + background-image: url('../../../image/loading-ajax.gif'); + background-position: center center; + background-repeat: no-repeat; + opacity: 1; + z-index: 101; + filter: alpha(opacity=100); /* ie */ + -moz-opacity: 1; /* mozilla */ +} +.existing_invoice{ + background-color:#ffab51; + color:#fff; + +} + + +/*----chane font_size (Amount Due && Balance)----*/ +#balance{ + height: 50%; + font-size: 20px; +} + +.amount_balance{ + height: 50%; + font-size: 20px; +} + + +#amount_due{ + height: 50%; + font-size: 20px; +} + +/*customer modal UI */ + .wizard { + background: #f1f1f1; + padding: 10px; + } + .wizard .nav-tabs { + position: relative; + border: 0px; + } + .wizard > div.wizard-inner { + position: relative; + margin: 0 0 0 145px !important; + } + .connecting-line{ + height:12px; + background: #e0e0e0; + position: absolute; + width: 110%; + margin: 0 auto; + left: 0; + right: 0; + top:38%; + z-index: 1; + border-radius: 15px; + } + .active-line{ + height:12px; + background: #e0e0e0; + position: absolute; + width: 5%; + margin: 0 auto; + left: 0; + right: 0; + top:61%; + z-index: 1; + border-radius: 15px !important; + } + .connecting-line a.active{ + background-color: #2ED4E0; + } + .border-right{ + border-radius: 15px 0 0 15px; + } + .border-left{ + border-radius: 0; + } + .wizard .nav-tabs > li { + margin-bottom: -20px; + } + .wizard .nav-tabs > li > a.active > a, .wizard .nav-tabs > li > a.active > a:hover, .wizard .nav-tabs > li > a.active > a:focus { + cursor: default; + border: 0; + color:#2ED4E0; + border-bottom-color: transparent; + } + .wizard .nav-tabs li p{ + padding-top:40px; + font-size: 14px; + text-align: center; + } + .list-inline{ + text-align: center; + } + span.round-tab { + width: 28px; + height: 28px; + line-height: 28px; + display: inline-block; + border-radius: 100px; + background:#DFE3E4; + border: 2px solid #fff; + z-index:1; + position:absolute; + text-align: center; + font-size: 16px; + } + .wizard li > a.active span.round-tab{ + background:#2196F3; + color:white; + border: 1px solid #fff; + } + span.round-tab:hover{ + color: white; + border: 1px solid #fff; + background-color:#2196F3; + } + .wizard .nav-tabs > li { + width: 25%; + } + .wizard .nav-tabs > li a{ + width: 28px; + height: 28px; + margin: 18px auto; + border-radius: 100%; + padding: 0; + color: #777; + } + .wizard .tab-pane { + position: relative; + padding-top: 5px; + border-top: 1px solid #fff; + margin-top: 20px; + } + .next-step:hover, .next-step, .prev-step:hover, .prev-step{ + position: relative; + background-color: #2196F3; + font-size: 14px; + color: #FFFFFF; + } +/*customer modal UI */ + +.payment-btn-box { + width: 130px; + height: 50px; +} + +@media screen and (max-width: 785px) { + section.content{ + margin: 80px 15px 0 225px; + } + + .mbl_view{ + display: none; + } + + .navbar-brand-txt{ + margin-top: -15px; + } + + .toggle_mbl { + text-align: right; + } + + .toggle_mbl img{ + width: 24px; + margin-bottom: 14px; + } + + .toggle_mbl a:hover, a:focus{ + background-color: unset; + } + + .col-mbl-view{ + width: 50%; + } + + .info-box .icon{ + display: none; + } + + .mbl_product_div{ + display: none; + } + + .sidebar .menu{ + top: 10px; + } + + .page-header{ + width: 100% !important; + } + + .ls-closed .bars:after, .ls-closed .bars:before{ + top: 14px; + } + + .mbl_card{ + width: 100% !important; + } + + .mbl_lbl{ + display: none; + } + + .mbl-style{ + padding: 10px 10px; + } + + .m-auto{ + width: 33%; + } + + .online_order{ + text-align: right; + } + + .mbl-right-btn{ + text-align: right; + } +} diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index 0e8ea909..4302d6a4 100755 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -1,11 +1,29 @@ class Api::ApiController < ActionController::API + + + include MultiTenancy include TokenVerification include ActionController::MimeResponds + include ActionView::Rendering - # before_action :lookup_domain + before_action :core_allow helper_method :current_token, :current_login_employee, :get_cashier + def core_allow + headers['Access-Control-Allow-Origin'] = '*' + headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS' + headers['Access-Control-Request-Method'] = '*' + headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization' + end + private + + # ActionView::Rendering override render_to_body breaks render :json, + # resulting in an ActionView::MissingTemplate error. + def render_to_body(options) + _render_to_body_with_renderer(options) || super + end + #this is base api base controller to need to inherit. #all token authentication must be done here #response format must be set to JSON diff --git a/app/controllers/api/authenticate_controller.rb b/app/controllers/api/authenticate_controller.rb index 8816b7af..ba2cf5a8 100755 --- a/app/controllers/api/authenticate_controller.rb +++ b/app/controllers/api/authenticate_controller.rb @@ -1,13 +1,13 @@ class Api::AuthenticateController < Api::ApiController skip_before_action :authenticate - before_action :find_shop + # before_action :find_shop def create emp_id = params[:emp_id] password = params[:password] if emp_id && password - @employee = Employee.login(@shop, emp_id, password) + @employee = Employee.login(emp_id, password) if @employee && @employee.role == "waiter" render json: JSON.generate({:status => true, :session_token => @employee.token_session, :name => @employee.name, :role => @employee.role}) else @@ -67,8 +67,8 @@ class Api::AuthenticateController < Api::ApiController params.permit(:emp_id, :password, :session_token) end - private - def find_shop + private + def find_shop @shop = Shop.find_by_shop_code(params[:shop_code]) end end diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 4c9d5a79..77c188fb 100755 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -2,6 +2,7 @@ class Api::BillController < Api::ApiController #Create invoice based on booking #Output and invoice + def create @status = false @error_message = "Order ID or Booking ID is require to request for a bill." @@ -106,7 +107,7 @@ class Api::BillController < Api::ApiController # unique_code = "ReceiptBillPdf" # #shop detail - # shop_details = Shop.find(1) + # shop_details = @shop # customer= Customer.find(@sale_data.customer_id) # # get member information diff --git a/app/controllers/api/call_waiters_controller.rb b/app/controllers/api/call_waiters_controller.rb index 08edc944..dcb543b7 100644 --- a/app/controllers/api/call_waiters_controller.rb +++ b/app/controllers/api/call_waiters_controller.rb @@ -23,7 +23,6 @@ class Api::CallWaitersController < ActionController::API end ActionCable.server.broadcast "call_waiter_channel",table: @table,time:@time,from: from, shift_ids: shift_ids # get printer info - # @shop = Shop.first unique_code = "CallWaiterPdf" print_settings = PrintSetting.find_by_unique_code(unique_code) printer = Printer::ReceiptPrinter.new(print_settings) diff --git a/app/controllers/api/order_reserve/order_reservation_controller.rb b/app/controllers/api/order_reserve/order_reservation_controller.rb index 32c2192e..f10a00c4 100644 --- a/app/controllers/api/order_reserve/order_reservation_controller.rb +++ b/app/controllers/api/order_reserve/order_reservation_controller.rb @@ -70,7 +70,7 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController order_reservation_id, flag = OrderReservation.addOrderReservationInfo(order_reservation) if !order_reservation_id.nil? && flag - shop = Shop.find_by_id(1) + shop = @shop if !shop.nil? shop_code = shop.shop_code order_audio = DisplayImage.find_by_shop_id_and_name(shop.id, "order_audio") @@ -96,9 +96,6 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController result = { :status => true, :order_reservation_id => order_reservation_id, :message => "Order reservation is already existed!" } end end - - # puts "!!! send doemal ::" - # puts result Rails.logger.debug "send status to doemal" Rails.logger.debug result diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 411fca2c..68d1e32c 100755 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -46,9 +46,7 @@ class Api::OrdersController < Api::ApiController @tax_profile = TaxProfile.where("lower(group_type)='cashier'") # end - # @shop = Shop.first - puts "Hello world" - puts @shop.to_json + # return @shop.to_json end @@ -64,77 +62,89 @@ class Api::OrdersController < Api::ApiController def create Rails.logger.debug "Order Source - " + params[:order_source].to_s Rails.logger.debug "Table ID - " + params[:table_id].to_s + @shop = Shop.find_by_shop_code(params[:shop_code]) + current_shift = ShiftSale.current_shift + if current_shift.nil? + @status = false + @message = "No Current Open Shift for This Employee" + else + current_user =Employee.find(current_shift.employee_id) + if checkin_checkout_time(params[:booking_id]) - if checkin_checkout_time(params[:booking_id]) - - if params[:booking_id].present? - booking = Booking.find(params[:booking_id]) - end - if params[:table_id].present? - if booking.nil? || booking.dining_facility_id.to_i != params[:table_id].to_i - table = DiningFacility.find(params[:table_id]) - booking = table.get_current_booking + if params[:booking_id].present? + booking = Booking.find(params[:booking_id]) + end + if params[:table_id].present? + if booking.nil? || booking.dining_facility_id.to_i != params[:table_id].to_i + table = DiningFacility.find(params[:table_id]) + booking = table.get_current_booking + end end - end - #for extratime - is_extra_time = false - extra_time = '' + #for extratime + is_extra_time = false + extra_time = '' - params[:order_items].each { |i| - i["item_instance_code"] = i["item_instance_code"].downcase.to_s - if i["item_instance_code"].include? "ext" - is_extra_time = true - arr_exts = i["item_instance_code"].split("_") - if arr_exts[1].match(/^(\d)+$/) - time = arr_exts[1].to_i*60*i["quantity"].to_i - extra_time = Time.at(time) + params[:order_items].each { |i| + i["item_instance_code"] = i["item_instance_code"].downcase.to_s + if i["item_instance_code"].include? "ext" + is_extra_time = true + arr_exts = i["item_instance_code"].split("_") + if arr_exts[1].match(/^(\d)+$/) + time = arr_exts[1].to_i*60*i["quantity"].to_i + extra_time = Time.at(time) + end + end + } + #end extra time + + # begin + @order = Order.new + @order.source = params[:order_source] + @order.order_type = params[:order_type] + @order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile + @order.items = params[:order_items] + @order.guest = params[:guest_info] + @order.table_id = params[:table_id] # this is dining facilities's id + @order.new_booking = true + @order.waiters = current_login_employee.name + @order.employee_name = current_login_employee.name + @order.shop_code = @shop.shop_code + @order.is_extra_time = is_extra_time + @order.extra_time = extra_time + + #Create Table Booking or Room Booking + if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved' + @order.new_booking = true + else + @order.new_booking = false + @order.booking_id = booking.booking_id + end + + @status, @booking = @order.generate + if @status && @booking + Order.process_order_queue(@order.order_id,@order.table_id,@order.source) + end + if @order.table_id.to_i > 0 + table = DiningFacility.find(@booking.dining_facility_id) + type = 'order' + from = getCloudDomain #get sub domain in cloud mode + ActionCable.server.broadcast "order_channel",table: table,type:type,from:from + end + # # for parallel order + # remoteIP = "" + # begin + # @status, @booking = @order.generate + # remoteIP = request.remote_ip + # end while request.remote_ip != remoteIP + if current_user.role != "waiter" && params[:create_type] == "create_pay" + if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court') || (@order.source == 'app') + @status, @sale = Sale.request_bill(@order,current_user,current_user) end end - } - #end extra time - - # begin - @order = Order.new - @order.source = params[:order_source] - @order.order_type = params[:order_type] - @order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile - @order.items = params[:order_items] - @order.guest = params[:guest_info] - @order.table_id = params[:table_id] # this is dining facilities's id - @order.new_booking = true - @order.waiters = current_login_employee.name - @order.employee_name = current_login_employee.name - - @order.is_extra_time = is_extra_time - @order.extra_time = extra_time - - #Create Table Booking or Room Booking - if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved' - @order.new_booking = true else - @order.new_booking = false - @order.booking_id = booking.booking_id + return return_json_status_with_code(406, "Checkout time is over!") end - - @status, @booking = @order.generate - if @status && @booking - Order.process_order_queue(@order.order_id,@order.table_id,@order.source) - end - if @order.table_id.to_i > 0 - table = DiningFacility.find(@booking.dining_facility_id) - type = 'order' - from = getCloudDomain #get sub domain in cloud mode - ActionCable.server.broadcast "order_channel",table: table,type:type,from:from - end - # # for parallel order - # remoteIP = "" - # begin - # @status, @booking = @order.generate - # remoteIP = request.remote_ip - # end while request.remote_ip != remoteIP - else - return return_json_status_with_code(406, "Checkout time is over!") end end @@ -150,7 +160,6 @@ class Api::OrdersController < Api::ApiController table = DiningFacility.find(table_id) if table booking = table.get_current_booking - # puts booking if booking if !booking.sale_id.nil? if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new" diff --git a/app/controllers/api/payment/mobilepayment_controller.rb b/app/controllers/api/payment/mobilepayment_controller.rb index 1dd984c4..0c0ca37a 100644 --- a/app/controllers/api/payment/mobilepayment_controller.rb +++ b/app/controllers/api/payment/mobilepayment_controller.rb @@ -14,11 +14,12 @@ class Api::Payment::MobilepaymentController < Api::ApiController saleObj = Sale.find(sale_id) sale_items = SaleItem.get_all_sale_items(sale_id) - # shop_detail = Shop.first + + shop_detail = @shop # rounding adjustment if !path.include? ("credit_payment") - if @shop.is_rounding_adj + if shop_detail.is_rounding_adj a = saleObj.grand_total % 25 # Modulus b = saleObj.grand_total / 25 # Division #not calculate rounding if modulus is 0 and division is even diff --git a/app/controllers/api/payments_controller.rb b/app/controllers/api/payments_controller.rb index 521f58a3..47467026 100755 --- a/app/controllers/api/payments_controller.rb +++ b/app/controllers/api/payments_controller.rb @@ -1,5 +1,5 @@ class Api::PaymentsController < Api::ApiController - + skip_before_action :authenticate #Payment by Invoice ID # Payment Method - [Cash | CreditNote | VISA | MASTER | etc..] @@ -25,9 +25,14 @@ class Api::PaymentsController < Api::ApiController if params[:sale_id] && params[:card_no] sale = Sale.find_by_sale_id(params[:sale_id]) if !sale.nil? + sale_id =sale.sale_id + sale_items = SaleItem.get_all_sale_items(sale_id) + @shop =Shop.find_by_shop_code(sale.shop_code) if sale.sale_status == "new" if !params[:card_no].empty? - @status, @message = send_account_paymal(sale.grand_total, params[:card_no], sale.receipt_no) + current_shift = ShiftSale.current_shift + current_login_employee =Employee.find(current_shift.employee_id) + @status, @message = send_account_paymal(sale.grand_total, params[:card_no], sale.receipt_no,current_login_employee) if @status sale_payment = SalePayment.new status, @sale, @membership_data = sale_payment.process_payment(sale, current_login_employee, sale.grand_total, "paymal",params[:card_no]) @@ -36,9 +41,123 @@ class Api::PaymentsController < Api::ApiController sale_payment = SalePayment.new status = sale_payment.process_payment(sale, current_login_employee, 0, "cash") #card_balance amount for Paymal payment - card_balance_amount = SaleAudit.getCardBalanceAmount(params[:sale_id]) + card_balance_amount, transaction_ref = SaleAudit.getCardBalanceAmount(params[:sale_id]) - render json: JSON.generate({:status => true, :balance_amount => card_balance_amount,:receipt_no => sale.receipt_no, :message => "Payment successful."}) + + rebate_amount = nil + # For Cashier by Zone + bookings = Booking.find_by_sale_id(sale_id) + + shift = ShiftSale.current_open_shift(current_login_employee) + if !shift.nil? + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + else + if bookings.dining_facility_id.to_i > 0 + table = DiningFacility.find(bookings.dining_facility_id) + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + + type = 'payment' + from = getCloudDomain #get sub domain in cloud mode + ActionCable.server.broadcast "order_channel",table: table,type:type,from:from + else + shift = ShiftSale.find(sale.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + end + end + + # For Print + receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf + unique_code = "ReceiptBillPdf" + print_settings = PrintSetting.all + if !print_settings.nil? + print_settings.each do |setting| + if setting.unique_code == 'ReceiptBillPdf' + unique_code = "ReceiptBillPdf" + elsif setting.unique_code == 'ReceiptBillStarPdf' + unique_code = "ReceiptBillStarPdf" + end + end + end + + if !receipt_bill_a5_pdf.empty? + receipt_bill_a5_pdf.each do |receipt_bilA5| + if receipt_bilA5[0] == 'ReceiptBillA5Pdf' + if receipt_bilA5[1] == '1' + unique_code = "ReceiptBillA5Pdf" + # else + + end + end + end + end + + customer= Customer.find(sale.customer_id) + + # get member information + rebate = MembershipSetting.find_by_rebate(1) + credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote') + + if customer.membership_id != nil && rebate && credit_data.nil? + member_info = Customer.get_member_account(customer) + + if member_info["status"] == true + rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no) + current_balance = SaleAudit.paymal_search(sale_id) + end + end + + #orders print out + booking = Booking.find_by_sale_id(sale_id) + if booking.dining_facility_id.to_i>0 + table_id = booking.dining_facility_id + else + table_id = 0 + end + + latest_order = booking.booking_orders.order("order_id DESC").limit(1).first() + if !latest_order.nil? + latest_order_no = latest_order.order_id + end + + booking.booking_orders.each do |order| + # Order.pay_process_order_queue(order.order_id, table_id) + oqs = OrderQueueStation.new + oqs.pay_process_order_queue(order.order_id, table_id) + + assign_order = AssignedOrderItem.assigned_order_item_by_job(order.order_id) + from = getCloudDomain #get sub domain in cloud mode + ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from + end + + + #for card sale data + card_data = Array.new + card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id) + if !card_sale_trans_ref_no.nil? + card_sale_trans_ref_no.each do |cash_sale_trans| + card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s + card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s + card_no = cash_sale_trans.pan.last(4) + card_no = card_no.rjust(19,"**** **** **** ") + card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id}) + end + end + + #card_balance amount for Paymal payment + card_balance_amount,transaction_ref = SaleAudit.getCardBalanceAmount(sale_id) + + # get printer info + print_settings=PrintSetting.find_by_unique_code(unique_code) + # Calculate Food and Beverage Total + item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items) + discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) + other_amount = SaleItem.calculate_other_charges(sale_items) + + printer = Printer::ReceiptPrinter.new(print_settings) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, 'Foodcourt',current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref) + + render json: JSON.generate({:status => true, :balance_amount => card_balance_amount,:receipt_no => sale.receipt_no,:order_no => latest_order_no, :message => "Payment successful."}) else if @membership_data if @membership_data["card_balance_amount"] != "null" @@ -67,15 +186,15 @@ class Api::PaymentsController < Api::ApiController end end - def send_account_paymal(amount, account_no, receipt_no) + def send_account_paymal(amount, account_no, receipt_no,current_login_employee) sale = Sale.find_by_receipt_no(receipt_no) @out = [] action_by = current_login_employee.name @status = true @message = "" - membership_setting = MembershipSetting.find_by_membership_type("paypar_url") + membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",sale.shop_code) if membership_setting.gateway_url - member_actions =MembershipAction.find_by_membership_type("get_account_balance") + member_actions =MembershipAction.find_by_membership_type_and_shop_code("get_account_balance",sale.shop_code) if member_actions.gateway_url @campaign_type_id = nil url = membership_setting.gateway_url.to_s + member_actions.gateway_url.to_s @@ -180,4 +299,13 @@ class Api::PaymentsController < Api::ApiController @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee) end end + #get cloud domain + def getCloudDomain + from = "" + if ENV["SERVER_MODE"] == 'cloud' + from = request.subdomain.to_s + "." + request.domain.to_s + end + + return from + end end diff --git a/app/controllers/api/sound_effect_controller.rb b/app/controllers/api/sound_effect_controller.rb index 97dc3db5..fda3a71d 100644 --- a/app/controllers/api/sound_effect_controller.rb +++ b/app/controllers/api/sound_effect_controller.rb @@ -2,7 +2,7 @@ class Api::SoundEffectController < Api::ApiController #sound effect / alarm api for doemal side calling def sound_effect - shop = Shop.find_by_id(1) + shop = @shop if !shop.nil? shop_code = shop.shop_code order_audio = DisplayImage.find_by_shop_id_and_name(shop.id, "order_audio") diff --git a/app/controllers/api/survey_controller.rb b/app/controllers/api/survey_controller.rb index 1c5e81a2..c82384ce 100644 --- a/app/controllers/api/survey_controller.rb +++ b/app/controllers/api/survey_controller.rb @@ -15,11 +15,7 @@ class Api::SurveyController < Api::ApiController def create dining_facility = DiningFacility.find(params[:id]) - # cashier_zone = CashierTerminalByZone.find_by_zone_id(dining_facility.zone_id) - # shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil) - # puts params.to_json - # set cashier - open_cashier = Employee.where("shop_code='#{@shop.shop_code}' and role = 'cashier' AND token_session <> ''") + open_cashier = Employee.where("role = 'cashier' AND token_session <> ''") current_shift = ShiftSale.current_shift(@shop.shop_code) current_shift_user =Employee.find_by_id(current_shift.employee_id) if open_cashier.count>0 diff --git a/app/controllers/api/verifications_controller.rb b/app/controllers/api/verifications_controller.rb index ba055b88..b53b2bad 100644 --- a/app/controllers/api/verifications_controller.rb +++ b/app/controllers/api/verifications_controller.rb @@ -1,5 +1,5 @@ -class Api::VerificationsController < ActionController::API - +class Api::VerificationsController < Api::ApiController + skip_before_action :authenticate def new phone_number = params[:phone_number] diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c4023b49..716af395 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,5 @@ class ApplicationController < ActionController::Base + include MultiTenancy include LoginVerification #before_action :check_installation @@ -17,5 +18,4 @@ class ApplicationController < ActionController::Base flash[:warning] = exception.message redirect_to root_path end - end diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 1bf5b4d4..1bb0421e 100755 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -1,5 +1,6 @@ class BaseController < ActionController::Base + include MultiTenancy layout "installation" protect_from_forgery with: :exception - + end diff --git a/app/controllers/base_crm_controller.rb b/app/controllers/base_crm_controller.rb index 00b5cf98..275a435d 100755 --- a/app/controllers/base_crm_controller.rb +++ b/app/controllers/base_crm_controller.rb @@ -1,4 +1,7 @@ class BaseCrmController < ActionController::Base + + + include MultiTenancy include LoginVerification layout "CRM" diff --git a/app/controllers/base_foodcourt_controller.rb b/app/controllers/base_foodcourt_controller.rb new file mode 100644 index 00000000..3d28f342 --- /dev/null +++ b/app/controllers/base_foodcourt_controller.rb @@ -0,0 +1,58 @@ +class BaseFoodcourtController < ActionController::Base + include LoginVerification, MultiTenancy + layout "foodcourt" + + before_action :check_user + + #before_action :check_installation + protect_from_forgery with: :exception + + helper_method :current_token + + rescue_from CanCan::AccessDenied do |exception| + flash[:warning] = exception.message + # redirect_to origami_root_path + redirect_to origami_dashboard_path + end + + def check_user + if check_mobile + if current_user.nil? + return render status: 401, json: { + message: "User using other device!" + }.to_json + end + else + if current_user.nil? + redirect_to root_path + end + end + end + + # def checkin_process + # CheckinJob.set(wait: 1.minute).perform_later() + # end + + ##already in LoginVerification + # Get current Cashier + # def get_cashier + # @cashier = Employee.where("role = 'cashier' AND token_session <> ''") + # end + + #check webview + def check_mobile + status = false + authenticate_with_http_token do |token, options| + if token + session[:webview] = true + session[:session_token] = token + end + end + + if session[:webview] && request.user_agent =~ /android|blackberry|iphone|ipad|ipod|iemobile|mobile|webos/i + status = true + end + + return status + end +end diff --git a/app/controllers/base_inventory_controller.rb b/app/controllers/base_inventory_controller.rb index 8ee82777..b591fe85 100755 --- a/app/controllers/base_inventory_controller.rb +++ b/app/controllers/base_inventory_controller.rb @@ -1,4 +1,6 @@ class BaseInventoryController < ActionController::Base + + include MultiTenancy include LoginVerification layout "inventory" diff --git a/app/controllers/base_oqs_controller.rb b/app/controllers/base_oqs_controller.rb index 9b337b69..776f8749 100755 --- a/app/controllers/base_oqs_controller.rb +++ b/app/controllers/base_oqs_controller.rb @@ -1,5 +1,8 @@ class BaseOqsController < ActionController::Base + + include MultiTenancy include LoginVerification + layout "OQS" before_action :check_user diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index 3c362207..a23ba942 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -1,4 +1,6 @@ class BaseOrigamiController < ActionController::Base + + include MultiTenancy include LoginVerification layout "origami" diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb index 0875fda5..021d29c6 100755 --- a/app/controllers/base_report_controller.rb +++ b/app/controllers/base_report_controller.rb @@ -1,11 +1,13 @@ class BaseReportController < ActionController::Base + + include MultiTenancy include LoginVerification - layout "application" + layout "application" - before_action :check_user + before_action :check_user - #before_action :check_installation - protect_from_forgery with: :exception + #before_action :check_installation + protect_from_forgery with: :exception rescue_from CanCan::AccessDenied do |exception| flash[:warning] = exception.message @@ -26,61 +28,51 @@ class BaseReportController < ActionController::Base } def get_date_range_from_params - period_type = params[:period_type] - period = params[:period] - from = params[:from] - to = params[:to] - day_ref = Time.now.utc.getlocal + period_type = params[:period_type] + period = params[:period] - if from.present? && to.present? + if params[:from].present? && params[:to].present? + from = Time.parse(params[:from]) + to = Time.parse(params[:to]) + else + case period.to_i + when PERIOD["today"] + from = Time.now + to = Time.now + when PERIOD["yesterday"] + from = 1.day.ago + to = 1.day.ago + when PERIOD["this_week"] + from = Time.now.beginning_of_week + to = Time.now + when PERIOD["last_week"] + from = 1.week.ago.beginning_of_week + to = 1.week.ago.end_of_week + when PERIOD["last_7"] + from = 7.day.ago + to = Time.now + when PERIOD["this_month"] + from = Time.now.beginning_of_month + to = Time.now + when PERIOD["last_month"] + from = 1.month.ago.beginning_of_month + to = 1.month.ago.end_of_month + when PERIOD["last_30"] + from = 30.day.ago + to = Time.now + when PERIOD["this_year"] + from = Time.now.beginning_of_year + to = Time.now + when PERIOD["last_year"] + from = 1.year.ago.beginning_of_year + to = 1.year.ago.end_of_year + end + end - f_date = DateTime.parse(from) - t_date = DateTime.parse(to) - f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) - t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) - from = f_time.beginning_of_day.utc.getlocal - to = t_time.end_of_day.utc.getlocal + from = from.beginning_of_day + to = to.end_of_day - 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 + return from, to end def check_user diff --git a/app/controllers/base_waiter_controller.rb b/app/controllers/base_waiter_controller.rb index 580de0f9..598b93d6 100755 --- a/app/controllers/base_waiter_controller.rb +++ b/app/controllers/base_waiter_controller.rb @@ -1,5 +1,7 @@ class BaseWaiterController < ActionController::Base - include LoginVerification + + include MultiTenancy + include LoginVerification layout "waiter" before_action :check_user diff --git a/app/controllers/concerns/license_verification.rb b/app/controllers/concerns/license_verification.rb index e28cc28a..a29eaff5 100644 --- a/app/controllers/concerns/license_verification.rb +++ b/app/controllers/concerns/license_verification.rb @@ -56,7 +56,7 @@ module LicenseVerification elsif (flag == 2) flash[:notice] = 'Expiring! Please, License extend...' else - puts "RUN SAY BYAR" + Rails.logger.info "License successed" end end diff --git a/app/controllers/concerns/login_verification.rb b/app/controllers/concerns/login_verification.rb index 4b8f1067..1e3a61bf 100755 --- a/app/controllers/concerns/login_verification.rb +++ b/app/controllers/concerns/login_verification.rb @@ -2,7 +2,7 @@ module LoginVerification extend ActiveSupport::Concern included do before_action :authenticate_session_token - helper_method :current_company,:current_shop, :current_login_employee, :current_user, :get_cashier, :order_reservation, :bank_integration, :shop_detail + helper_method :current_company, :current_shop, :current_login_employee, :current_user, :get_cashier, :order_reservation, :bank_integration, :shop_detail end #this is base api base controller to need to inherit. @@ -18,38 +18,34 @@ module LoginVerification def current_shop begin - shop_code ='262' - @shop =Shop.find_by_shop_code(shop_code) - return @shop + return @shop rescue return nil end end def current_login_employee - @employee = Employee.find_by_token_session_and_shop_code(session[:session_token],@shop.shop_code) + @employee = Employee.find_by_token_session(session[:session_token]) end def current_user - @current_user ||= Employee.find_by_token_session_and_shop_code(session[:session_token],@shop.shop_code) if session[:session_token] + @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] end # Get current Cashiers def get_cashier - @cashier = Employee.where("shop_code='#{@shop.shop_code}' and role = 'cashier' AND token_session <> ''") + @cashier = Employee.where("role = 'cashier' AND token_session <> ''") end #Shop Name in Navbor def shop_detail - shop_code ='262' - @shop = Shop.find_by_shop_code(shop_code) - return @shop + @shop = current_shop end #check order reservation used def order_reservation - order_reserve = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('order_reservation') + order_reserve = Lookup.collection_of('order_reservation') status = false if !order_reserve.empty? order_reserve.each do |order| @@ -65,7 +61,7 @@ module LoginVerification #check bank integration used def bank_integration - bank_integration = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('bank_integration') + bank_integration = Lookup.collection_of('bank_integration') status = false if !bank_integration.empty? bank_integration.each do |bank| @@ -90,8 +86,7 @@ module LoginVerification if (token) #@current_user = User.find_by(api_key: token) #Rails.logger.debug "token - " + token.to_s - - @user =Employee.authenticate_by_token(token,current_shop) + @user = Employee.authenticate_by_token(token) if @user return true #Maybe log - login? diff --git a/app/controllers/concerns/multi_tenancy.rb b/app/controllers/concerns/multi_tenancy.rb new file mode 100644 index 00000000..d5efb2a2 --- /dev/null +++ b/app/controllers/concerns/multi_tenancy.rb @@ -0,0 +1,20 @@ +module MultiTenancy + extend ActiveSupport::Concern + + included do + set_current_tenant_through_filter if respond_to? :set_current_tenant_through_filter + before_action :find_shop_by_subdomain_or_frist if respond_to? :before_action + helper_method :current_shop if respond_to? :helper_method + end + + private + def find_shop_by_subdomain_or_frist + if request.subdomain.present? + shop_code = request.subdomain.partition('-').last + @shop = Shop.find_by(shop_code: shop_code) + else + @shop = Shop.first + end + set_current_tenant(@shop) + end +end diff --git a/app/controllers/concerns/number_formattable.rb b/app/controllers/concerns/number_formattable.rb new file mode 100644 index 00000000..bb022263 --- /dev/null +++ b/app/controllers/concerns/number_formattable.rb @@ -0,0 +1,68 @@ +module NumberFormattable + extend ActiveSupport::Concern + + def precision + return @precision if defined? @precision + @number_formats = Lookup.number_formats if !defined? @number_formats + if @number_formats + @precision = @number_formats.find? { |x| x.name.parameterize.underscore == 'precision'}.value.to_i rescue nil + end + if @precision.nil? + @print_settings = PrintSetting.get_precision_delimiter if !defined? @number_formats + if @print_settings + @precision = @print_settings.precision.to_i + else + @precision = 2 + end + end + end + + def delimiter + return @delimiter if defined? @delimiter + @number_formats = Lookup.number_formats if !defined? @number_formats + if @number_formats + @delimiter = @number_formats.find { |f| f.name.parameterize.underscore == 'delimiter'}.value.gsub(/\\u(\h{4})/) { |m| [$1].pack("H*").unpack("n*").pack("U*") } rescue nil + end + if @delimiter.nil? + @print_settings = PrintSetting.get_precision_delimiter if !defined? @number_formats + if @print_settings && @print_settings.delimiter + @delimiter = "," + else + @delimiter = "," + end + end + end + + def strip_insignificant_zeros + return @strip_insignificant_zeros if defined? @strip_insignificant_zeros + @number_formats = Lookup.number_formats if !defined? @number_formats + if @number_formats + @strip_insignificant_zeros = @number_formats.find { |f| f.name.parameterize.underscore == 'strip_insignificant_zeros'}.value.in? ['1', 't', 'true', 'on', 'y', 'yes'] rescue false + end + end + + def number_format(number, options = {}) + options[:precision] = options[:precision] || precision + # options[:delimiter] = options[:delimiter] || delimiter + options[:strip_insignificant_zeros] = options[:strip_insignificant_zeros] || strip_insignificant_zeros + + number = number.to_f.round(options[:precision]) + + if options[:precision] > 0 + if options[:strip_insignificant_zeros] + formatted = "%.12g" % number + else + formatted = "%.#{options[:precision]}f" % number + end + else + formatted = number.to_i.to_s + end + + if options[:delimiter] && !options[:delimiter].empty? + formatted = formatted.gsub(/(\d)(?=\d{3}+(\.\d*)?$)/, "\\1#{options[:delimiter]}") + end + + return formatted + end + +end diff --git a/app/controllers/concerns/token_verification.rb b/app/controllers/concerns/token_verification.rb index c1bce9b2..ec55b8ec 100755 --- a/app/controllers/concerns/token_verification.rb +++ b/app/controllers/concerns/token_verification.rb @@ -9,18 +9,18 @@ module TokenVerification protected # Authenticate the user with token based authentication - def authenticate + def authenticate authenticate_token || render_unauthorized end def authenticate_token - authenticate_with_http_token do |token, options| + authenticate_with_http_token do |token, options| # Rails.logger.debug "token - " + token.to_s if(options.length !=0 && options["from"] == "DOEMAL") if(ENV["SERVER_MODE"] === "cloud") from = request.subdomain.downcase + "." + request.domain.downcase #"local" aes = MyAesCrypt.new - return aes.checkKeyForAuth(from, token) + return aes.checkKeyForAuth(from, token) end end diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 936ef7a2..9cd67dde 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -83,7 +83,7 @@ class Crm::CustomersController < BaseCrmController @membership_types = Lookup.collection_of("member_group_type") # @taxes = TaxProfile.where(:group_type => 'cashier') - @taxes = TaxProfile.unscoped.select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name") + @taxes = TaxProfile.unscope(:order).select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name") .order("group_type ASC,order_by ASC") @filter = filter @@ -103,11 +103,6 @@ class Crm::CustomersController < BaseCrmController end end end - - # if flash["errors"] - # @crm_customer.valid? - # end - # puts @crm_customers.to_json respond_to do |format| format.html # index.html.erb format.json { render json: @crm_customers } diff --git a/app/controllers/crm/dining_queues_controller.rb b/app/controllers/crm/dining_queues_controller.rb index 28da784a..da0fe6fa 100755 --- a/app/controllers/crm/dining_queues_controller.rb +++ b/app/controllers/crm/dining_queues_controller.rb @@ -6,8 +6,8 @@ class Crm::DiningQueuesController < BaseCrmController # GET /crm/dining_queues.json def index today = DateTime.now.strftime('%Y-%m-%d') - @dining_queues = DiningQueue.where("shop_code='#{@shop.shop_code}' and DATE_FORMAT(created_at,'%Y-%m-%d') = ? and status is NULL ", today).order("queue_no asc") - @complete_queue = DiningQueue.where("shop_code='#{@shop.shop_code}' and DATE_FORMAT(created_at,'%Y-%m-%d') = ? and status = 'Assign' ", today).order("queue_no asc") + @dining_queues = DiningQueue.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and status is NULL ", today).order("queue_no asc") + @complete_queue = DiningQueue.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and status = 'Assign' ", today).order("queue_no asc") if params[:term] @customer = Customer.order(:name).where('lower(name) LIKE ?', "%#{params[:term].downcase}%") @@ -39,7 +39,6 @@ class Crm::DiningQueuesController < BaseCrmController # POST /crm/dining_queues # POST /crm/dining_queues.json def create - puts dining_queue_params @dining_queue = DiningQueue.new(dining_queue_params) @dining_queue.shop_code = @shop.shop_code respond_to do |format| @@ -88,7 +87,7 @@ class Crm::DiningQueuesController < BaseCrmController def assign @queue = DiningQueue.find(params[:id]) - @tables = DiningFacility.where("status = 'available' and shop_code='#{@shop.shop_code}' and type!='HotelRoom'") + @tables = DiningFacility.where("status = 'available' and type!='HotelRoom'") respond_to do |format| format.html # index.html.erb end @@ -109,8 +108,7 @@ class Crm::DiningQueuesController < BaseCrmController :type => type, :checkin_at => Time.now.utc, :customer_id => queue.customer_id, - :booking_status => "assign", - :shop_code => @shop.shop_code}) + :booking_status => "assign"}) booking.save! status = queue.update_attributes(dining_facility_id: table_id,status:"Assign") @@ -139,7 +137,7 @@ class Crm::DiningQueuesController < BaseCrmController private # Use callbacks to share common setup or constraints between actions. def set_dining_queue - @dining_queue = DiningQueue.find_by_id_and_shop_code(params[:id],@shop.shop_code) + @dining_queue = DiningQueue.find_by_id(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. diff --git a/app/controllers/foodcourt/addorders_controller.rb b/app/controllers/foodcourt/addorders_controller.rb new file mode 100755 index 00000000..2af43923 --- /dev/null +++ b/app/controllers/foodcourt/addorders_controller.rb @@ -0,0 +1,309 @@ +class Foodcourt::AddordersController < BaseFoodcourtController + # before_action :set_dining, only: [:detail] + + def index + @webview = false + if check_mobile + @webview = true + end + + @tables = Table.all.active.order('zone_id asc').group("zone_id") + @rooms = Room.all.active.order('zone_id asc').group("zone_id") + @all_table = Table.all.active.order('status desc') + @all_room = Room.all.active.order('status desc') + end + + def detail + @cashier_type = params[:type] + @webview = false + if check_mobile + @webview = true + end + display_type = Lookup.find_by_lookup_type("display_type") + if !display_type.nil? && display_type.value.to_i ==2 + @display_type = display_type.value + else + @display_type = nil + end + @menus = [] + @menu = [] + + @table_id = params[:id] + @table = DiningFacility.find(@table_id) + @booking = @table.get_booking + if @booking + @booking_id = @booking.booking_id + @obj_order = @booking.orders.first + @customer = @obj_order.customer + @date = @obj_order.created_at + @order_items = @booking.order_items + end + end + + def get_menu_category () + if (params[:id]) + + #Pull this menu + @menu = MenuCategory.find_by_id(params[:id]) + + # puts @menu.menu_items[1].item_attributes.to_json + return @menu + else + MenuCategory.current_menu + end + end + + def get_item_instance + @instance = MenuItemInstance.find(params[:id]) + end + + def get_menu() + if (params[:id]) + #Pull this menu + @menu = Menu.find_by_id(params[:id]) + @menu_category = MenuCategory.where("menu_id='#{@menu.id}'").order("order_by asc") + # puts @menu.menu_items[1].item_attributes.to_json + return @menu + else + Menu.current_menu + end + end + + def get_menu_sub_category () + + id = params[:id] + + if (id) + #Pull this menu + @sub_menu = MenuCategory.where("menu_category_id = #{id}").active + + # puts @menu.menu_items[1].item_attributes.to_json + return @sub_menu + end + end + + def get_all_product() + @product = Product.all + end + + def create + if params[:booking_id].present? + booking = Booking.find(params[:booking_id]) + end + if params[:table_id].present? + if booking.nil? || booking.dining_facility_id.to_i != params[:table_id].to_i + table = DiningFacility.find(params[:table_id]) + booking = table.get_current_booking + end + end + + is_extra_time = false + extra_time = '' + + items_arr = [] + JSON.parse(params[:order_items]).each { |i| + i["item_instance_code"] = i["item_instance_code"].downcase.to_s + if i["item_instance_code"].include? "ext" + is_extra_time = true + arr_exts = i["item_instance_code"].split("_") + if arr_exts[1].match(/^(\d)+$/) + time = arr_exts[1].to_i*60*i["quantity"].to_i + extra_time = Time.at(time) + end + end + if i["parent_order_item_id"]; + items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])} + else + items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])} + end + items_arr.push(items) + } + # begin + if params[:order_source] == "quick_service" && params[:table_id].to_i == 0 + customer_id = "CUS-000000000002" # for no customer id from mobile + else + customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile + end + + @order = Order.new + @order.source = params[:order_source] + @order.order_type = params[:order_type] + @order.customer_id = customer_id + @order.items = items_arr + @order.guest = params[:guest_info] + @order.table_id = params[:table_id] # this is dining facilities's id + @order.new_booking = true + @order.waiters = current_login_employee.name + @order.employee_name = current_login_employee.name + @order.shop_code = @shop.shop_code + @order.is_extra_time = is_extra_time + @order.extra_time = extra_time + + if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved' + @order.new_booking = true + else + @order.new_booking = false + @order.booking_id = booking.booking_id + end + + @status, @booking = @order.generate + + if @status && @booking + #send order broadcast to order_channel + if @order.table_id.to_i > 0 + table = DiningFacility.find(@booking.dining_facility_id) + type = 'order' + from = getCloudDomain #get sub domain in cloud mode + ActionCable.server.broadcast "order_channel",table: table,type:type,from:from + + end + + if params[:order_source] != "quick_service" && params[:order_source] != "food_court" + process_order_queue(@order.order_id,@order.table_id,@order.source) + end + end + + # Order.send_customer_view(@booking) + + if current_user.role != "waiter" && params[:create_type] == "create_pay" + if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court') + + @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) + + # for second display + if @order.source == 'quick_service' + from = getCloudDomain #get sub domain in cloud mode + ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale",from:from + end + #end + result = {:status=> @status, :data => @sale ,:current_user_role =>current_user.role} + render :json => result.to_json + end + else + result = {:status=> @status, :data => 0 } + render :json => result.to_json + end + + end + + # render json for http status code + def return_json_status_with_code(code, msg) + render status: code, json: { + message: msg, + booking_id: booking_id + }.to_json + end + + def check_order_with_table(table_id) + table = DiningFacility.find(table_id) + if table + booking = table.get_current_booking + # puts booking + if booking + if !booking.sale_id.nil? + if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new" + @order.new_booking = true + return false + end + else + @order.new_booking = false + @order.booking_id = booking.booking_id + return false + end + end + end + end + + # this can always true + def check_order_with_booking(booking) + if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new" + @order.new_booking = true + return false + else + @order.new_booking = false + @order.booking_id = params[:booking_id] + return false + end + end + + def process_order_queue(order_id,table_id,order_source) + print_status = nil + cup_status = nil + + #Send to background job for processing + order = Order.find(order_id) + sidekiq = Lookup.find_by_lookup_type("sidekiq") + if ENV["SERVER_MODE"] != 'cloud' + cup_status = `#{"sudo service cups status"}` + print_status = check_cup_status(cup_status) + end + + if print_status + if !sidekiq.nil? + OrderQueueProcessorJob.perform_later(order_id, table_id) + else + if order + oqs = OrderQueueStation.new + oqs.process_order(order, table_id, order_source) + end + # assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id) + # ActionCable.server.broadcast "order_queue_station_channel",order: assign_order + end + else + if ENV["SERVER_MODE"] != 'cloud' + cup_start = `#{"sudo service cups start"}` + cup_status = `#{"sudo service cups status"}` + print_status = check_cup_status(cup_status) + end + + if print_status + if !sidekiq.nil? + OrderQueueProcessorJob.perform_later(order_id, table_id) + else + if order + oqs = OrderQueueStation.new + oqs.process_order(order, table_id, order_source) + end + # assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id) + # ActionCable.server.broadcast "order_queue_station_channel",order: assign_order + end + else + if ENV["SERVER_MODE"] != 'cloud' + from = "" + msg = ' Print Error ! Please contact to service' + ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error',from:from + end + if !sidekiq.nil? + OrderQueueProcessorJob.perform_later(order_id, table_id) + else + if order + oqs = OrderQueueStation.new + oqs.process_order(order, table_id, order_source) + end + + from = getCloudDomain #get sub domain in cloud mode + assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id) + ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from + end + end + end + end + + def check_cup_status(status) + if status.include? "Active: active (running)" || "Active: active (exited)" #"Cup Server is already running" + return true + end + return false + end + + #get cloud domain + def getCloudDomain + from = "" + if ENV["SERVER_MODE"] == 'cloud' + from = request.subdomain.to_s + "." + request.domain.to_s + end + + return from + end + +end diff --git a/app/controllers/foodcourt/card_payments_controller.rb b/app/controllers/foodcourt/card_payments_controller.rb new file mode 100755 index 00000000..2c6aa0dd --- /dev/null +++ b/app/controllers/foodcourt/card_payments_controller.rb @@ -0,0 +1,27 @@ +class Foodcourt::CardPaymentsController < BaseFoodcourtController + def index + @membership_rebate_balance = 0 + @membership_id = 0 + if !@membership_id.nil? + membership_setting = MembershipSetting.find_by_membership_type("paypar_url") + membership_data = SalePayment.get_paypar_account(membership_setting.gateway_url,membership_setting.auth_token,@membership_id) + if membership_data["status"]==true + membership_account_data = membership_data["data"]; + membership_account_data.each do |acc_data| + if acc_data["accountable_type"] == "REBATEACCOUNT" + @membership_rebate_balance=acc_data["balance"] + else + @membership_rebate_balance = 0 + end + end + else + @membership_rebate_balance = 0 + end + end + + end + + def create + end + +end diff --git a/app/controllers/foodcourt/cash_ins_controller.rb b/app/controllers/foodcourt/cash_ins_controller.rb new file mode 100755 index 00000000..8700b01f --- /dev/null +++ b/app/controllers/foodcourt/cash_ins_controller.rb @@ -0,0 +1,43 @@ +class Foodcourt::CashInsController < BaseFoodcourtController + def new + end + + def create + reference = params[:reference] + remark = params[:remark] + amount = params[:amount] + payment_method = params[:payment_method] + payment_method_reference = params[:payment_method_reference] + type = params[:type] + + p_jour = PaymentJournal.new + + p_jour.cash_in(reference, remark, amount, payment_method, payment_method_reference, current_user) + shift = ShiftSale.current_open_shift(current_user) + + current_shift = ShiftSale.current_shift(@shop.shop_code) + # set cashier + if shift != nil + shift = shift + else + + open_cashier = Employee.where("role = 'cashier' AND token_session <> ''") + if open_cashier.count>0 + shift = ShiftSale.current_open_shift(open_cashier[0]) + + if shift + emp = Employee.find_by_id(shift.employee_id) + shift = ShiftSale.current_open_shift(emp) + else + shift = ShiftSale.current_open_shift(current_shift) + end + else + # shift = Employee.find(current_shift.employee_id).name + shift =current_shift + end + end + shift.cash_in = shift.cash_in + amount.to_f + shift.save + end + +end diff --git a/app/controllers/foodcourt/cash_outs_controller.rb b/app/controllers/foodcourt/cash_outs_controller.rb new file mode 100755 index 00000000..0ac91af5 --- /dev/null +++ b/app/controllers/foodcourt/cash_outs_controller.rb @@ -0,0 +1,39 @@ +class Foodcourt::CashOutsController < BaseFoodcourtController + def new + end + + def create + reference = params[:reference] + remark = params[:remark] + amount = params[:amount] + p_jour = PaymentJournal.new + p_jour.cash_out(reference, remark, amount, current_user) + shift = ShiftSale.current_open_shift(current_user) + + current_shift = ShiftSale.current_shift(@shop.shop_code) + + # set cashier + if shift != nil + shift = shift + else + open_cashier = Employee.where("role = 'cashier' AND token_session <> ''") + if open_cashier.count>0 + + shift = ShiftSale.current_open_shift(open_cashier[0]) + + if shift + emp = Employee.find_by_id(shift.employee_id) + shift = ShiftSale.current_open_shift(emp) + else + shift = ShiftSale.current_open_shift(current_shift) + end + else + # shift = Employee.find(current_shift.employee_id).name + shift =current_shift + end + end + shift.cash_out = shift.cash_out + amount.to_i + shift.save + end + +end diff --git a/app/controllers/foodcourt/customers_controller.rb b/app/controllers/foodcourt/customers_controller.rb new file mode 100644 index 00000000..316b9837 --- /dev/null +++ b/app/controllers/foodcourt/customers_controller.rb @@ -0,0 +1,193 @@ +class Foodcourt::CustomersController < BaseFoodcourtController + load_and_authorize_resource + def index + end + + # GET /crm/customers/1 + # GET /crm/customers/1.json + def show + end + + def get_customer + filter = params[:filter] + type = params[:type] + + 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.search(filter) + # search account no from paypar + if !@crm_customers.present? && type == "card" + response = Customer.search_paypar_account_no(filter) + if response["status"] == true + @crm_customers = Customer.new + @crm_customers.name = response["customer_data"]["name"] + @crm_customers.contact_no = response["customer_data"]["phone"] + @crm_customers.email = response["customer_data"]["email"] + @crm_customers.date_of_birth = response["customer_data"]["DOB"] + @crm_customers.nrc_no = response["customer_data"]["NRC"] + @crm_customers.address = response["customer_data"]["address"] + @crm_customers.card_no = response["customer_data"]["customer_card_no"] + @crm_customers.paypar_account_no = filter + @crm_customers.membership_id = response["customer_data"]["id"] + @crm_customers.membership_type = response["customer_data"]["member_group_id"] + @crm_customers.customer_type = "Dinein" + @crm_customers.tax_profiles = ["1", "2"] + @crm_customers.save + @crm_customers = Customer.search(filter) + else + @crm_customers = [{"customer_id": response["status"],"message": response["message"] }] + end + end + end + + render :json => @crm_customers.to_json + end + + def add_customer + @webview = false + if check_mobile + @webview = true + end + + @sale_id = params[:sale_id] + @cashier_type = params[:type] + @page = params[:dir_page] + + if(@sale_id[0,3] == "SAL") + @booking = Booking.find_by_sale_id(@sale_id) + if @booking.dining_facility_id.to_i > 0 + @dining_facility = DiningFacility.find(@booking.dining_facility_id) + else + @dining_facility = nil + end + + else + @booking_order = BookingOrder.find_by_order_id(@sale_id) + @booking = Booking.find(@booking_order.booking_id) + if @booking.dining_facility_id.to_i > 0 + @dining_facility = DiningFacility.find(@booking.dining_facility_id) + else + @dining_facility = nil + end + end + + 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.search(filter) + end + #@crm_customers = Customer.all + @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(20) + @crm_customer = Customer.new + @count_customer = Customer.count_customer + + # @taxes = TaxProfile.where(:group_type => 'cashier') + @taxes = TaxProfile.unscoped.select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name") + .order("group_type ASC,order_by ASC") + # if flash["errors"] + # @crm_customer.valid? + # end + @membership_types = Lookup.collection_of("member_group_type") + #get paypar accountno + @paypar_accountno = Customer.where("paypar_account_no IS NOT NULL AND paypar_account_no != ''").pluck("paypar_account_no") + #for create customer on/off + @create_flag = true + lookup_customer = Lookup.collection_of('customer_settings') + if !lookup_customer.empty? + lookup_customer.each do |create_setting| + if create_setting[0].downcase == "create" + if create_setting[1] == '0' && current_login_employee.role == 'cashier' + @create_flag = false + end + end + end + end + + respond_to do |format| + # format.html { render :template => "crm/customers/index" } + format.html { render action: "index"} + format.json { render json: @crm_customers } + end + end + + def update_sale_by_customer + + id = params[:sale_id][0,3] + customer_id = params[:customer_id] + customer = Customer.find(customer_id) + order_source = params[:type] + # Check and find with card no + # if(!customer_id.include? "CUS") + # customer = Customer.find_by_paypar_account_no(customer_id) + # if(customer != nil) + # customer_id = customer.customer_id + # end + # end + + if(id == "SAL") + sale = Sale.find(params[:sale_id]) + status = sale.update_attributes(customer_id: customer_id) + sale.sale_orders.each do |sale_order| + order = Order.find(sale_order.order_id) + status = order.update_attributes(customer_id: customer_id,order_type:customer.customer_type) + end + action_by = current_user.id + remark = "Assign Customer Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} | Customer ID ->#{customer.customer_id}- Customer Name ->#{customer.name}" + sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,sale.cashier_id, action_by,remark,"ASSIGNCUSTOMER" ) + + else + @booking = BookingOrder.find_by_order_id(params[:sale_id]) + @orders = BookingOrder.where("booking_id = ? ", @booking.booking_id) + + @orders.each do |bo| + order = Order.find(bo.order_id) + status = order.update_attributes(customer_id: customer_id,order_type:customer.customer_type) + end + + end + + if status == true + render json: JSON.generate({:status => true}) + if(id == "SAL") + sale.compute_by_sale_items(sale.total_discount, nil, order_source) + end + else + render json: JSON.generate({:status => false, :error_message => "Record not found"}) + end + end + + def send_account + amount = params[:amount] + account_no = params[:account_no] + receipt_no = params[:receipt_no] + sale = Sale.find_by_receipt_no(receipt_no) + @out = [] + action_by = current_user.name + 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 = nil + url = membership_setting.gateway_url.to_s + member_actions.gateway_url.to_s + merchant_uid= member_actions.merchant_account_id + auth_token = member_actions.auth_token.to_s + membership_data = SalePayment.get_paypar_account_data(url,membership_setting.auth_token,merchant_uid,auth_token,account_no,amount,receipt_no) + + if membership_data["status"]==true + remark = "Payment by account no Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} | Transaction ref: #{membership_data[:transaction_ref]} | Reload amount #{membership_data[:reload_amount]} | Old Balance Amount #{membership_data[:old_balance_amount]} | DateTime : #{membership_data[:date]}" + sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,sale.cashier_id, action_by,remark,"PAYBYACCOUNT" ) + else + remark = "Payment by account no Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} | Remark : #{membership_data[:message]}" + sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,sale.cashier_id, action_by,remark,"PAYBYACCOUNT" ) + end + @out = membership_data + render json: JSON.generate({:status => membership_data["status"], :message => membership_data["message"]}) + end + end + end +end diff --git a/app/controllers/foodcourt/dashboard_controller.rb b/app/controllers/foodcourt/dashboard_controller.rb new file mode 100644 index 00000000..6857eab1 --- /dev/null +++ b/app/controllers/foodcourt/dashboard_controller.rb @@ -0,0 +1,121 @@ +class Foodcourt::DashboardController < BaseFoodcourtController + + def index + today = DateTime.now.strftime('%Y-%m-%d') + + @display_type = Lookup.find_by_lookup_type("display_type") + + @sale_data = Array.new + @total_payment_methods = Sale.total_payment_methods(@shop,today,current_user) + 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" || payment.payment_method == "unionpay" || payment.payment_method == "alipay" + pay = Sale.payment_sale(@shop,'card', today, current_user) + @sale_data.push({'card' => pay.payment_amount}) + else + pay = Sale.payment_sale(@shop,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(@shop,today,current_user) + @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(@shop,today,current_user,@from,@to,@from_time,@to_time) + # @total_other_customer = Sale.total_other_customer(today,current_user) + + @total_order = Sale.total_order(@shop,today,current_user) + @total_accounts = Sale.total_account(@shop,today,current_user) + @account_data = Array.new + if !@total_accounts.nil? + @total_accounts.each do |account| + acc = Sale.account_data(@shop,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(@shop,today,current_user) + @total_foc_items = Sale.total_foc_items(@shop,today,current_user) + + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + @current_user = current_user + #dine-in cashier + dinein_cashier = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('dinein_cashier') + @dinein_cashier = 0 + if !dinein_cashier[0].nil? + @dinein_cashier = dinein_cashier[0][1] + end + + #quick service + quick_service = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('quick_service') + @quick_service = 0 + if !quick_service[0].nil? + @quick_service = quick_service[0][1] + end + + #fourt court + food_court = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('food_court') + @food_court = 0 + @food_court_name = nil + if !food_court[0].nil? + @food_court = food_court[0][1] + @food_court_name = food_court[0][0] + end + + #order reservation + order_reservation = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('order_reservation') + @order_reservation = 0 + if !order_reservation.empty? + order_reservation.each do |order_reserve| + if order_reserve[0] == 'OrderReservation' + @order_reservation = order_reserve[1] + end + end + end + + #dashboard settings on/off for supervisor and cashier + dashboard_settings = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('dashboard_settings') + @setting_flag = true + if !dashboard_settings.empty? + dashboard_settings.each do |setting| + if setting[0].to_s.downcase == current_user.role.downcase && setting[1] == '0' + @setting_flag = false + end + end + end + + #reservation + reservation = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('reservation') + @reservation = 0 + if !reservation.empty? + reservation.each do |reserve| + if reserve[0] == 'Reservation' + @reservation = reserve[1] + end + end + end + end + +def get_all_menu + @menus = Menu.includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).active.all + @item_attributes = MenuItemAttribute.all.load + @item_options = MenuItemOption.all.load +end + +def get_credit_sales + credit_sales = SalePayment.get_credit_sales(params,@shop.shop_code) + if !credit_sales.nil? + result = {:status=> true, :data=> credit_sales } + else + result = {:status=> false, :message=>"There is no record." } + end + + render :json => result.to_json +end + +end diff --git a/app/controllers/foodcourt/discounts_controller.rb b/app/controllers/foodcourt/discounts_controller.rb new file mode 100755 index 00000000..5ab25a7a --- /dev/null +++ b/app/controllers/foodcourt/discounts_controller.rb @@ -0,0 +1,336 @@ +class Foodcourt::DiscountsController < BaseFoodcourtController + authorize_resource :class => false + + #discount page show from origami index with selected order + def index + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + @webview = false + if check_mobile + @webview = true + end + + sale_id = params[:id] + @cashier_type = params[:type] + if Sale.exists?(sale_id) + @sale_data = Sale.find(sale_id) + if @sale_data.bookings[0].dining_facility_id.to_i > 0 + @table = DiningFacility.find(@sale_data.bookings[0].dining_facility_id) + else + @table = nil + end + end + + @member_discount = MembershipSetting.find_by_discount(1) + @accounts = Account.where("shop_code='#{@shop.shop_code}'") + end + + #discount page show from origami index with selected order + def create + order_source = params[:cashier_type] + sale_id = params[:sale_id] + discount_items = JSON.parse(params[:discount_items]) + overall_discount = params[:overall_discount] + sub_total = params[:sub_total] + + if Sale.exists?(sale_id) + sale = Sale.find(sale_id) + if sale.bookings[0].dining_facility_id.to_i > 0 + table_id = sale.bookings[0].dining_facility_id + table = DiningFacility.find(table_id) + else + table = nil + table_id = nil + end + + + # sale.total_discount = overall_discount.to_f + # sale.total_amount = sub_total.to_f + # sale.grand_total = (sub_total.to_f - overall_discount.to_f) + sale.total_tax; + # sale.save + if discount_items.length > 0 + + #save sale item for discount + discount_items.each do |di| + origin_sale_item = SaleItem.find(di["id"]) + + sale_item = SaleItem.new + + # if !origin_sale_item.nil? + # menu_category = MenuCategory.get_menu_category(origin_sale_item.product_code) #get menu category for menu items + # if !menu_category.nil? + # sale_item.menu_category_code = menu_category.code + # sale_item.menu_category_name = menu_category.name + # end + # end + + sale_item.menu_category_code = origin_sale_item.menu_category_code + sale_item.menu_category_name = origin_sale_item.menu_category_name + + sale_item.sale_id = sale_id + sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id + sale_item.product_name = di["name"] + sale_item.item_instance_code = origin_sale_item.item_instance_code + sale_item.product_alt_name = "" + sale_item.status = "Discount" + + sale_item.qty = -1 + sale_item.unit_price = di["price"].to_f * -1 + sale_item.taxable_price = di["price"] + sale_item.is_taxable = 1 + sale_item.account_id = origin_sale_item.account_id + + sale_item.price = di["price"] + sale_item.save + + action_by = current_user.name + remark = "Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} " + + sale_audit = SaleAudit.record_audit_discount(sale_item.sale_id,sale.cashier_name, action_by,remark,"ITEMDISCOUNT" ) + + end + end + + # Re-calc All Amount in Sale + if overall_discount.to_f > 0 + action_by = current_user.name + if table.nil? + remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- no Table " + else + remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} " + end + + sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_name, action_by,remark,"OVERALLDISCOUNT" ) + end + sale.compute_by_sale_items(overall_discount.to_f, nil,order_source) + if !table.nil? + result = {:status=> "Success", :table_id => table_id, :table_type => table.type } + else + result = {:status=> "Success" } + end + else + if !table.nil? + result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table.type } + else + result = {:status=> "Please, Check Again!" } + end + end + + + render :json => result.to_json + end + + # Remove selected discount Items + def remove_discount_items + order_source = params[:cashier_type] + sale_id = params[:sale_id] + discount_items = JSON.parse(params[:discount_items]) + if Sale.exists?(sale_id) + sale = Sale.find(sale_id) + if sale.bookings[0].dining_facility_id.to_i > 0 + table_id = sale.bookings[0].dining_facility_id + table = DiningFacility.find(table_id) + else + table_id = nil + table = nil + end + + + if discount_items.length > 0 + #destroy sale item for discount + discount_items.each do |di| + sale_item = SaleItem.find(di["id"]) + sale.total_amount = (sale.total_amount + sale_item.price.abs) + + action_by = current_user.name + if table.nil? + remark = "Remove Item Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} | Table- No Table " + else + remark = "Remove Item Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} | Table- #{table.name} " + end + sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_name, action_by,remark,"REMOVEITEMDISCOUNT" ) + + sale_item.destroy + end + end + + # sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax; + # sale.save + # Re-calc All Amount in Sale + sale.compute_by_sale_items(sale.total_discount, nil, order_source) + if table.nil? + result = {:status=> "Success"} + else + result = {:status=> "Success", :table_id => table_id, :table_type => table.type } + end + + else + if table.nil? + result = {:status=> "Please, Check Again!"} + else + result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table.type } + end + + end + + render :json => result.to_json + end + + # Remove all discount Items + def remove_all_discount + sale_id = params[:id] + order_source = params[:type] + + if Sale.exists?(sale_id) + sale = Sale.find(sale_id) + + if sale.bookings[0].dining_facility_id.to_i > 0 + table_id = sale.bookings[0].dining_facility_id + table = DiningFacility.find(table_id) + table_type = table.type + else + table_id = nil + table = nil + table_type = nil + end + + discount_items = [] + #destroy all discount sale item + sale.sale_items.each do |si| + if si.status == "Discount" && si.price < 0 + sale.total_amount = (sale.total_amount + si.price.abs) + discount_items.push(si) + end + end + + # sale.total_discount = 0 + # sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax; + # sale.save + + #destroy in sale.sale_items + sale.sale_items.destroy(discount_items) + + action_by = current_user.name + if table.nil? + remark = "Remove Discount Sale Id [#{sale.sale_id}]| Receipt No #{sale.receipt_no} | Table- No Table" + else + remark = "Remove Discount Sale Id [#{sale.sale_id}]| Receipt No #{sale.receipt_no} | Table- #{table.name} " + end + sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_name, action_by,remark,"REMOVEALLDISCOUNT" ) + + # Re-calc All Amount in Sale + sale.compute_by_sale_items(0, nil, order_source) + if table.nil? + result = {:status=> "Success"} + else + result = {:status=> "Success", :table_id => table_id, :dining => table.name, :table_type => table_type } + end + + else + if table.nil? + result = {:status=> "Please, Check Again!"} + else + result = {:status=> "Please, Check Again!", :table_id => table_id, :dining => table.name, :table_type => table_type } + end + + end + + render :json => result.to_json + end + + # Member Discount + def member_discount + order_source = params[:cashier_type] + sale_id = params[:sale_id] + is_card = params[:is_card] + sub_total = params[:sub_total] + tax_type = params[:tax_type] + sale = Sale.find(sale_id) + if is_card == 'true' + is_card = true + else is_card.to_s == 'false' + is_card = false + end + # Check for Card Payment + is_card_payment = SalePayment.get_sale_payments_by_card(sale.sale_payments) + + # if is_card != "true" + account_types = Account.where("discount=?",true) + table_id = sale.bookings[0].dining_facility_id + table_type = DiningFacility.find(table_id).type + + # Get Prices for each accounts (eg: food, beverage) + account_price = SaleItem.calculate_price_by_accounts(sale.sale_items) + acc_prices = Array.new; + + account_types.each do |at| + account_price.each do |pc| + if pc[:name] == at.title && pc[:price]>0 + str={type:pc[:name],amount:pc[:price]} + acc_prices.push(str) + end + end + end + generic_customer_id = sale.customer.membership_id + receipt_no = sale.receipt_no + membership = MembershipSetting.find_by_membership_type("paypar_url") + memberaction = MembershipAction.find_by_membership_type("member_discount") + merchant_uid = memberaction.merchant_account_id.to_s + campaign_type_id = memberaction.additional_parameter["campaign_type_id"] + auth_token = memberaction.auth_token.to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + account_no = sale.customer.paypar_account_no rescue nil + + # Check for items for Paypar Cloud + if acc_prices.length > 0 + begin + response = HTTParty.post(url, + :body => { account_no: account_no, + generic_customer_id:generic_customer_id , + campaign_type_id: campaign_type_id, + receipt_no: receipt_no, + merchant_uid:merchant_uid, + campaign_method:acc_prices.to_json, + total_sale_transaction_amount: sale.grand_total, + is_card: is_card, + auth_token:auth_token}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json; version=3' + }, :timeout => 10) + rescue HTTParty::Error + response = {"status": false, "message": "Http party error" } + + rescue Net::OpenTimeout + response = {"status": false, "message": "Connection TIme out " } + rescue OpenURI::HTTPError + response = {"status": false, "message": "Can't open membership server " } + + rescue SocketError + response = {"status": false, "message": "Can't open membership server " } + end + else + response = {"status": false, "message": "You have no selected discount item" } + end + Rails.logger.debug "-------------- Member Discount Osaka ---------" + Rails.logger.debug response.to_json + # Re-calc All Amount in Sale + if response["status"] == true + discount_amount = response["discount_earned"] + if response["discount_bonus_earned"] + discount_amount = discount_amount + response["discount_bonus_earned"] + end + sale.compute_by_sale_items(discount_amount, 'member_discount', order_source, tax_type) + result = {:status=> "Success",:title=>"Member Discount", :table_id => table_id,:table_type => table_type } + elsif response["status"] == "500" + result = {:status=> response["error"],:title=>"Alert", :table_id => table_id,:table_type => table_type } + else + result = {:status=> response["message"],:title=>"Alert", :table_id => table_id,:table_type => table_type } + end + + render :json => result.to_json + + # end #end Is Card Payment + end + +end diff --git a/app/controllers/foodcourt/food_court_controller.rb b/app/controllers/foodcourt/food_court_controller.rb new file mode 100644 index 00000000..f0a35a96 --- /dev/null +++ b/app/controllers/foodcourt/food_court_controller.rb @@ -0,0 +1,207 @@ +class Foodcourt::FoodCourtController < ApplicationController + # before_action :set_dining, only: [:detail] + before_action :check_user + def check_user + if current_user.nil? + redirect_to root_path + end + end + + def index + today = DateTime.now + day = Date.today.wday + # if params[:menu] == "true" + @menus = [] + @menu = [] + # else + # @menus = Menu.all + # @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') + # end + @zone = Zone.all.where("is_active= true") + @customer = Customer.all + @tables = Table.all.active.order('status desc') + @rooms = Room.all.active.order('status desc') + @cashier_type = "food_court" + #checked quick_service only + @quick_service_only = true + lookup_dine_in = Lookup.collection_of('dinein_cashier') + if !lookup_dine_in.empty? + lookup_dine_in.each do |dine_in| + if dine_in[0].downcase == "dineincashier" + if dine_in[1] == '1' + @quick_service_only = false + end + end + end + end + @app_order_new_count = Booking.select("bookings.*,customers.*") + .joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id") + .joins("JOIN orders ON orders.order_id=booking_orders.order_id") + .joins("JOIN order_items ON orders.order_id=order_items.order_id") + .joins("JOIN customers ON orders.customer_id=customers.customer_id") + .where("orders.source='app' and bookings.shop_code='#{@shop.shop_code}' and DATE(bookings.created_at) = '#{Date.today}' and bookings.booking_status='assign'").uniq.length + + render "foodcourt/addorders/detail" + end + + def modify_order + @cashier_type = "food_court" + today = DateTime.now + day = Date.today.wday + # if params[:menu] == "true" + @menus = [] + @menu = [] + # else + # @menus = Menu.all + # @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') + # end + if(params[:id][0,3] == "BKI") + @table_id = nil + @table = nil + @booking = Booking.find(params[:id]) + else + @table_id = params[:id] + @table = DiningFacility.find(@table_id) + @booking = @table.get_booking + end + + @sale_id = @booking.sale_id + + if @booking + @booking_id = @booking.booking_id + @obj_order = @booking.orders.first + @customer = @obj_order.customer + @date = @obj_order.created_at + @order_items = @booking.order_items + end + + render "foodcourt/addorders/detail" + end + + def update_modify_order + booking = Booking.find(params[:booking_id]) + sale = booking.sale + if sale && sale.sale_status != 'new' + render :json => { :status => false } + end + + is_extra_time = false + extra_time = '' + cashier_type = "food_court" + + items_arr = [] + JSON.parse(params[:order_items]).each { |i| + i["item_instance_code"] = i["item_instance_code"].downcase.to_s + if i["item_instance_code"].include? "ext" + is_extra_time = true + arr_exts = i["item_instance_code"].split("_") + if arr_exts[1].match(/^(\d)+$/) + time = arr_exts[1].to_i*60*i["quantity"].to_i + extra_time = Time.at(time) + end + end + if i["parent_order_item_id"] + items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": i["options"]} + else + items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": i["options"]} + end + items_arr.push(items) + } + + # begin + order = Order.new + order.source = params[:order_source] + order.order_type = params[:order_type] + order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile + order.items = items_arr + order.guest = params[:guest_info] + order.table_id = params[:table_id] # this is dining facilities's id + order.waiters = current_login_employee.name + order.employee_name = current_login_employee.name + + order.is_extra_time = is_extra_time + order.extra_time = extra_time + + order.new_booking = false + order.booking_id = booking.booking_id + + if order.generate + if sale + Sale.add_to_existing_pending_invoice(nil, sale.sale_id, booking) + render :json => { :status => true, :data => sale } + else + render :json => { :status => true, :data => 'OK' } + end + else + render :json => { :status => false } + end + + end + + def get_menu_category () + if (params[:id]) + puts params[:id] + #Pull this menu + @menu = MenuCategory.find_by_id(params[:id]) + # puts @menu.menu_items[1].item_attributes.to_json + return @menu + else + MenuCategory.current_menu + end + end + + + def get_menu_sub_category () + id = params[:id] + if (id) + #Pull this menu + @sub_menu = MenuCategory.where("menu_category_id = #{id}").active + # puts @menu.menu_items[1].item_attributes.to_json + return @sub_menu + end + end + + def get_all_product() + @product = Product.where("shop_code='#{@shop.shop_code}'") + end + + # render json for http status code + def return_json_status_with_code(code, msg) + render status: code, json: { + message: msg, + booking_id: booking_id + }.to_json + end + + def check_order_with_table(table_id) + table = DiningFacility.find(table_id) + if table + booking = table.get_current_booking + # puts booking + if booking + if !booking.sale_id.nil? + if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new" + @order.new_booking = true + return false + end + else + @order.new_booking = false + @order.booking_id = booking.booking_id + return false + end + end + end + end + # this can always true + def check_order_with_booking(booking) + if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new" + @order.new_booking = true + return false + else + @order.new_booking = false + @order.booking_id = params[:booking_id] + return false + end + end + +end diff --git a/app/controllers/foodcourt/home_controller.rb b/app/controllers/foodcourt/home_controller.rb new file mode 100755 index 00000000..09b85b16 --- /dev/null +++ b/app/controllers/foodcourt/home_controller.rb @@ -0,0 +1,167 @@ +class Foodcourt::HomeController < BaseFoodcourtController + authorize_resource :class => false + before_action :set_dining, only: [:show] + + def index + @webview = check_mobile + @tables = Table.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') + @rooms = Room.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') + @complete = Sale.completed_sale("cashier",@shop.shop_code) + @orders = Order.includes("sale_orders").where("shop_code='#{@shop.shop_code}' and DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') + + @customers = Customer.pluck("customer_id, name") + @occupied_table = DiningFacility.where("shop_code='#{@shop.shop_code}' and status='occupied'").count + @shift = ShiftSale.current_open_shift(current_user) + end + + # origami table detail + def show + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + @webview = check_mobile + @tables = Table.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') + @rooms = Room.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') + @complete = Sale.completed_sale("cashier",@shop.shop_code) + @orders = Order.includes("sale_orders").where("shop_code='#{@shop.shop_code}' and DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') + @customers = Customer.pluck("customer_id, name") + @shift = ShiftSale.current_open_shift(current_user) + + @status_order = "" + @status_sale = "" + @sale_array = Array.new + + @membership = MembershipSetting.find_by_shop_code(@shop.shop_code) + @payment_methods = PaymentMethodSetting.where("shop_code='#{@shop.shop_code}'") + @dining_booking = @dining.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ") + #@dining_booking = @dining.bookings.active.where("created_at between '#{DateTime.now.utc - 12.hours}' and '#{DateTime.now.utc}'") + @order_items = Array.new + @dining_booking.each do |booking| + if booking.sale_id.nil? && booking.booking_status != 'moved' + @order_items = Array.new + # @assigned_order_items = Array.new + if booking.booking_orders.empty? + @booking = booking + else + booking.booking_orders.each do |booking_order| + order = Order.find(booking_order.order_id) + if (order.status == "new") + @obj_order = order + @customer = order.customer + @date = order.created_at + @booking= booking + order.order_items.each do |item| + @order_items.push(item) + # assigned_order_items = AssignedOrderItem.find_by_item_code_and_instance_code_and_order_id(item.item_code,item.item_instance_code,item.order_id) + # if !assigned_order_items.nil? + # @assigned_order_items.push({item.order_items_id => assigned_order_items.assigned_order_item_id}) + # end + end + @account_arr = Array.new + if @customer.tax_profiles + accounts = @customer.tax_profiles + @account_arr =[] + accounts.each do |acc| + account = TaxProfile.find_by_id(acc) + if !account.nil? + @account_arr.push(account) + end + end + end + end + end + end + @status_order = 'order' + else + sale = Sale.find(booking.sale_id) + if sale.sale_status != "completed" && sale.sale_status != 'void' && sale.sale_status != 'spoile' && sale.sale_status != 'waste' + @sale_array.push(sale) + if @status_order == 'order' + @status_order = 'sale' + end + @booking= booking + @date = sale.created_at + @status_sale = 'sale' + @obj_sale = sale + @customer = sale.customer + accounts = @customer.tax_profiles + @account_arr =[] + accounts.each do |acc| + account = TaxProfile.find_by_id(acc) + if !account.nil? + @account_arr.push(account) + end + end + end + @sale_taxes = [] + sale_taxes = SaleTax.where("sale_id = ?", sale.sale_id) + if !sale_taxes.empty? + sale_taxes.each do |sale_tax| + @sale_taxes.push(sale_tax) + end + end + end + end + + #for bank integration + @checkout_time = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('checkout_time') + @checkout_alert_time = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('checkout_alert_time') + + accounts = TaxProfile.where("shop_code='#{@shop.shop_code}' and group_type = ?","cashier").order("order_by ASC") + @tax_arr =[] + accounts.each do |acc| + @tax_arr.push(acc.name) + end + + lookup_spit_bill = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('split_bill') + @split_bill = 0 + if !lookup_spit_bill[0].nil? + @split_bill = lookup_spit_bill[0][1] + end + + #for edit order on/off + @edit_order_origami = true + lookup_edit_order = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('edit_order') + if !lookup_edit_order.empty? + lookup_edit_order.each do |edit_order| + if edit_order[0].downcase == "editorderorigami" + if edit_order[1] == '0' && (current_login_employee.role == 'cashier' || current_login_employee.role == 'waiter') + @edit_order_origami = false + end + end + end + end + + #for changable on/off + @changable_tax = true + lookup_changable_tax = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('changable_tax') + if !lookup_changable_tax.empty? + lookup_changable_tax.each do |changable_tax| + if changable_tax[0].downcase == "change" + if changable_tax[1] == '0' + @changable_tax = false + end + end + end + end + + end + +def check_emp_access_code + pin_code = params[:code] + employee = Employee.find_by_emp_id(pin_code) + if employee && (employee.role == "manager" || employee.role == "supervisor") + result = {:status=> true, :message=>"Success" } + else + result = {:status=> false, :message=>"Invalid Access Code" } + end + render :json => result.to_json + +end + +private + +def set_dining + @dining = DiningFacility.find(params[:dining_id]) +end + +end diff --git a/app/controllers/foodcourt/orders_controller.rb b/app/controllers/foodcourt/orders_controller.rb new file mode 100755 index 00000000..082e9ab4 --- /dev/null +++ b/app/controllers/foodcourt/orders_controller.rb @@ -0,0 +1,84 @@ +class Foodcourt::OrdersController < BaseFoodcourtController + def show + @webview = false + if check_mobile + @webview = true + end + + @tables = Table.unscoped.all.active.order('status desc') + @rooms = Room.unscoped.all.active.order('status desc') + @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) + @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') + @order = Order.find(params[:order_id]) + booking = Booking.select('bookings.booking_id, bookings.dining_facility_id') + .joins(" JOIN booking_orders as bo on bo.booking_id = bookings.booking_id") + .where("bo.order_id='#{params[:order_id]}'").first() + + @booking = Array.new + if !booking.nil? + if booking.dining_facility_id.to_i > 0 + dining_facilities = DiningFacility.find_by_id(booking.dining_facility_id) + @booking.push({'booking_id' => booking.booking_id, 'dining_facility_id' => booking.dining_facility_id, 'type' => dining_facilities.type}) + else + @booking.push({'booking_id' => booking.booking_id, 'dining_facility_id' => booking.dining_facility_id, 'type' => nil}) + end + + end + @customers = Customer.pluck("customer_id, name") + #for split bill + lookup_spit_bill = Lookup.collection_of('split_bill') + @split_bill = 0 + if !lookup_spit_bill[0].nil? + @split_bill = lookup_spit_bill[0][1] + end + + sale_order = SaleOrder.find_by_order_id(@order.order_id) + if sale_order + unless sale_order.sale_id.nil? + sale = Sale.find(sale_order.sale_id) + @sale_status = sale.sale_status + end + end + + @order.order_items.each_with_index do |item, order_item_index| + if !item.set_menu_items.nil? + instance_item_sets = JSON.parse(item.set_menu_items) + arr_instance_item_sets = Array.new + instance_item_sets.each do |instance_item| + item_instance_name = MenuItemInstance.find_by_item_instance_code(instance_item["item_instance_code"]).item_instance_name + arr_instance_item_sets.push(item_instance_name) + item.price = item.price.to_f + instance_item["price"].to_f + end + @order.order_items[order_item_index].set_menu_items = arr_instance_item_sets + end + end + end + def app_orders + if !params[:booking_id].nil? && !params[:booking_id].blank? + @booking = Booking.select("orders.*,bookings.*,customers.*") + .joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id") + .joins("JOIN orders ON orders.order_id=booking_orders.order_id") + .joins("JOIN customers ON orders.customer_id=customers.customer_id") + .where("orders.source='app' and bookings.booking_id='#{params[:booking_id]}'").first + @customer_id =@booking.customer_id + @booking_id =@booking.booking_id + @order_id =@booking.order_id + @sale_data = Sale.find_by_sale_id(@booking.sale_id) + end + @bookings = Booking.select("bookings.*,customers.*") + .joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id") + .joins("JOIN orders ON orders.order_id=booking_orders.order_id") + .joins("JOIN order_items ON orders.order_id=order_items.order_id") + .joins("JOIN customers ON orders.customer_id=customers.customer_id") + .where("orders.source='app' and bookings.shop_code=? and DATE(bookings.created_at)=?",@shop.shop_code,Date.today).order("bookings.created_at desc").uniq + end + def completed + customer =Customer.find_by_customer_id(params[:customer_id]) + phone_number =customer.contact_no + if Order.send_message(phone_number,params[:order_id],@shop.name) + booking =Booking.find(params[:booking_id]) + booking.booking_status ='completed' + booking.save! + end + end +end diff --git a/app/controllers/foodcourt/other_charges_controller.rb b/app/controllers/foodcourt/other_charges_controller.rb new file mode 100755 index 00000000..c02cb0ca --- /dev/null +++ b/app/controllers/foodcourt/other_charges_controller.rb @@ -0,0 +1,85 @@ +class Foodcourt::OtherChargesController < BaseFoodcourtController + authorize_resource :class => false + + def index + @webview = false + if check_mobile + @webview = true + end + + sale_id = params[:sale_id] + @cashier_type = params[:type] + if Sale.exists?(sale_id) + @sale_data = Sale.find(sale_id) + if @sale_data.bookings[0].dining_facility_id.to_i > 0 + @table = DiningFacility.find(@sale_data.bookings[0].dining_facility_id) + else + @table = nil + end + end + end + + def create + sale_id = params[:sale_id] + other_charges_items = JSON.parse(params[:other_charges_items]) + sub_total = params[:sub_total] + cashier_type = params[:cashier_type] + + if Sale.exists?(sale_id) + sale = Sale.find(sale_id) + if sale.bookings[0].dining_facility_id.to_i > 0 + table_id = sale.bookings[0].dining_facility_id + table = DiningFacility.find(table_id) + else + table_id = nil + table = nil + end + + + # sale.total_amount = sub_total.to_f + # sale.grand_total = sub_total.to_f + sale.total_tax; + # sale.save + if other_charges_items.length > 0 + #save sale item for discount + other_charges_items.each do |di| + # origin_sale_item = SaleItem.find(di["id"]) + sale_item = SaleItem.new + + sale_item.sale_id = sale_id + sale_item.menu_category_code = "0.0" + sale_item.menu_category_name = "Other Charges" + sale_item.product_code = "Other Charges" + sale_item.product_name = "*" + di["name"] + sale_item.product_alt_name = "" + sale_item.status = "Other Charges" + + sale_item.qty = 1 + sale_item.unit_price = di["price"] + sale_item.taxable_price = di["price"] * 1 + sale_item.is_taxable = di["is_taxable"] + sale_item.account_id = 0 + + sale_item.price = di["price"] * 1 + sale_item.save + + action_by = current_user.name + if table.nil? + remark = "Add Other Charges - Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} |Charges ->#{di["price"]} For ->#{di["name"]}- Table ->" + else + remark = "Add Other Charges - Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} |Charges ->#{di["price"]} For ->#{di["name"]}- Table ->#{table.name}" + end + + sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,sale.cashier_name, action_by,remark,"ADDOTHERCHARGES" ) + + end + end + + # Re-calc All Amount in Sale + sale.compute_by_sale_items(sale.total_discount, nil, cashier_type) + end + if !table.nil? + dining = {:table_id => table_id, :table_type => table.type } + render :json => dining.to_json + end + end +end diff --git a/app/controllers/foodcourt/paymal_controller.rb b/app/controllers/foodcourt/paymal_controller.rb new file mode 100644 index 00000000..82deda15 --- /dev/null +++ b/app/controllers/foodcourt/paymal_controller.rb @@ -0,0 +1,98 @@ +class Foodcourt::PaymalController < BaseFoodcourtController + + def index + @sale_id = params[:sale_id] + payment_method = params[:payment_method] + @cashier_type = params[:type] + @membership_rebate_balance=0 + sale_data = Sale.find_by_sale_id(@sale_id) + @receipt_no = sale_data.receipt_no + + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + else + new_total = sale_data.grand_total + end + @rounding_adj = new_total-sale_data.grand_total + # @rounding_adj = sale_data.rounding_adjustment + + @payparcount = 0 + others = 0 + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "paypar" + @payparcount = @payparcount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @payment_prices = sale_data.grand_total - @payparcount -others + + + 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_and_shop_code("paypar_url",@shop.shop_code) + if membership_setting.gateway_url + member_actions =MembershipAction.find_by_membership_type_and_shop_code("get_account_balance",@shop.shop_code) + if member_actions.gateway_url + @campaign_type_id = nil + url = membership_setting.gateway_url.to_s + member_actions.gateway_url.to_s + merchant_uid= member_actions.merchant_account_id + auth_token = member_actions.auth_token.to_s + membership_data = SalePayment.get_paypar_account(url,membership_setting.auth_token,@membership_id,@campaign_type_id,merchant_uid,auth_token) + 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 + +def create + cash = params[:payment_amount] + sale_id = params[:sale_id] + transaction_ref = params[:transaction_ref] + account_no = params[:account_no] + if(Sale.exists?(sale_id)) + saleObj = Sale.find(sale_id) + # shop_details = Shop.first + + # rounding adjustment + # if shop_details.is_rounding_adj + # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) + # rounding_adj = new_total-saleObj.grand_total + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + # end + + # saleObj = Sale.find(sale_id) + sale_payment = SalePayment.new + status, @sale,@membership_data = sale_payment.process_payment(saleObj, current_user, cash, "paymal",account_no) + + if status == true && @membership_data["status"] == true + @out = true, "Success!" + else + @out =false, @membership_data["message"] + end + end + end +end diff --git a/app/controllers/foodcourt/payments_controller.rb b/app/controllers/foodcourt/payments_controller.rb new file mode 100755 index 00000000..3559edc8 --- /dev/null +++ b/app/controllers/foodcourt/payments_controller.rb @@ -0,0 +1,691 @@ +class Foodcourt::PaymentsController < BaseFoodcourtController + authorize_resource :class => false + def index + end + + def create + cash = params[:cash] + sale_id = params[:sale_id] + member_info = nil + type = params[:type] + tax_type = params[:tax_type] + path = request.fullpath + latest_order_no = nil + is_kbz = params[:is_kbz] + + if(Sale.exists?(sale_id)) + saleObj = Sale.find(sale_id) + sale_items = SaleItem.get_all_sale_items(sale_id) + #shop_detail = Shop.first + # rounding adjustment + if !path.include? ("credit_payment") + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(saleObj.grand_total) + rounding_adj = new_total - saleObj.grand_total + saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0 + end + end + #end rounding adjustment + sp = SalePayment.where('sale_id=? and payment_method=? and payment_status=?', sale_id, 'kbzpay', 'paid').last + if is_kbz == 'false' + Rails.logger.info '################ CASH PAYMENT #################' + sale_payment = SalePayment.new + sale_payment.process_payment(saleObj, current_user, cash, "cash") + else + sp.kbz_edit_sale_payment(sp.received_amount.to_f, current_user) + end + + # end + + if !path.include? ("credit_payment") + rebate_amount = nil + # For Cashier by Zone + # bookings = Booking.where("sale_id='#{sale_id}'") + bookings = Booking.find_by_sale_id(sale_id) + + shift = ShiftSale.current_open_shift(current_user) + if !shift.nil? + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + else + if bookings.dining_facility_id.to_i > 0 + table = DiningFacility.find(bookings.dining_facility_id) + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + + type = 'payment' + from = getCloudDomain #get sub domain in cloud mode + ActionCable.server.broadcast "order_channel",table: table,type:type,from:from + else + shift = ShiftSale.find(saleObj.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + end + end + + # For Print + # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf + unique_code = "ReceiptBillPdf" + print_settings = PrintSetting.all + if !print_settings.nil? + print_settings.each do |setting| + if setting.unique_code == 'ReceiptBillPdf' + unique_code = "ReceiptBillPdf" + elsif setting.unique_code == 'ReceiptBillStarPdf' + unique_code = "ReceiptBillStarPdf" + end + end + end + + if !receipt_bill_a5_pdf.empty? + receipt_bill_a5_pdf.each do |receipt_bilA5| + if receipt_bilA5[0] == 'ReceiptBillA5Pdf' + if receipt_bilA5[1] == '1' + unique_code = "ReceiptBillA5Pdf" + # else + + end + end + end + end + + customer= Customer.find(saleObj.customer_id) + + # get member information + rebate = MembershipSetting.find_by_rebate(1) + credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote') + + if customer.membership_id != nil && rebate && credit_data.nil? + member_info = Customer.get_member_account(customer) + + if member_info["status"] == true + rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no) + current_balance = SaleAudit.paymal_search(sale_id) + end + end + + #orders print out + # if type == "quick_service" + booking = Booking.find_by_sale_id(sale_id) + if booking.dining_facility_id.to_i>0 + table_id = booking.dining_facility_id + else + table_id = 0 + end + + latest_order = booking.booking_orders.order("order_id DESC").limit(1).first() + if !latest_order.nil? + latest_order_no = latest_order.order_id + end + + booking.booking_orders.each do |order| + # Order.pay_process_order_queue(order.order_id, table_id) + oqs = OrderQueueStation.new + oqs.pay_process_order_queue(order.order_id, table_id) + + assign_order = AssignedOrderItem.assigned_order_item_by_job(order.order_id) + from = getCloudDomain #get sub domain in cloud mode + ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from + end + + # end + + #for card sale data + card_data = Array.new + card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id) + if !card_sale_trans_ref_no.nil? + card_sale_trans_ref_no.each do |cash_sale_trans| + card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s + card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s + card_no = cash_sale_trans.pan.last(4) + card_no = card_no.rjust(19,"**** **** **** ") + card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id}) + end + end + + #card_balance amount for Paymal payment + card_balance_amount,transaction_ref = SaleAudit.getCardBalanceAmount(sale_id) + + # get printer info + print_settings=PrintSetting.find_by_unique_code(unique_code) + # Calculate Food and Beverage Total + item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items) + discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) + other_amount = SaleItem.calculate_other_charges(sale_items) + + printer = Printer::ReceiptPrinter.new(print_settings) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, 'Foodcourt',current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref) + + #end + end + logger.debug 'saleObj++++++++++++++++++++++++++' + logger.debug saleObj.to_json + if !saleObj.nil? + # InventoryJob.perform_now(self.id) + # InventoryDefinition.calculate_product_count(saleObj) + end + end + + # status, filename, sale_receipt_no, printer_name = Payment.pay(getCloudDomain, cash, sale_id, member_info, type, tax_type, path, latest_order_no, shop_detail, current_user, nil, nil) + render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :printer_name => printer_name}) + end + + def show + display_type = Lookup.find_by_lookup_type("display_type") + if !display_type.nil? && display_type.value.to_i ==2 + @display_type = display_type.value + else + @display_type = nil + end + path = request.fullpath + sale_id = params[:sale_id] + @trans_flag = true + if params[:type] == "transaction" + @trans_flag = false + @cashier_type = "cashier" + else + @cashier_type = params[:type] + end + + if path.include? ("credit_payment") + @sale_payment = SalePayment.get_credit_amount_due_left(sale_id) + end + + @member_discount = MembershipSetting.find_by_discount(1) + @membership_rebate_balance=0 + + if Sale.exists?(sale_id) + @cash = 0.0 + @kbz_pay_amount = 0.0 + @other = 0.0 + @ppamount = 0.0 + @visacount= 0.0 + @jcbcount= 0.0 + @mastercount = 0.0 + @unionpaycount = 0.0 + @alipaycount = 0.0 + @junctionpaycount = 0.0 + @credit = 0.0 + @paymalcount = 0.0 + @dingacount = 0.0 + @giftvouchercount = 0.0 + @sale_data = Sale.find_by_sale_id(sale_id) + @balance = 0 + @accountable_type = '' + @table_no = '' + @dining = '' + @other_payment = 0.0 + @pdf_view = nil + @lookup_pdf = Lookup.find_by_lookup_type("ReceiptPdfView") + if !@lookup_pdf.nil? + @pdf_view = @lookup_pdf.value + end + + amount = SalePayment.get_kbz_pay_amount(sale_id, current_user,@shop) + @kbz_pay_amount += amount.to_f + + #for changable on/off + @changable_tax = true + lookup_changable_tax = Lookup.collection_of('changable_tax') + if !lookup_changable_tax.empty? + lookup_changable_tax.each do |changable_tax| + if changable_tax[0].downcase == "change" + if changable_tax[1] == '0' + @changable_tax = false + end + end + end + end + + # @shop = shop_detail #show shop info + + @customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'") + + saleObj = Sale.find(sale_id) + + #total customer with individual total amount + @individual_total = Array.new + if !saleObj.equal_persons.nil? + per_person_amount = saleObj.grand_total.to_f / saleObj.equal_persons.to_i + @individual_total.push({'total_customer' => saleObj.equal_persons.to_i, 'per_person_amount' => per_person_amount.to_f }) + end + + # rounding adjustment + # if @shop.is_rounding_adj + # a = saleObj.grand_total % 25 # Modulus + # b = saleObj.grand_total / 25 # Division + # #not calculate rounding if modulus is 0 and division is even + # #calculate rounding if modulus is zero or not zero and division are not even + # if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) + # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) + # @rounding_adj = new_total-saleObj.grand_total + # else + # @rounding_adj = @sale_data.rounding_adjustment + # end + # else + # @rounding_adj = @sale_data.rounding_adjustment + # end + #end rounding adjustment + + # rounding adjustment + if @shop.is_rounding_adj + a = saleObj.grand_total % 25 # Modulus + b = saleObj.grand_total / 25 # Division + #not calculate rounding if modulus is 0 and division is even + #calculate rounding if modulus is zero or not zero and division are not even + if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) + new_total = Sale.get_rounding_adjustment(saleObj.grand_total) + @rounding_adj = new_total-saleObj.grand_total + saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:@rounding_adj) + @sale_data.grand_total = new_total + @sale_data.old_grand_total = saleObj.grand_total + @sale_data.rounding_adjustment = @rounding_adj + else + @rounding_adj = @sale_data.rounding_adjustment + end + else + @rounding_adj = @sale_data.rounding_adjustment + end + #end rounding adjustment + + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + + #get customer amount + @customer = Customer.find(@sale_data.customer_id) + # accounts = @customer.tax_profiles + accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC") + @account_arr =[] + @tax_arr =[] + accounts.each do |acc| + account = TaxProfile.find(acc.id) + # @account_arr.push(account) + @tax_arr.push(account.name) + end + sale_taxes = SaleTax.where("sale_id = ?", saleObj.sale_id) + if !sale_taxes.empty? + sale_taxes.each do |sale_tax| + @account_arr.push(sale_tax) + end + end + rebate = MembershipSetting.find_by_rebate(1) + # get member information + if @customer.membership_id != nil && rebate + response = Customer.get_member_account(@customer) + if response["status"]==true + response["account_data"].each do |res| + if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount" + @balance = @balance.to_f + res["balance"].to_f + # @accountable_type = res["accountable_type"] + @accountable_type = "Rebate Balance" + end + end + end + end + + #end customer amount + + #paymal payment + + @sale_data.bookings.each do |sbk| + if sbk.dining_facility_id.to_i >0 + df = DiningFacility.find(sbk.dining_facility_id) + @table_no = df.type + ' ' + df.name + @checkin_time = sbk.checkin_at + @dining = df + break + else + @table_no = nil + @checkin_time = nil + @dining = nil + end + end + + if path.include? ("credit_payment") + @sale_payment_data = SalePayment.get_sale_payment_for_credit(@sale_data) + else + @sale_payment_data = SalePayment.get_sale_payments(@sale_data) + end + @sale_payment_data.each do |spay| + if spay.payment_method == "cash" + @cash += spay.payment_amount + end + if spay.payment_method !="creditnote" + @other_payment += spay.payment_amount + end + + if spay.payment_method == "mpu" + @other += spay.payment_amount + elsif spay.payment_method == "paypar" + @ppamount += spay.payment_amount + elsif spay.payment_method == "visa" + @visacount += spay.payment_amount + elsif spay.payment_method == "jcb" + @jcbcount += spay.payment_amount + elsif spay.payment_method == "master" + @mastercount += spay.payment_amount + elsif spay.payment_method == "unionpay" + @unionpaycount += spay.payment_amount + elsif spay.payment_method == "JunctionPay" + @junctionpaycount += spay.payment_amount + elsif spay.payment_method == "creditnote" + @credit += spay.payment_amount + elsif spay.payment_method == "paymal" + @paymalcount += spay.payment_amount + elsif spay.payment_method == "alipay" + @alipaycount += spay.payment_amount + elsif spay.payment_method == "dinga" + @dingacount += spay.payment_amount + elsif spay.payment_method == "giftvoucher" + @giftvouchercount += spay.payment_amount + end + + end + end + end + + def reprint + sale_id = params[:sale_id] + member_info = nil + latest_order_no = nil + saleObj = Sale.find(sale_id) + + # For Cashier by Zone + bookings = Booking.where("sale_id='#{sale_id}'") + + booking = Booking.find_by_sale_id(sale_id) + latest_order = booking.booking_orders.joins(" JOIN orders ON orders.order_id = booking_orders.order_id").where("orders.source = 'quick_service'").order("order_id DESC").limit(1).first() + if !latest_order.nil? + latest_order_no = latest_order.order_id + end + # if bookings.count > 1 + # # for Multiple Booking + # table = DiningFacility.find(bookings[0].dining_facility_id) + # else + # table = DiningFacility.find(bookings[0].dining_facility_id) + # end + shift = ShiftSale.current_open_shift(current_user) + if !shift.nil? + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + else + if bookings[0].dining_facility_id.to_i > 0 + table = DiningFacility.find(bookings[0].dining_facility_id) + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + else + shift = ShiftSale.find(saleObj.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + end + end + + # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf + unique_code = "ReceiptBillPdf" + if !receipt_bill_a5_pdf.empty? + receipt_bill_a5_pdf.each do |receipt_bilA5| + if receipt_bilA5[0] == 'ReceiptBillA5Pdf' + if receipt_bilA5[1] == '1' + unique_code = "ReceiptBillA5Pdf" + else + unique_code = "ReceiptBillPdf" + end + end + end + end + customer= Customer.find(saleObj.customer_id) + + #shop detail + #shop_detail = Shop.first + # get member information + rebate = MembershipSetting.find_by_rebate(1) + if customer.membership_id != nil && rebate + member_info = Customer.get_member_account(customer) + rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no) + current_balance = SaleAudit.paymal_search(sale_id) + end + + #for card sale data + card_data = Array.new + card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id) + if !card_sale_trans_ref_no.nil? + card_sale_trans_ref_no.each do |cash_sale_trans| + card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s + card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s + card_no = cash_sale_trans.pan.last(4) + card_no = card_no.rjust(19,"**** **** **** ") + card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id}) + end + end + + #card_balance amount for Paymal payment + card_balance_amount,transaction_ref= SaleAudit.getCardBalanceAmount(sale_id) + + # get printer info + print_settings=PrintSetting.find_by_unique_code(unique_code) + + # Calculate price_by_accounts + item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items) + discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) + other_amount = SaleItem.calculate_other_charges(saleObj.sale_items) + + printer = Printer::ReceiptPrinter.new(print_settings) + + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref) + + result = { + :status => true, + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings + } + + # Mobile Print + render :json => result.to_json + # end + end + + def foc + cash = params[:cash] + sale_id = params[:sale_id] + sub_total = params[:sub_total] + remark = params[:remark] + member_info = nil + rebate_amount = nil + current_balance = nil + order_source = params[:type] + + if(Sale.exists?(sale_id)) + saleObj = Sale.find(sale_id) + #calculate cash acmount + cash = saleObj.total_amount + + if saleObj.discount_type == "member_discount" + saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0) + saleObj.compute_by_sale_items(0, nil, order_source) + end + + saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0) + + sale_payment = SalePayment.new + sale_payment.process_payment(saleObj, current_user, cash, "foc" ,remark) + + bookings = Booking.where("sale_id='#{sale_id}'") + if bookings[0].dining_facility_id.to_i > 0 + table = DiningFacility.find(bookings[0].dining_facility_id) + type = 'payment' + from = getCloudDomain #get sub domain in cloud mode + ActionCable.server.broadcast "order_channel",table: table,type:type,from:from + end + + + + # For Cashier by Zone + bookings = Booking.where("sale_id='#{sale_id}'") + + shift = ShiftSale.current_open_shift(current_user) + if !shift.nil? + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + else + if bookings[0].dining_facility_id.to_i > 0 + table = DiningFacility.find(bookings[0].dining_facility_id) + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + else + shift = ShiftSale.find(saleObj.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + end + end + + # Re-call Sale Data + saleObj = Sale.find(sale_id) + + # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + # unique_code = "ReceiptBillPdf" + customer= Customer.find(saleObj.customer_id) + + #shop detail + #shop_detail = Shop.first + printer = PrintSetting.where("shop_code='#{@shop.shop_code}'") + + unique_code="ReceiptBillPdf" + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'ReceiptBillPdf' + unique_code="ReceiptBillPdf" + elsif printer_setting.unique_code == 'ReceiptBillA5Pdf' + unique_code="ReceiptBillA5Pdf" + elsif printer_setting.unique_code == 'ReceiptBillStarPdf' + unique_code="ReceiptBillStarPdf" + end + end + end + # get printer info + print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code) + # Calculate Food and Beverage Total + item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items) + discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) + + other_amount = SaleItem.calculate_other_charges(saleObj.sale_items) + + printer = Printer::ReceiptPrinter.new(print_settings) + + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "FOC",nil,nil,other_amount,nil,nil,nil,nil) + result = { + :status => true, + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings + } + + # Mobile Print + render :json => result.to_json + + if params[:type] == "quick_service" + booking = Booking.find_by_sale_id(sale_id) + if booking.dining_facility_id.to_i>0 + table_id = booking.dining_facility_id + else + table_id = 0 + end + + booking.booking_orders.each do |order| + Order.pay_process_order_queue(order.order_id,table_id) + end + end + # end + if !saleObj.nil? + #InventoryJob.perform_now(self.id) + # InventoryDefinition.calculate_product_count(saleObj) + end + end + end + + def rounding_adj + + saleObj = Sale.find(params[:sale_id]) + + if @shop.is_rounding_adj + a = saleObj.grand_total % 25 # Modulus + b = saleObj.grand_total / 25 # Division + #not calculate rounding if modulus is 0 and division is even + #calculate rounding if modulus is zero or not zero and division are not even + if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) + new_total = Sale.get_rounding_adjustment(saleObj.grand_total) + rounding_adj = new_total-saleObj.grand_total + saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + end + end + end + + #print function for receipt + def print + filename = params[:filename] + receipt_no = params[:receipt_no] + printer_name = params[:printer_name] + cashier_type = params[:type] + + if cashier_type.strip.downcase == "doemal_order" + unique_code = "ReceiptBillOrderPdf" + else + receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf + unique_code = "ReceiptBillPdf" + print_settings = PrintSetting.where("shop_code='#{@shop.shop_code}'") + if !print_settings.nil? + print_settings.each do |setting| + if setting.unique_code == 'ReceiptBillPdf' + unique_code = "ReceiptBillPdf" + elsif setting.unique_code == 'ReceiptBillStarPdf' + unique_code = "ReceiptBillStarPdf" + end + end + end + if !receipt_bill_a5_pdf.empty? + receipt_bill_a5_pdf.each do |receipt_bilA5| + if receipt_bilA5[0] == 'ReceiptBillA5Pdf' + if receipt_bilA5[1] == '1' + unique_code = "ReceiptBillA5Pdf" + # else + # unique_code = "ReceiptBillPdf" + end + end + end + end + end + # get printer info + print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code) + printer = Printer::ReceiptPrinter.new(print_settings) + printer.print_receipt_pdf(filename,receipt_no,print_settings.print_copies,printer_name) + + result = { + :status => true, + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings + } + Rails.logger.debug "$$$$$$$$$ result ::" + Rails.logger.debug result + # Mobile Print + render :json => result.to_json + # render :json => {status: true} + end + + #changable tax for sale + def change_tax + sale_id = params[:sale_id] + order_source = params[:cashier_type] + tax_type = params[:tax_type] + sale = Sale.find(sale_id) + sale.compute_by_sale_items(sale.total_discount, nil, order_source, tax_type) + + render json: JSON.generate({:status => true}) + end + + #get cloud domain + def getCloudDomain + from = "" + if ENV["SERVER_MODE"] == 'cloud' + from = request.subdomain.to_s + "." + request.domain.to_s + end + + return from + end +end diff --git a/app/controllers/foodcourt/paypar_payments_controller.rb b/app/controllers/foodcourt/paypar_payments_controller.rb new file mode 100755 index 00000000..64fe7a6d --- /dev/null +++ b/app/controllers/foodcourt/paypar_payments_controller.rb @@ -0,0 +1,31 @@ +class Foodcourt::PayparPaymentsController < BaseFoodcourtController + def create + sale_id = params[:sale_id] + @cashier_type = params[:type] + redeem_amount = params[:redeem_amount] + membership_id = params[:membership_id] + payment_method = "paypar" + if(Sale.exists?(sale_id)) + saleObj = Sale.find(sale_id) + + # rounding adjustment + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(saleObj.grand_total) + rounding_adj = new_total-saleObj.grand_total + saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + end + + sale_payment = SalePayment.new + status,msg =sale_payment.process_payment(saleObj, current_user, redeem_amount,payment_method) + if status == true + @out = true, "Success!" + else + @out =false, "Please try again payment!" + end + else + @out = false, "There has no sale record!" + end + + end + +end diff --git a/app/controllers/foodcourt/request_bills_controller.rb b/app/controllers/foodcourt/request_bills_controller.rb new file mode 100755 index 00000000..d97dcd1f --- /dev/null +++ b/app/controllers/foodcourt/request_bills_controller.rb @@ -0,0 +1,113 @@ +class Foodcourt::RequestBillsController < ApplicationController + before_action :check_user + + def check_user + if current_user.nil? + redirect_to root_path + end + end + # Print Request Bill and add to sale tables + def print + if !ShiftSale.current_shift.nil? + order_id = params[:id] # order_id + order = Order.find(order_id) + booking = order.booking + if booking.checkin_at.utc > Time.now.utc && booking.checkout_at.nil? + @status = false + @error_message = "Operation failed, Could not request bill!" + else + table = DiningFacility.find_by(id: booking.dining_facility_id) + + if sale_data = booking.sale + @status = true + elsif sale_data = Sale.generate_invoice_from_booking(booking, current_login_employee, current_user, order.source, params[:current_checkin_induties_count]) + @status = true + # in-duty update + in_duties = InDuty.where("booking_id=?", booking.id) + if !in_duties.empty? + in_duties.each do |in_duty| + induty = InDuty.find(in_duty.id) + induty.sale_id = sale_data.sale_id + induty.out_time = Time.now.utc + induty.save + end + end + end + + # Bind shift sale id to sale + # @sale_data.shift_sale_id = shift.id + # @sale_data.save + + action_by = current_user.name + type = "REQUEST_BILL" + + remark = "Request bill Receipt No #{sale_data.receipt_no}" + sale_audit = SaleAudit.record_audit_sale(sale_data.sale_id,remark,action_by,type ) + + # Promotion Activation + Promotion.promo_activate(sale_data) + + #bill channel + if ENV["SERVER_MODE"] == 'cloud' + from = request.subdomain + "." + request.domain + else + from = "" + end + + if order.source == "cashier" || order.source == "quick_service" + ActionCable.server.broadcast "bill_channel",table: table, from: from + end + if order.source == "quick_service" || order.source == "food_court" + result = {:status=> @status, :data => sale_data.sale_id } + render :json => result.to_json + else + #check checkInOut pdf print + checkout_time = Lookup.collection_of('checkout_time') + if !booking.dining_facility_id.nil? + terminal = DiningFacility.find_by_id(booking.dining_facility_id) + cashier_terminal = CashierTerminal.find_by_id(terminal.zone_id) + + if (!checkout_time.empty?) && (ENV["SERVER_MODE"] != "cloud") #no print in cloud server + unique_code = "CheckInOutPdf" + printer = PrintSetting.find_by_unique_code(unique_code) + + # print when complete click + order_queue_printer = Printer::OrderQueuePrinter.new(printer) + + if !printer.nil? + order_queue_printer.print_check_in_out(printer, cashier_terminal, booking, table) + end + end + end + end + end + @status = true + else + @status = false + @error_message = "No Current Open Shift for This Employee" + end + +# Not Use for these printed bill cannot give customer + # unique_code = "ReceiptBillPdf" + # #shop detail + # shop_details = Shop.find(1) + # # customer= Customer.where('customer_id=' +.customer_id) + # customer= Customer.find(@sale_data.customer_id) + # # get member information + # member_info = Customer.get_member_account(customer) + # # get printer info + # 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 price_by_accounts + # item_price_by_accounts = SaleItem.calculate_price_by_accounts(@sale_items) + + # printer = Printer::ReceiptPrinter.new(print_settings) + + + # printer.print_receipt_bill(print_settings, false, nil,@sale_items,@sale_data,customer.name, item_price_by_accounts,member_info,shop_details) + end + +end diff --git a/app/controllers/foodcourt/sale_edit_controller.rb b/app/controllers/foodcourt/sale_edit_controller.rb new file mode 100755 index 00000000..9971e50d --- /dev/null +++ b/app/controllers/foodcourt/sale_edit_controller.rb @@ -0,0 +1,232 @@ +class Foodcourt::SaleEditController < BaseFoodcourtController + authorize_resource class: false + # Index for sale item void OR edit + def edit + sale_id = params[:sale_id] + if params[:table_id] + @table_id = params[:table_id] + @table_type = DiningFacility.find(@table_id).type + else + @table_id = nil + @table_type = nil + end + + @cashier_type = params[:type] + @saleobj = Sale.find(sale_id) + end + + # create item void. make duplicate old record and update qty and price + def item_void + saleitemId = params[:sale_item_id] + remark = params[:remark] + access_code = params[:access_code] + order_source = params[:type] + saleitemObj = SaleItem.find(saleitemId) + saleitemObj.status = 'void' + saleitemObj.remark = remark + saleitemObj.save + @newsaleitem = SaleItem.new + @newsaleitem = saleitemObj.dup + # @newsaleitem.save + @newsaleitem.qty = saleitemObj.qty * -1 + @newsaleitem.price = saleitemObj.price * -1 + @newsaleitem.is_taxable = 1 + @newsaleitem.taxable_price = saleitemObj.taxable_price * -1 + @newsaleitem.product_name = saleitemObj.product_name + ' (VOID)' + @newsaleitem.remark = remark + @newsaleitem.save + + # re-calc tax + saleObj = Sale.find(saleitemObj.sale_id) + + + # booking = Booking.find_by_sale_id(saleitemObj.sale_id) + # booking.booking_orders.each do |bo| + # order = Order.find(bo.order_id) + # order.order_items.each do |o| + # if saleitemObj.product_code == o.item_code + # o.qty = saleitemObj.qty * -1 + # o.price = saleitemObj.price * -1 + # o.save + # end + # end + # end + # FOr Sale Audit + action_by = current_user.name + if access_code != "null" && current_user.role == "cashier" + action_by = Employee.find_by_emp_id(access_code).name + end + remark = "Void Sale Item ID #{saleitemObj.sale_item_id} | Receipt No #{saleObj.receipt_no} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}" + sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMVOID" ) + + saleObj.compute_by_sale_items(saleObj.total_discount, nil, order_source) + ProductCommission.create_product_commission(@newsaleitem, saleitemObj) + end + + def item_foc + saleitemId = params[:sale_item_id] + remark = params[:remark] + access_code = params[:access_code] + order_source = params[:type] + saleitemObj = SaleItem.find(saleitemId) + saleitemObj.status = 'foc' + saleitemObj.remark = remark + saleitemObj.save + + @newsaleitem = saleitemObj.dup + @newsaleitem.qty = saleitemObj.qty * -1 + @newsaleitem.unit_price = saleitemObj.unit_price * 1 + @newsaleitem.taxable_price = saleitemObj.taxable_price * -1 + @newsaleitem.price = saleitemObj.price * -1 + @newsaleitem.product_name = saleitemObj.product_name + ' (FOC)' + @newsaleitem.remark = remark + @newsaleitem.save + + # re-calc tax + saleObj = Sale.find(saleitemObj.sale_id) + + order_id = SaleOrder.find_by_sale_id(saleitemObj.sale_id).order_id + order = Order.find(order_id) + + action_by = current_user.name + if access_code != "null" && current_user.role == "cashier" + action_by = Employee.find_by_emp_id(access_code).name + end + remark = "FOC Sale Item ID #{saleitemObj.sale_item_id} | Receipt No #{saleObj.receipt_no} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}Receipt No #{saleObj.receipt_no}" + sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMFOC" ) + + saleObj.compute_by_sale_items(saleObj.total_discount, nil, order_source) + ProductCommission.create_product_commission(@newsaleitem, saleitemObj) + end + + # def item_edit + # saleitemId = params[:sale_item_id] + # update_qty = params[:update_qty] + # update_price = params[:update_price] + # saleitemObj = SaleItem.find(saleitemId) + # saleitemObj.status = 'void' + # saleitemObj.save + # @newsaleitem = SaleItem.new + # @newsaleitem = saleitemObj.dup + # @newsaleitem.save + # @newsaleitem.qty = update_qty + # @newsaleitem.price = update_price + # @newsaleitem.unit_price = update_price + # @newsaleitem.taxable_price = update_price + # @newsaleitem.is_taxable = 0 + # @newsaleitem.remark = 'edit' + # @newsaleitem.product_name = saleitemObj.product_name + " - updated" + # @newsaleitem.save + # end + + def item_edit + saleitemId = params[:sale_item_id] + update_qty = params[:update_qty] + update_price = params[:update_price] + access_code = params[:access_code] + order_source = params[:type] + saleitemObj = SaleItem.find(saleitemId) + original_qty = saleitemObj.qty + original_price = saleitemObj.unit_price + sale = Sale.find(saleitemObj.sale_id) + + saleitemObj.qty = update_qty + saleitemObj.price = update_qty.to_f * update_price.to_f + saleitemObj.unit_price = update_price + saleitemObj.taxable_price = update_qty.to_f * update_price.to_f + + action_by = current_user.name + if access_code != "null" && current_user.role == "cashier" + action_by = Employee.find_by_emp_id(access_code).name + end + remark = "Update From Qty=>#{original_qty} Price=>[#{original_price}] to qty=>#{update_qty} Price =>[#{saleitemObj.price}]| Receipt No #{sale.receipt_no} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}" + sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMEDIT" ) + # saleitemObj.remark = 'edit' + + unless saleitemObj.product_name.include? 'UPDATED' + saleitemObj.product_name = saleitemObj.product_name + ' (UPDATED)' + end + + saleitemObj.save + + # re-calc tax + # saleObj = Sale.find(saleitemObj.sale_id) + + # order_id = SaleOrder.find_by_sale_id(saleitemObj.sale_id).order_id + # order = Order.find(order_id) + + # order.order_items.each do |o| + # if saleitemObj.product_code == o.item_code + # o.qty = update_qty + # o.price = update_price + # o.save + # end + # end + + sale.compute_by_sale_items(sale.total_discount, nil, order_source) + + ProductCommission.edit_product_commission(saleitemObj,sale.shop_code) + end + + # make cancel void item + def item_void_cancel + saleitemId = params[:sale_item_id] + access_code = params[:access_code] + order_source = params[:type] + + saleitemObj = SaleItem.find(saleitemId) + + saleObj = saleitemObj.sale + + saleObj.sale_items.where(product_code: saleitemObj.product_code) + .where(qty: saleitemObj.qty.abs) + .where(unit_price: saleitemObj.unit_price) + .where(status: saleitemObj.status).first.update(status: nil, remark: nil) + + saleitemObj.destroy + # re-calc tax + + order_id = SaleOrder.find_by_sale_id(saleitemObj.sale_id).order_id + order = Order.find(order_id) + + action_by = current_user.name + if access_code != "null" && current_user.role == "cashier" + action_by = Employee.find_by_emp_id(access_code).name + end + remark = "Cancle Void Sale Item ID #{saleitemObj.sale_item_id} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}|Receipt No #{saleObj.receipt_no}" + sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"ITEMCANCELVOID" ) + + saleObj.compute_by_sale_items(saleObj.total_discount, nil, order_source) + ProductCommission.remove_product_commission(saleitemObj) + end + + # remove all void items + def cancel_all_void + sale_id = params[:sale_id] + order_source = params[:type] + saleObj = Sale.find(sale_id) + saleObj.sale_items.each do |item| + if item.qty.to_i < 0 + item.destroy + else + item.status = nil + end + item.save + ProductCommission.remove_product_commission(item) + end + saleObj.sale_items.reset + # re-calc tax + saleObj.compute_by_sale_items(saleObj.total_discount,nil, order_source) + end + + def apply_void + sale_id = params[:sale_id] + order_source = params[:type] + saleObj = Sale.find(sale_id) + saleObj.compute_without_void(order_source) + saleObj.sale_items.each do |item| + ProductCommission.remove_product_commission(item) + end + end + +end diff --git a/app/controllers/foodcourt/sales_controller.rb b/app/controllers/foodcourt/sales_controller.rb new file mode 100755 index 00000000..cbc34cbe --- /dev/null +++ b/app/controllers/foodcourt/sales_controller.rb @@ -0,0 +1,78 @@ +class Foodcourt::SalesController < BaseFoodcourtController + def show + @webview = false + if check_mobile + @webview = true + end + + @tables = Table.unscoped.all.active.order('status desc') + @rooms = Room.unscoped.all.active.order('status desc') + @complete = Sale.completed_sale("cashier") + @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') + @customers = Customer.pluck("customer_id, name") + @sale = Sale.find(params[:sale_id]) + @order = SaleOrder.find_by_sale_id(@sale.sale_id).order_id + @booking = BookingOrder.find_by_order_id(@order).booking_id + if Booking.find(@booking).dining_facility_id.to_i>0 + @table_id = Booking.find(@booking).dining_facility_id + @dining = DiningFacility.find(@table_id) + else + @table_id = nil + @dining = nil + end + end + + def add_to_existing_invoice + dining = params[:dining_id] + sale_id = params[:sale_id] + tax_type = params[:tax_type] + sale_data = [] + table = DiningFacility.find(dining) + existing_booking = Booking.find_by_sale_id(sale_id) + table.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ").each do |booking| + if booking.sale_id.nil? + order_array = [] + booking.booking_orders.each do |booking_order| + + booking.booking_status = 'moved' + order = Order.find(booking_order.order_id) + order.status = 'billed' + order.order_items.each do |item| + item.order_item_status = 'billed' + end + # create sale item + saleobj = Sale.find(sale_id) + order.order_items.each do |orer_item| + saleobj.add_item (orer_item) + if !orer_item.set_menu_items.nil? + saleobj.add_sub_item(orer_item.set_menu_items) + end + sale_data.push(orer_item) + end + + # Re-compute for add + saleobj.compute(order.source,tax_type) + saleobj.save + order.save + booking.save + + order_array.push(order.order_id) + end + + receipt_no = Sale.find(sale_id).receipt_no + action_by = current_user.name + type = "ADD_TO_EXISTING" + + remark = "#{action_by} add to existing order #{order_array} to Receipt No=>#{receipt_no} in #{table.name}" + sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type ) + + booking_order = BookingOrder.where('booking_id=?',booking) + booking_order.each do |bo| + bo.booking_id = existing_booking.booking_id + bo.save + end + end + end + end + +end diff --git a/app/controllers/foodcourt/second_display_controller.rb b/app/controllers/foodcourt/second_display_controller.rb new file mode 100644 index 00000000..e180ed1d --- /dev/null +++ b/app/controllers/foodcourt/second_display_controller.rb @@ -0,0 +1,34 @@ +class Foodcourt::SecondDisplayController < BaseFoodcourtController + + def index + @display_images = DisplayImage.all + end + + def show + end + + def customer_view + display_type = Lookup.find_by_lookup_type("display_type") + if !display_type.nil? && display_type.value.to_i == 2 + if params[:status]!= "billed" + tax_profiles = TaxProfile.all.order("order_by asc") + else + tax_profiles = nil + end + if ENV["SERVER_MODE"] == 'cloud' + from = request.subdomain + "." + request.domain + else + from = "" + end + ActionCable.server.broadcast "second_display_view_channel",data: params[:data],tax_profiles: tax_profiles,status:params[:status],from:from + end + # end + end + #Shop Name in Navbor + # helper_method :shop_detail + # def shop_detail + # @shop = Shop.first + # end + + +end diff --git a/app/controllers/foodcourt/shifts_controller.rb b/app/controllers/foodcourt/shifts_controller.rb new file mode 100755 index 00000000..599dad1e --- /dev/null +++ b/app/controllers/foodcourt/shifts_controller.rb @@ -0,0 +1,158 @@ +class Foodcourt::ShiftsController < BaseFoodcourtController + def index + end + + def show + @cashier_type = params[:type] + @shift = ShiftSale.current_open_shift(current_user) + #for bank integration + bank_integration = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('bank_integration') + @bank_integration = 0 + if !bank_integration[0].nil? + @bank_integration = bank_integration[0][1] + end + + end + + def new + @float = Lookup.where('lookup_type=?','float_value') + @terminal = CashierTerminal.available.where("shop_code='#{@shop.shop_code}'") + end + + def create + opening_balance = params[:opening_balance] + cashier_terminal_param = params[:cashier_terminal] + + # Multiple Cashier + cashier_terminal = CashierTerminal.find(cashier_terminal_param) + if cashier_terminal.is_currently_login + respond_to do |format| + format.html { redirect_to settings_order_queue_stations_url, notice: 'Cashier Terminal already signin!' } + end + end + + # Update Cashier Terminal + cashier_terminal.is_currently_login = 1 + cashier_terminal.save + + @shift_sale = ShiftSale.new + @shift_sale.create(opening_balance,cashier_terminal_param, current_user) + end + + + + def update_shift + closing_balance = params[:closing_balance] + shift_id = params[:shift_id] + @shift = ShiftSale.find_by_id(shift_id) + if @shift + @shift.shift_closed_at = DateTime.now.utc + @shift.closing_balance = closing_balance.to_f + @shift.save + + # Multiple Cashier + cashier_terminal = @shift.cashier_terminal + cashier_terminal.is_currently_login = 0 + cashier_terminal.save + + #add shift_sale_id to card_settle_trans + bank_integration = Lookup.find_by_lookup_type_and_shop_code('bank_integration',@shop.shop_code) + if !bank_integration.nil? + card_settle_trans = CardSettleTran.select('id').where(['shift_sale_id IS NULL and status IS NOT NULL']) + + card_settle_trans.each do |data| + card_sett_trans = CardSettleTran.find(data.id) + card_sett_trans.shift_sale_id = @shift.id + card_sett_trans.save() + end + end + + if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + + + + # if !close_cashier_print[0].nil? + # @close_cashier_print = close_cashier_print[0][1] + # end + close_cashier_pdf = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("print_settings") + unique_code = "CloseCashierPdf" + + if !close_cashier_pdf.empty? + close_cashier_pdf.each do |close_cashier| + if close_cashier[0] == 'CloseCashierCustomisePdf' + if close_cashier[1] == '1' + unique_code="CloseCashierCustomisePdf" + else + unique_code="CloseCashierPdf" + end + end + end + end + shop_details = shop_detail + #get tax + shift_obj = ShiftSale.where('id =?',@shift.id) + sale_items = '' + @lookup = Lookup.shift_sale_items_lookup_value(@shop.shop_code) + if @lookup.to_i == 1 + @sale_items = Sale.get_shift_sale_items(@shift.id) + other_charges = Sale.get_other_charges() + @total_other_charges_info = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",@shift) + end + @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='').where("sales.shop_code='#{@shop.shop_code}'") + @total_waste = Sale.get_total_waste(shift_id).sum(:grand_total) + @total_spoile = Sale.get_total_spoile(shift_id).sum(:grand_total) + #other payment details for mpu or visa like card + @other_payment = ShiftSale.get_by_shift_other_payment(@shift) + + # Calculate price_by_accounts + @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') + @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') + @total_member_discount = ShiftSale.get_total_member_discount(@shift) + @total_dinein = ShiftSale.get_total_dinein(@shift).total_dinein_amount + @total_takeway = ShiftSale.get_total_takeway(@shift).total_takeway_amount + @total_other_charges = ShiftSale.get_total_other_charges(@shift).total_other_charges_amount + @total_credit_payments = ShiftSale.get_shift_sales_with_credit_payment(shift_id).total_credit_payments + + # get printer info + print_settings = PrintSetting.find_by_unique_code(unique_code) + printer = Printer::CashierStationPrinter.new(print_settings) + + # print close cashier setting + close_cashier_print = Lookup.collection_of('close_cashier_print') + if close_cashier_print.empty? + @settings_lookup = Lookup.new(lookup_type: "close_cashier_print", name: "CloseCashierPrint", value: "1") + @settings_lookup.save + end + find_close_cashier_print = Lookup.collection_of('close_cashier_print') + if find_close_cashier_print[0][1].to_i > 0 + printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments) + end + end + end + Employee.logout(session[:session_token]) + session[:session_token] = nil + end + + def edit + end + + def sale_summary + @shift = ShiftSale.current_open_shift(current_user) + + # @shift = ShiftSale.find_by_id(shift_id) + if @shift + #get tax + shift_obj = ShiftSale.where('id =?',@shift.id) + @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='').where("sales.shop_code='#{@shop.shop_code}'") + #other payment details for mpu or visa like card + @other_payment = ShiftSale.get_by_shift_other_payment(@shift) + + # Calculate price_by_accounts + @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') + @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') + @total_member_discount = ShiftSale.get_total_member_discount(@shift) + end + + end + +end diff --git a/app/controllers/foodcourt/surveys_controller.rb b/app/controllers/foodcourt/surveys_controller.rb new file mode 100644 index 00000000..363bc6ba --- /dev/null +++ b/app/controllers/foodcourt/surveys_controller.rb @@ -0,0 +1,112 @@ +class Foodcourt::SurveysController < BaseFoodcourtController + def new + @webview = false + if check_mobile + @webview = true + end + + @survey = Survey.new + @id = params[:id] + @cashier_type = params[:type] + + if(@id[0,3] == "SAL") + @sale = Sale.find(@id) + @receipt_no = @sale.receipt_no + @grand_total = @sale.grand_total + @booking = Booking.find_by_sale_id(@id) + + if @booking.dining_facility_id.to_i>0 + @dining_facility = DiningFacility.find(@booking.dining_facility_id) + @table_type = @dining_facility.type + @survey_data = Survey.find_by_dining_name_and_shop_code(@dining_facility.name,@shop.shop_code) + survey_process = Survey.find_by_receipt_no_and_shop_code(@receipt_no,@shop.shop_code) + if !survey_process.nil? + @survey_data = survey_process + end + else + @dining_facility = nil + @table_type = nil + end + + else + @dining_facility = DiningFacility.find(@id) + @table_type = @dining_facility.type + @receipt_no = nil + @grand_total = nil + @survey_data = Survey.find_by_dining_name_and_receipt_no_and_shop_code(@dining_facility.name,nil,@shop.shop_code) + end + end + + def create + @type = params[:cashier_type] + @sale_id = params[:sale_id] + if params[:table_id].to_i>0 + @dining_facility = DiningFacility.find(params[:table_id]) + if params[:sale_id].to_i > 0 + # cashier_zone = CashierTerminalByZone.find_by_zone_id(@dining_facility.zone_id) + # shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil) + # set cashier + open_cashier = Employee.where("role = 'cashier' AND token_session <> '' and shop_code='#{@shop.shop_code}'") + current_shift = ShiftSale.current_shift(@shop.shop_code) + current_shift_user =Employee.find_by_id(current_user.employee_id) + if open_cashier.count>0 + shift_by_terminal = ShiftSale.current_open_shift(open_cashier[0]) + else + shift_by_terminal = ShiftSale.current_open_shift(current_shift_user) + end + else + sale = Sale.find(@sale_id) + shift = ShiftSale.find(sale.shift_sale_id) + shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(shift.cashier_terminal_id,nil) + end + else + sale = Sale.find(@sale_id) + shift = ShiftSale.find(sale.shift_sale_id) + shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(shift.cashier_terminal_id,nil) + end + + if @type == "quick_service" || @type == "food_court" + @url = "/foodcourt/sale/"+@sale_id+"/"+@type+"/payment" + else + @url = "/foodcourt/"+@dining_facility.type.downcase+"/"+params[:table_id] + end + + + if params[:survey_id].nil? || params[:survey_id] == "" + @survey = Survey.new(survey_params) + @survey.shift_id = shift_by_terminal.id + @survey.foreigner = params["survey"]["foreigner"].to_json + @survey.shop_code = @shop.shop_code + # respond_to do |format| + if @survey.save + redirect_to @url + end + # end + else + survey = Survey.find_by_id(params[:survey_id]) + survey.child = params["survey"]["child"] + survey.adult = params["survey"]["adult"] + survey.male = params["survey"]["male"] + survey.female = params["survey"]["female"] + survey.local = params["survey"]["local"] + survey.dining_name = params["survey"]["dining_name"] + survey.receipt_no = params["survey"]["receipt_no"] + survey.shift_id = shift_by_terminal.id + survey.created_by = params["survey"]["created_by"] + survey.total_customer = params["survey"]["total_customer"] + survey.total_amount = params["survey"]["total_amount"] + survey.foreigner = params["survey"]["foreigner"].to_json + if survey.save! + redirect_to @url + end + end + end + + private + + # Never trust parameters from the scary internet, only allow the white list through. + def survey_params + params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner, :dining_name,:receipt_no,:shift_id,:created_by,:total_customer,:total_amount,:survey_id) + end + +end diff --git a/app/controllers/foodcourt/void_controller.rb b/app/controllers/foodcourt/void_controller.rb new file mode 100755 index 00000000..5cb18b4f --- /dev/null +++ b/app/controllers/foodcourt/void_controller.rb @@ -0,0 +1,157 @@ +class Foodcourt::VoidController < BaseFoodcourtController + authorize_resource :class => false + def overall_void + + sale_id = params[:sale_id] + remark = params[:remark] + order_source = params[:type] #tax profile source + access_code = params[:access_code] + if Sale.exists?(sale_id) + sale = Sale.find_by_sale_id(sale_id) + if sale.discount_type == "member_discount" + sale.update_attributes(total_discount: 0) + sale.compute_by_sale_items(0, nil, order_source) + end + + # update count for shift sale + if(sale.sale_status == "completed") + if sale.shift_sale_id != nil + shift = ShiftSale.find(sale.shift_sale_id) + shift.calculate(sale_id, "void") + end + else + # void before sale payment complete + if sale.shift_sale_id != nil + shift = ShiftSale.find(sale.shift_sale_id) + shift.total_void = shift.total_void + sale.grand_total + shift.save + end + end + + sale.rounding_adjustment = 0.0 + sale.payment_status = 'void' + sale.sale_status = 'void' + sale.save + + if sale.bookings[0].dining_facility_id.to_i > 0 + table_avaliable = true + table_count = 0 + table = sale.bookings[0].dining_facility + table.bookings.each do |booking| + if booking.booking_status != 'moved' + if booking.sale_id + if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' && booking.sale.sale_status != 'spoile' && booking.sale.sale_status != 'waste' + table_avaliable = false + table_count += 1 + else + table_avaliable = true + end + else + table_avaliable = false + table_count += 1 + end + end + end + + if table_avaliable && table_count == 0 + table.status = 'available' + table.save + end + else + table = nil + end + + # FOr Sale Audit + action_by = current_user.name + if access_code != "null" && current_user.role == "cashier" + action_by = Employee.find_by_emp_id_and_shop_code(access_code,@shop.shop_code).name + end + + # remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}" + sale_audit = SaleAudit.record_audit_for_edit(sale_id,current_user.name, action_by,remark,"SALEVOID" ) + + #call paymal to void + if sale.sale_payments.nil? + membership_response =sale.paymal_payment_void + end + Rails.logger.debug "---------Paymal Payment Void response in VoidController" + Rails.logger.debug membership_response.to_json + + # For Print + member_info = nil + rebate_amount = nil + current_balance = nil + + # For Cashier by Zone + bookings = Booking.where("sale_id='#{sale_id}'") + if bookings.count > 1 + # for Multiple Booking + if bookings[0].dining_facility_id.to_i>0 + table = DiningFacility.find(bookings[0].dining_facility_id) + end + end + + if bookings[0].dining_facility_id.to_i > 0 + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + else + shift = ShiftSale.find(sale.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + end + + customer= Customer.find(sale.customer_id) + + # get member information + rebate = MembershipSetting.find_by_rebate(1) + if customer.membership_id != nil && rebate + member_info = Customer.get_member_account(customer) + rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no) + # current_balance = SaleAudit.paymal_search(sale_id) + current_balance = 0 + end + + printer = PrintSetting.where("shop_code='#{@shop.shop_code}'") + + unique_code="ReceiptBillPdf" + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'ReceiptBillPdf' + unique_code="ReceiptBillPdf" + elsif printer_setting.unique_code == 'ReceiptBillA5Pdf' + unique_code="ReceiptBillA5Pdf" + elsif printer_setting.unique_code == 'ReceiptBillStarPdf' + unique_code="ReceiptBillStarPdf" + end + end + end + # get printer info + print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code) + # Calculate Food and Beverage Total + item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items) + discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) + other_amount = SaleItem.calculate_other_charges(sale.sale_items) + printer = Printer::ReceiptPrinter.new(print_settings) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "VOID",current_balance,nil,other_amount,nil,nil,nil,nil) + result = { + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings + } + + # Mobile Print + render :json => result.to_json + # end + + #end print + + # update complete order items in oqs + SaleOrder.where("sale_id = '#{ sale_id }'").find_each do |sodr| + AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi| + aoi.delivery_status = 1 + aoi.save + end + end + end + end + +end diff --git a/app/controllers/foodcourt/waste_spoile_controller.rb b/app/controllers/foodcourt/waste_spoile_controller.rb new file mode 100755 index 00000000..c7619636 --- /dev/null +++ b/app/controllers/foodcourt/waste_spoile_controller.rb @@ -0,0 +1,144 @@ +class Foodcourt::WasteSpoileController < BaseFoodcourtController + def waste_and_spoilage + sale_id = params[:sale_id] + remark = params[:remark] + order_source = params[:type] + access_code = params[:access_code] #tax profile source + if Sale.exists?(sale_id) + sale = Sale.find_by_sale_id(sale_id) + SaleTax.where("sale_id='#{sale_id}'").find_each do |existing_tax| + existing_tax.delete + end + sale.update_attributes(total_discount: 0,total_tax: 0,grand_total: sale.total_amount,rounding_adjustment:0) + sale.payment_status = remark + sale.sale_status = remark + sale.save + + # add to sale item with foc + # sale_items = SaleItem.where("sale_id='#{ sale_id }' and status is null") + + sale.sale_items.each do|item| + # SaleItem.update_existing_item(item.qty, item, sale_id, remark, item.unit_price, item.price) + item.status = remark + item.remark = remark + item.save + end + + if sale.bookings[0].dining_facility_id.to_i > 0 + table_avaliable = true + table_count = 0 + table = sale.bookings[0].dining_facility + table.bookings.each do |booking| + if booking.booking_status != 'moved' + if booking.sale_id + if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' && booking.sale.sale_status != 'spoile' && booking.sale.sale_status != 'waste' + table_avaliable = false + table_count += 1 + else + table_avaliable = true + end + else + table_avaliable = false + table_count += 1 + end + end + end + if table_avaliable && table_count == 0 + table.status = 'available' + table.save + end + else + table = nil + end + + # FOr Sale Audit + action_by = current_user.name + if access_code != "null" && current_user.role == "cashier" + action_by = Employee.find_by_emp_id_and_shop_code(access_code,@shop.shop_code).name + end + # remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}" + sale_audit = SaleAudit.record_audit_for_edit(sale_id,current_user.name, action_by,remark,remark ) + + # For Print + + member_info = nil + rebate_amount = nil + current_balance = nil + + # For Cashier by Zone + bookings = Booking.where("sale_id='#{sale_id}'") + if bookings.count > 1 + # for Multiple Booking + if bookings[0].dining_facility_id.to_i>0 + table = DiningFacility.find(bookings[0].dining_facility_id) + end + end + + if bookings[0].dining_facility_id.to_i > 0 + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + else + shift = ShiftSale.find(sale.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + end + + + # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + # unique_code = "ReceiptBillPdf" + customer= Customer.find(sale.customer_id) + + # get member information + rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code) + if customer.membership_id != nil && rebate + member_info = Customer.get_member_account(customer) + rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no) + # current_balance = SaleAudit.paymal_search(sale_id) + current_balance = 0 + end + + printer = PrintSetting.where("shop_code='#{@shop.shop_code}'") + + unique_code="ReceiptBillPdf" + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'ReceiptBillPdf' + unique_code="ReceiptBillPdf" + elsif printer_setting.unique_code == 'ReceiptBillA5Pdf' + unique_code="ReceiptBillA5Pdf" + elsif printer_setting.unique_code == 'ReceiptBillStarPdf' + unique_code="ReceiptBillStarPdf" + end + end + end + + # get printer info + print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code) + # Calculate Food and Beverage Total + item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items) + discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) + other_amount = SaleItem.calculate_other_charges(sale.sale_items) + printer = Printer::ReceiptPrinter.new(print_settings) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, remark,current_balance,nil,other_amount,nil,nil,nil,nil) + result = { + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings + } + + # Mobile Print + render :json => result.to_json + # end + + #end print + + # update complete order items in oqs + SaleOrder.where("sale_id = '#{ sale_id }'").find_each do |sodr| + AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi| + aoi.delivery_status = 1 + aoi.save + end + end + end + end + +end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 32d47ce3..1f445e6c 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -18,8 +18,8 @@ class HomeController < ApplicationController def index # @employees = Employee.all_emp_except_waiter.order("name asc") - @employees = Employee.all.where("shop_code='#{current_shop.shop_code}' and is_active = true").order("name asc") - @roles = Employee.where("shop_code='#{current_shop.shop_code}'").distinct.pluck(:role) + @employees = Employee.all.where("shop_code='#{@shop.shop_code}' and is_active = true").order("name asc") + @roles = Employee.where("shop_code='#{@shop.shop_code}'").distinct.pluck(:role) # byebug # @roles = Lookup.collection_of("employee_roles") @@ -52,7 +52,7 @@ class HomeController < ApplicationController @login_form = LoginForm.new() @login_form.emp_id = params[:login_form][:emp_id] @login_form.password = params[:login_form][:password] - @employee = Employee.login(current_shop,@login_form.emp_id, @login_form.password) + @employee = Employee.login(@login_form.emp_id, @login_form.password) if @employee != nil if @employee.is_active @@ -78,6 +78,9 @@ class HomeController < ApplicationController elsif @employee.role == "kitchen" session[:session_token] = @employee.token_session redirect_to oqs_root_path + elsif @employee.role == "foodcourt_cashier" + session[:session_token] = @employee.token_session + route_by_role(@employee) else render :index end @@ -91,31 +94,24 @@ class HomeController < ApplicationController end def dashboard - @from, @to, @from_time, @to_time = get_date_range_from_params - today = DateTime.now.strftime('%Y-%m-%d') - if !@from.nil? && !@to.nil? - if !@from_time.nil? && @to_time.nil? - @orders = Sale::where("shop_code='#{@shop.shop_code}' and payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count() - else - @orders = Sale::where("shop_code='#{@shop.shop_code}' and payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() - end - else - @orders = Sale::where("shop_code='#{@shop.shop_code}' and payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() - end - if !@from.nil? && !@to.nil? - if !@from_time.nil? && @to_time.nil? - @sales = Sale::where("shop_code='#{@shop.shop_code}' and payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count() - else - @sales = Sale::where("shop_code='#{@shop.shop_code}' and payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() - end - else - @sales = Sale::where("shop_code='#{@shop.shop_code}' and payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() - end - @top_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"top",@shop).sum('i.qty') - @bottom_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"bottom",@shop).sum('i.qty') - @hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time,@shop).sum(:grand_total) + @from, @to = get_date_range_from_params + + @orders = Sale.receipt_date_between(@from, @to).where("payment_status = 'new' and sale_status = 'bill'") + @sales = Sale.receipt_date_between(@from, @to).completed + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + @orders = @orders.where(shift_sale_id: shift.id) + @sales = @sales.where(shift_sale_id: shift.id) + end + end + + + @top_products = Sale.top_bottom_products(current_user,@from,@to,"top",current_shop) + @bottom_products = Sale.top_bottom_products(current_user,@from,@to,"bottom",current_shop) + @hourly_sales = Sale.hourly_sales(current_user,@from,@to,current_shop) + employee_sales = Sale.employee_sales(current_user,@from,@to,current_shop) - employee_sales = Sale.employee_sales(today,current_user,@from,@to,@from_time,@to_time,@shop) @employee_sales = [] if !employee_sales.nil? employee_sales.each do |emp| @@ -127,43 +123,43 @@ class HomeController < ApplicationController end end end - @inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time,@shop).sum(:balance) - @total_trans = Sale.total_trans(today,current_user,@from,@to,@from_time,@to_time,@shop) - @total_card = Sale.total_card_sale(today,current_user,@from,@to,@from_time,@to_time,@shop) - @total_credit = Sale.credit_payment(today,current_user,@from,@to,@from_time,@to_time,@shop) + @inventories = StockJournal.inventory_balances(@from,@to, current_shop).sum(:balance) + + @total_trans = Sale.total_trans(current_user,@from,@to) + @total_card = Sale.total_card_sale(current_user,@from,@to) + @total_credit = Sale.credit_payment(current_user,@from,@to, current_shop) @sale_data = Array.new - @total_payment_methods = Sale.total_payment_methods(@shop,today,current_user,@from,@to,@from_time,@to_time) + @total_payment_methods = Sale.total_payment_methods(current_user,@from,@to) 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" || payment.payment_method == "unionpay" || payment.payment_method == "alipay" - pay = Sale.payment_sale(@shop,'card', today, current_user,@from,@to,@from_time,@to_time) - @sale_data.push({'card' => pay.payment_amount}) - else - pay = Sale.payment_sale(@shop,payment.payment_method, today, current_user,@from,@to,@from_time,@to_time) - @sale_data.push({payment.payment_method => pay.payment_amount}) - end + pay = Sale.payment_sale(payment.payment_method, current_user,@from,@to) + @sale_data.push({payment.payment_method => pay.payment_amount}) end end - @summ_sale = Sale.summary_sale_receipt(@shop,today,current_user,@from,@to,@from_time,@to_time) - @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(@shop,today,current_user,@from,@to,@from_time,@to_time) - @total_order = Sale.total_order(@shop,today,current_user,@from,@to,@from_time,@to_time) - @total_accounts = Sale.total_account(@shop,today,current_user,@from,@to,@from_time,@to_time) + @summ_sale = Sale.summary_sale_receipt(current_user,@from,@to) + @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(current_user,@from,@to) + # @total_other_customer = Sale.total_other_customer(today,current_user) + + @total_order = Sale.total_order(current_user,@from,@to, current_shop) + @total_accounts = Account.select("accounts.id as account_id, accounts.title as title") @account_data = Array.new if !@total_accounts.nil? @total_accounts.each do |account| - acc = Sale.account_data(@shop,account.account_id, today,current_user,@from,@to,@from_time,@to_time) - if !acc.nil? + + acc = Sale.account_data(account.account_id,current_user,@from,@to) + if !acc.nil? && acc.cnt_acc > 0 @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) end end + @total_accounts = @total_accounts.reject.with_index { |x, i| @account_data[i].nil? } end - @top_items = Sale.top_items(@shop,today,current_user,@from,@to,@from_time,@to_time) - @total_foc_items = Sale.total_foc_items(@shop,today,current_user,@from,@to,@from_time,@to_time) + @top_items = Sale.top_items(current_user,@from,@to) + @total_foc_items = Sale.total_foc_items(current_user,@from,@to) # get printer info # @print_settings = get_precision_delimiter @@ -171,7 +167,7 @@ class HomeController < ApplicationController def destroy # clear in employee session - Employee.logout(@shop,session[:session_token]) + Employee.logout(session[:session_token]) session[:session_token] = nil # redirect_to root_path render :json => {:status=> "Success", :url => root_path }.to_json @@ -221,27 +217,30 @@ class HomeController < ApplicationController redirect_to origami_dashboard_path elsif employee.role == "account" redirect_to reports_dailysale_index_path + elsif employee.role == "foodcourt_cashier" + #check if cashier has existing open cashier + shift = ShiftSale.current_open_shift(employee) + if !shift.nil? + redirect_to foodcourt_food_court_path + else + redirect_to new_foodcourt_shift_path + end end end def get_date_range_from_params - from = params[:from] - to = params[:to] - from_time = params[:from_time] - to_time = params[:to_time] - - if from.present? && to.present? - # f_date = DateTime.parse(from) - # t_date = DateTime.parse(to) - # f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) - # t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) - # from = f_time.beginning_of_day.utc.getlocal - # to = t_time.end_of_day.utc.getlocal - - from = DateTime.parse(from).utc.getlocal.strftime('%Y-%m-%d') - to = DateTime.parse(to).utc.getlocal.strftime('%Y-%m-%d') + if params[:from].present? && params[:to].present? + if params[:from_time].present? && params[:to_time].present? + from = Time.parse("#{params[:from]} #{params[:from_time]}") + to = Time.parse("#{params[:to]} #{params[:to_time]}") + else + from = Time.parse(params[:from]) + to = Time.parse(params[:to]).end_of_day end - - return from, to, from_time, to_time + else + from = Time.now.beginning_of_day + to = Time.now.end_of_day + end + return from, to end end diff --git a/app/controllers/inventory/inventory_controller.rb b/app/controllers/inventory/inventory_controller.rb index 137b733a..e9629f4e 100755 --- a/app/controllers/inventory/inventory_controller.rb +++ b/app/controllers/inventory/inventory_controller.rb @@ -18,4 +18,5 @@ class Inventory::InventoryController < BaseInventoryController format.xls end end + end diff --git a/app/controllers/inventory/stock_checks_controller.rb b/app/controllers/inventory/stock_checks_controller.rb index c756c8bb..2eb0bdae 100755 --- a/app/controllers/inventory/stock_checks_controller.rb +++ b/app/controllers/inventory/stock_checks_controller.rb @@ -32,7 +32,7 @@ class Inventory::StockChecksController < BaseInventoryController def save_to_journal check = params[:data] - stockCheck = StockCheck.find_by_id_and_shop_code(check,@shop.shop_code) + stockCheck = StockCheck.find_by_id(check) stockCheck.stock_check_items.each do |item| StockJournal.from_stock_check(item,@shop) end @@ -40,14 +40,14 @@ class Inventory::StockChecksController < BaseInventoryController def print_stock_check stock_id = params[:stock_check_id] # sale_id - stockcheck = StockCheck.find_by_id_and_shop_code(stock_id,@shop.shop_code) + stockcheck = StockCheck.find_by_id(stock_id) stockcheck_items = stockcheck.stock_check_items member_info = nil unique_code = 'StockCheckPdf' - shop_details = current_shop - checker = Employee.find_by_id_and_shop_code(stockcheck.check_by,@shop.shop_code) - print_settings = PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code) + + checker = Employee.find(stockcheck.check_by) + print_settings = PrintSetting.find_by_unique_code(unique_code) if !print_settings.nil? printer = Printer::ReceiptPrinter.new(print_settings) printer.print_stock_check_result(print_settings, stockcheck, stockcheck_items, checker.name, @shop) @@ -59,20 +59,12 @@ class Inventory::StockChecksController < BaseInventoryController #Pull this menu @menu_category = InventoryDefinition.search_by_category(params[:id]) - puts @menu_category.to_json - # puts @menu.menu_items[1].item_attributes.to_json return @menu_category else MenuCategory.current_menu end end - #Shop Name in Navbor - helper_method :shop_detail - def shop_detail - @shop = current_shop - end - # before_action :set_stock_check, only: [:show, :edit, :update, :destroy] # GET /stock_checks diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index f63e505e..c89f6e0a 100755 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -118,8 +118,6 @@ class Oqs::HomeController < BaseOqsController status = params[:status] items = queue_items_query(false,oqs_id,filter,table_id,status) -puts "items0" -puts items.to_json if !items.empty? items.each do |item| if !item.set_menu_items.nil? diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index baa88e4d..7ae3b0f5 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -6,7 +6,6 @@ class Origami::AddordersController < BaseOrigamiController if check_mobile @webview = true end - @tables = Table.all.active.where("shop_code='#{@shop.shop_code}'").order('zone_id asc').group("zone_id") @rooms = Room.all.active.where("shop_code='#{@shop.shop_code}'").order('zone_id asc').group("zone_id") @all_table = Table.all.where("shop_code='#{@shop.shop_code}'").active.order('status desc') @@ -46,8 +45,6 @@ class Origami::AddordersController < BaseOrigamiController #Pull this menu @menu = MenuCategory.find_by_id(params[:id]) - - # puts @menu.menu_items[1].item_attributes.to_json return @menu else MenuCategory.current_menu @@ -63,7 +60,6 @@ class Origami::AddordersController < BaseOrigamiController #Pull this menu @menu = Menu.find_by_id(params[:id]) @menu_category = MenuCategory.where("menu_id='#{@menu.id}'").order("order_by asc") - # puts @menu.menu_items[1].item_attributes.to_json return @menu else Menu.current_menu @@ -77,8 +73,6 @@ class Origami::AddordersController < BaseOrigamiController if (id) #Pull this menu @sub_menu = MenuCategory.where("menu_category_id = #{id}").active - - # puts @menu.menu_items[1].item_attributes.to_json return @sub_menu end end @@ -136,7 +130,7 @@ class Origami::AddordersController < BaseOrigamiController @order.new_booking = true @order.waiters = current_login_employee.name @order.employee_name = current_login_employee.name - @order.shop_code =@shop.shop_code + @order.shop_code = @shop.shop_code @order.is_extra_time = is_extra_time @order.extra_time = extra_time @@ -199,7 +193,6 @@ class Origami::AddordersController < BaseOrigamiController table = DiningFacility.find(table_id) if table booking = table.get_current_booking - # puts booking if booking if !booking.sale_id.nil? if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new" @@ -230,7 +223,6 @@ class Origami::AddordersController < BaseOrigamiController def process_order_queue(order_id,table_id,order_source) print_status = nil cup_status = nil - #Send to background job for processing order = Order.find(order_id) sidekiq = Lookup.find_by_lookup_type_and_shop_code("sidekiq",@shop.shop_code) diff --git a/app/controllers/origami/alipay_controller.rb b/app/controllers/origami/alipay_controller.rb index 63ff5a6b..49a121ca 100644 --- a/app/controllers/origami/alipay_controller.rb +++ b/app/controllers/origami/alipay_controller.rb @@ -11,7 +11,7 @@ class Origami::AlipayController < BaseOrigamiController end total = 0 @alipaycount = 0 - # @shop = Shop.first + @rounding_adj = 0 @can_alipay = 0 @member_discount = 0 @@ -64,7 +64,7 @@ class Origami::AlipayController < BaseOrigamiController ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - # shop_details = Shop.first + # rounding adjustment # if shop_details.is_rounding_adj @@ -85,9 +85,4 @@ class Origami::AlipayController < BaseOrigamiController end end - #Shop Name in Navbor - # helper_method :shop_detail - # def shop_detail - # @shop = Shop.first - # end end diff --git a/app/controllers/origami/cash_ins_controller.rb b/app/controllers/origami/cash_ins_controller.rb index 7ebb698a..ac3c0648 100755 --- a/app/controllers/origami/cash_ins_controller.rb +++ b/app/controllers/origami/cash_ins_controller.rb @@ -36,7 +36,6 @@ class Origami::CashInsController < BaseOrigamiController shift =current_shift end end - puts shift.to_json shift.cash_in = shift.cash_in + amount.to_f shift.save end diff --git a/app/controllers/origami/credit_payments_controller.rb b/app/controllers/origami/credit_payments_controller.rb index f5ac5740..ecf811ba 100755 --- a/app/controllers/origami/credit_payments_controller.rb +++ b/app/controllers/origami/credit_payments_controller.rb @@ -8,7 +8,6 @@ class Origami::CreditPaymentsController < BaseOrigamiController total = sale_data.grand_total @creditcount = 0 others = 0 - if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else diff --git a/app/controllers/origami/credit_sales_controller.rb b/app/controllers/origami/credit_sales_controller.rb index 8f43edda..587b22dd 100644 --- a/app/controllers/origami/credit_sales_controller.rb +++ b/app/controllers/origami/credit_sales_controller.rb @@ -3,11 +3,11 @@ class Origami::CreditSalesController < BaseOrigamiController @cashier_type = 'cashier' @webview = false if check_mobile - @webview = true + @webview = true end - - @tables = Table.unscoped.all.active.order('status desc') - @rooms = Room.unscoped.all.active.order('status desc') + + @tables = Table.unscope(:order).all.active.order('status desc') + @rooms = Room.unscope(:order).all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @customers = Customer.pluck("customer_id, name") @@ -15,7 +15,7 @@ class Origami::CreditSalesController < BaseOrigamiController @sale = Sale.find_by_sale_id(params[:sale_id]) @sale_payment = SalePayment.select("SUM(payment_amount) as payment_amount") .where("sale_id = ? and payment_method=?", @sale.sale_id, "creditnote") - + @sale_taxes = [] sale_taxes = SaleTax.where("sale_id = ?", @sale.sale_id) if !sale_taxes.empty? @@ -24,5 +24,5 @@ class Origami::CreditSalesController < BaseOrigamiController end end end - + end diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 151ff8e8..dc21ba26 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -87,7 +87,7 @@ class Origami::CustomersController < BaseOrigamiController @count_customer = Customer.count_customer # @taxes = TaxProfile.where(:group_type => 'cashier') - @taxes = TaxProfile.unscoped.select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name") + @taxes = TaxProfile.unscope(:order).select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name") .order("group_type ASC,order_by ASC") # if flash["errors"] # @crm_customer.valid? @@ -168,15 +168,17 @@ class Origami::CustomersController < BaseOrigamiController sale = Sale.find_by_receipt_no(receipt_no) @out = [] action_by = current_user.name - membership_setting = MembershipSetting.find_by_membership_type("paypar_url") + membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",@shop.shop_code) if membership_setting.gateway_url - member_actions =MembershipAction.find_by_membership_type("get_account_balance") + member_actions =MembershipAction.find_by_membership_type_and_shop_code("get_account_balance",@shop.shop_code) if member_actions.gateway_url @campaign_type_id = nil url = membership_setting.gateway_url.to_s + member_actions.gateway_url.to_s merchant_uid= member_actions.merchant_account_id auth_token = member_actions.auth_token.to_s membership_data = SalePayment.get_paypar_account_data(url,membership_setting.auth_token,merchant_uid,auth_token,account_no,amount,receipt_no) + puts membership_data.to_json + if membership_data["status"]==true remark = "Payment by account no Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} | Transaction ref: #{membership_data[:transaction_ref]} | Reload amount #{membership_data[:reload_amount]} | Old Balance Amount #{membership_data[:old_balance_amount]} | DateTime : #{membership_data[:date]}" sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,sale.cashier_id, action_by,remark,"PAYBYACCOUNT" ) diff --git a/app/controllers/origami/dashboard_controller.rb b/app/controllers/origami/dashboard_controller.rb index 0a8e5c18..004cbf3b 100644 --- a/app/controllers/origami/dashboard_controller.rb +++ b/app/controllers/origami/dashboard_controller.rb @@ -1,65 +1,67 @@ class Origami::DashboardController < BaseOrigamiController def index - today = DateTime.now.strftime('%Y-%m-%d') - - @display_type = Lookup.where("shop_code='#{@shop.shop_code}'").find_by_lookup_type("display_type") + @display_type = Lookup.find_by_lookup_type("display_type") @sale_data = Array.new - @total_payment_methods = Sale.total_payment_methods(@shop,today,current_user) + + @total_payment_methods = Sale.total_payment_methods(current_user) + 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" || payment.payment_method == "unionpay" || payment.payment_method == "alipay" - pay = Sale.payment_sale(@shop,'card', today, current_user) - @sale_data.push({'card' => pay.payment_amount}) - else - pay = Sale.payment_sale(@shop,payment.payment_method, today, current_user) - @sale_data.push({payment.payment_method => pay.payment_amount}) - end - end + + @total_payment_methods.each do |payment| + pay = Sale.payment_sale(payment.payment_method, current_user) + @sale_data.push({payment.payment_method => pay.payment_amount}) + end else @sale_data = nil end - @summ_sale = Sale.summary_sale_receipt(@shop,today,current_user) - @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(@shop,today,current_user,@from,@to,@from_time,@to_time) + + @summ_sale = Sale.summary_sale_receipt(current_user) + @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(current_user,@from,@to) # @total_other_customer = Sale.total_other_customer(today,current_user) - @total_order = Sale.total_order(@shop,today,current_user) - @total_accounts = Sale.total_account(@shop,today,current_user) + @total_order = Sale.total_order(current_user) + + @total_accounts = Account.select("accounts.id as account_id, accounts.title as title") @account_data = Array.new if !@total_accounts.nil? - @total_accounts.each do |account| - acc = Sale.account_data(@shop,account.account_id, today,current_user) - if !acc.nil? - @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) - end + + @total_accounts.each do |account| + acc = Sale.account_data(account.account_id, current_user) + if !acc.nil? + @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) end + end + @total_accounts = @total_accounts.reject.with_index { |x, i| @account_data[i].nil? } else @account_data = nil end - @top_items = Sale.top_items(@shop,today,current_user) - @total_foc_items = Sale.total_foc_items(@shop,today,current_user) + + @top_items = Sale.top_items(current_user) + @total_foc_items = Sale.total_foc_items(current_user) + # get printer info @print_settings = PrintSetting.get_precision_delimiter() @current_user = current_user #dine-in cashier - dinein_cashier = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('dinein_cashier') + dinein_cashier = Lookup.where("shop_code='#{current_shop.shop_code}'").collection_of('dinein_cashier') @dinein_cashier = 0 if !dinein_cashier[0].nil? @dinein_cashier = dinein_cashier[0][1] end #quick service - quick_service = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('quick_service') + quick_service = Lookup.where("shop_code='#{current_shop.shop_code}'").collection_of('quick_service') @quick_service = 0 if !quick_service[0].nil? @quick_service = quick_service[0][1] end #fourt court - food_court = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('food_court') + food_court = Lookup.where("shop_code='#{current_shop.shop_code}'").collection_of('food_court') @food_court = 0 @food_court_name = nil if !food_court[0].nil? @@ -68,7 +70,7 @@ class Origami::DashboardController < BaseOrigamiController end #order reservation - order_reservation = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('order_reservation') + order_reservation = Lookup.where("shop_code='#{current_shop.shop_code}'").collection_of('order_reservation') @order_reservation = 0 if !order_reservation.empty? order_reservation.each do |order_reserve| @@ -79,7 +81,7 @@ class Origami::DashboardController < BaseOrigamiController end #dashboard settings on/off for supervisor and cashier - dashboard_settings = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('dashboard_settings') + dashboard_settings = Lookup.where("shop_code='#{current_shop.shop_code}'").collection_of('dashboard_settings') @setting_flag = true if !dashboard_settings.empty? dashboard_settings.each do |setting| @@ -90,7 +92,7 @@ class Origami::DashboardController < BaseOrigamiController end #reservation - reservation = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('reservation') + reservation = Lookup.where("shop_code='#{current_shop.shop_code}'").collection_of('reservation') @reservation = 0 if !reservation.empty? reservation.each do |reserve| @@ -102,7 +104,9 @@ class Origami::DashboardController < BaseOrigamiController end def get_all_menu - @menus = Menu.includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).active.all.where("shop_code='#{@shop.shop_code}'") + + @menus = Menu.includes(:menu_categories => :children).includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).includes(:menu_categories => {:menu_items => {:item_sets => :menu_item_instances}}).active.all + @item_attributes = MenuItemAttribute.all.load @item_options = MenuItemOption.all.load end diff --git a/app/controllers/origami/dinga_controller.rb b/app/controllers/origami/dinga_controller.rb index 0472728a..3098377a 100644 --- a/app/controllers/origami/dinga_controller.rb +++ b/app/controllers/origami/dinga_controller.rb @@ -6,7 +6,6 @@ class Origami::DingaController < BaseOrigamiController @membership_rebate_balance=0 @sale_data = Sale.find_by_sale_id(@sale_id) @receipt_no = @sale_data.receipt_no - # @shop = Shop.first if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(@sale_data.grand_total) else @@ -77,7 +76,7 @@ def create account_no = params[:account_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - # shop_details = Shop.first + # rounding adjustment # if shop_details.is_rounding_adj # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) diff --git a/app/controllers/origami/food_court_controller.rb b/app/controllers/origami/food_court_controller.rb index 69826641..16766001 100644 --- a/app/controllers/origami/food_court_controller.rb +++ b/app/controllers/origami/food_court_controller.rb @@ -134,10 +134,8 @@ class Origami::FoodCourtController < ApplicationController def get_menu_category () if (params[:id]) - puts params[:id] #Pull this menu @menu = MenuCategory.find_by_id(params[:id]) - # puts @menu.menu_items[1].item_attributes.to_json return @menu else MenuCategory.current_menu @@ -150,7 +148,6 @@ class Origami::FoodCourtController < ApplicationController if (id) #Pull this menu @sub_menu = MenuCategory.where("menu_category_id = #{id}").active - # puts @menu.menu_items[1].item_attributes.to_json return @sub_menu end end @@ -171,7 +168,6 @@ class Origami::FoodCourtController < ApplicationController table = DiningFacility.find(table_id) if table booking = table.get_current_booking - # puts booking if booking if !booking.sale_id.nil? if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new" diff --git a/app/controllers/origami/gift_voucher_controller.rb b/app/controllers/origami/gift_voucher_controller.rb index 7bd4cd77..dac27995 100644 --- a/app/controllers/origami/gift_voucher_controller.rb +++ b/app/controllers/origami/gift_voucher_controller.rb @@ -6,7 +6,6 @@ class Origami::GiftVoucherController < BaseOrigamiController sale_data = Sale.find_by_sale_id(@sale_id) total = 0 @gift_vouchercount = 0 - # @shop = Shop.first @rounding_adj = 0 @can_gift_voucher = 0 @member_discount = 0 @@ -48,8 +47,6 @@ class Origami::GiftVoucherController < BaseOrigamiController ref_no = params[:reference_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - # shop_details = Shop.first - # rounding adjustment # if shop_details.is_rounding_adj # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) @@ -62,10 +59,4 @@ class Origami::GiftVoucherController < BaseOrigamiController @status, @sale = sale_payment.process_payment(saleObj, current_user, cash, "GiftVoucher",ref_no) end end - - #Shop Name in Navbor - # helper_method :shop_detail - # def shop_detail - # @shop = Shop.first - # end end diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 81986afa..b31e1a17 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -4,10 +4,13 @@ class Origami::HomeController < BaseOrigamiController def index @webview = check_mobile - @tables = Table.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') - @rooms = Room.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') - @complete = Sale.completed_sale("cashier",@shop.shop_code) - @orders = Order.includes("sale_orders").where("shop_code='#{@shop.shop_code}' and DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') + + + @tables = Table.unscope(:order).includes(:zone).all.active.order('status desc') + @rooms = Room.unscope(:order).includes(:zone).all.active.order('status desc') + @complete = Sale.completed_sale("cashier") + @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') + @customers = Customer.pluck("customer_id, name") @occupied_table = DiningFacility.where("shop_code='#{@shop.shop_code}' and status='occupied'").count @@ -20,10 +23,12 @@ class Origami::HomeController < BaseOrigamiController @print_settings = PrintSetting.get_precision_delimiter() @webview = check_mobile - @tables = Table.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') - @rooms = Room.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') - @complete = Sale.completed_sale("cashier",@shop.shop_code) - @orders = Order.includes("sale_orders").where("shop_code='#{@shop.shop_code}' and DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') + + @tables = Table.unscope(:order).includes(:zone).all.active.order('status desc') + @rooms = Room.unscope(:order).includes(:zone).all.active.order('status desc') + @complete = Sale.completed_sale("cashier") + @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') + @customers = Customer.pluck("customer_id, name") @shift = ShiftSale.current_open_shift(current_user) diff --git a/app/controllers/origami/in_duties_controller.rb b/app/controllers/origami/in_duties_controller.rb index 5210851b..0c1b3723 100755 --- a/app/controllers/origami/in_duties_controller.rb +++ b/app/controllers/origami/in_duties_controller.rb @@ -47,12 +47,6 @@ class Origami::InDutiesController < BaseOrigamiController def create_for_in_duty # this one use for create and update in_duty = in_duty_params - # in_time = DateTime.new in_duty['in_time(1i)'].to_i, in_duty['in_time(2i)'].to_i, in_duty['in_time(3i)'].to_i, in_duty['in_time(4i)'].to_i, in_duty['in_time(5i)'].to_i - # in_time = in_time.change(offset: '+06:30') - # out_time = DateTime.new in_duty['out_time(1i)'].to_i, in_duty['out_time(2i)'].to_i, in_duty['out_time(3i)'].to_i, in_duty['out_time(4i)'].to_i, in_duty['out_time(5i)'].to_i - # out_time = out_time.change(offset: '+06:30') - # puts in_duty.to_json - # puts "sssssssssssssssssss" @in_duty = InDuty.new in_duty_id = in_duty[:id] unless in_duty_id.empty? diff --git a/app/controllers/origami/jcb_controller.rb b/app/controllers/origami/jcb_controller.rb index 897d8bae..74bcdcd3 100644 --- a/app/controllers/origami/jcb_controller.rb +++ b/app/controllers/origami/jcb_controller.rb @@ -12,7 +12,7 @@ class Origami::JcbController < BaseOrigamiController end total = 0 @jcbcount = 0 - # @shop = Shop.first + @rounding_adj = 0 @can_jcb = 0 @member_discount= 0 @@ -66,8 +66,6 @@ class Origami::JcbController < BaseOrigamiController ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - # shop_details = Shop.first - # rounding adjustment # if shop_details.is_rounding_adj # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) @@ -86,9 +84,4 @@ class Origami::JcbController < BaseOrigamiController end end - #Shop Name in Navbor - # helper_method :shop_detail - # def shop_detail - # @shop = Shop.first - # end end diff --git a/app/controllers/origami/junction_pay_controller.rb b/app/controllers/origami/junction_pay_controller.rb index 67a9c748..f6a7fc78 100644 --- a/app/controllers/origami/junction_pay_controller.rb +++ b/app/controllers/origami/junction_pay_controller.rb @@ -11,7 +11,6 @@ class Origami::JunctionPayController < BaseOrigamiController @cashier_id = current_user.emp_id @payment_method_setting_nav = PaymentMethodSetting.all - # @shop = Shop.first if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else @@ -52,7 +51,6 @@ class Origami::JunctionPayController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - # shop_details = Shop.first # rounding adjustment # if shop_details.is_rounding_adj diff --git a/app/controllers/origami/master_controller.rb b/app/controllers/origami/master_controller.rb index 26a31b71..17fe4598 100644 --- a/app/controllers/origami/master_controller.rb +++ b/app/controllers/origami/master_controller.rb @@ -12,7 +12,6 @@ class Origami::MasterController < BaseOrigamiController end total = 0 @mastercount = 0 - # @shop = Shop.first @rounding_adj = 0 @can_master = 0 @member_discount = 0 @@ -63,7 +62,6 @@ class Origami::MasterController < BaseOrigamiController ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - # shop_details = Shop.first # rounding adjustment # if shop_details.is_rounding_adj @@ -83,10 +81,4 @@ class Origami::MasterController < BaseOrigamiController end end - - #Shop Name in Navbor - # helper_method :shop_detail - # def shop_detail - # @shop = Shop.first - # end end diff --git a/app/controllers/origami/movetable_controller.rb b/app/controllers/origami/movetable_controller.rb index 41c58941..1433a048 100755 --- a/app/controllers/origami/movetable_controller.rb +++ b/app/controllers/origami/movetable_controller.rb @@ -105,7 +105,7 @@ class Origami::MovetableController < BaseOrigamiController # @type = (DiningFacility.find(change_to)).type # @moved_by = @current_user.name # @date = DateTime.now - # @shop = Shop.first + # @shop = @shop # unique_code = "MoveTablePdf" # pdf_no = PrintSetting.where(:unique_code => unique_code).count # #print_settings = PrintSetting.find_by_unique_code(unique_code) diff --git a/app/controllers/origami/mpu_controller.rb b/app/controllers/origami/mpu_controller.rb index 2c8a1d29..89d6fe7f 100644 --- a/app/controllers/origami/mpu_controller.rb +++ b/app/controllers/origami/mpu_controller.rb @@ -11,7 +11,6 @@ class Origami::MpuController < BaseOrigamiController end total = 0 @mpucount = 0 - # @shop = Shop.first @rounding_adj = 0 @can_mpu = 0 @member_discount = 0 @@ -64,7 +63,6 @@ class Origami::MpuController < BaseOrigamiController ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - # shop_details = Shop.first # rounding adjustment # if shop_details.is_rounding_adj @@ -83,10 +81,4 @@ class Origami::MpuController < BaseOrigamiController @status, @sale = sale_payment.process_payment(saleObj, current_user, cash, "mpu",ref_no,payment_for) end end - - #Shop Name in Navbor - # helper_method :shop_detail - # def shop_detail - # @shop = Shop.first - # end end diff --git a/app/controllers/origami/order_reservation_controller.rb b/app/controllers/origami/order_reservation_controller.rb index 3bde49ec..b20656df 100644 --- a/app/controllers/origami/order_reservation_controller.rb +++ b/app/controllers/origami/order_reservation_controller.rb @@ -98,7 +98,7 @@ class Origami::OrderReservationController < BaseOrigamiController end def get_order_info - order_reservation = OrderReservation.where("status = 'new' and shop_code='#{@shop.shop_code}'").count() + order_reservation = OrderReservation.where("status = 'new' and shop_code='#{current_shop.shop_code}'").count() render :json => order_reservation end diff --git a/app/controllers/origami/orders_controller.rb b/app/controllers/origami/orders_controller.rb index 5f34d9a3..2a7c9aa3 100755 --- a/app/controllers/origami/orders_controller.rb +++ b/app/controllers/origami/orders_controller.rb @@ -5,8 +5,8 @@ class Origami::OrdersController < BaseOrigamiController @webview = true end - @tables = Table.unscoped.all.active.order('status desc') - @rooms = Room.unscoped.all.active.order('status desc') + @tables = Table.unscope(:order).all.active.order('status desc') + @rooms = Room.unscope(:order).all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @order = Order.find(params[:order_id]) diff --git a/app/controllers/origami/paymal_controller.rb b/app/controllers/origami/paymal_controller.rb index 91fa4790..a65319d2 100644 --- a/app/controllers/origami/paymal_controller.rb +++ b/app/controllers/origami/paymal_controller.rb @@ -6,7 +6,6 @@ class Origami::PaymalController < BaseOrigamiController @membership_rebate_balance=0 sale_data = Sale.find_by_sale_id(@sale_id) @receipt_no = sale_data.receipt_no - # @shop = Shop.first if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else @@ -74,7 +73,6 @@ def create account_no = params[:account_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - # shop_details = Shop.first # rounding adjustment # if shop_details.is_rounding_adj diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index fac5937a..cc9c510e 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -59,7 +59,7 @@ class Origami::PaymentsController < BaseOrigamiController end #shop detail - ## shop_detail = Shop.first + ## shop_detail = @shop # customer= Customer.where('customer_id=' +.customer_id) customer = Customer.find(sale_data.customer_id) # rounding adjustment @@ -113,7 +113,7 @@ class Origami::PaymentsController < BaseOrigamiController end end - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, status, qr, cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, @shop, "Frt",current_balance,nil,other_amount,nil,nil,nil) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, status, qr, cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, @shop, "Frt",current_balance,nil,other_amount,nil,nil,nil,nil) result = { :filepath => filename, @@ -141,7 +141,7 @@ class Origami::PaymentsController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) sale_items = SaleItem.get_all_sale_items(sale_id) - #shop_detail = Shop.first + #shop_detail = @shop # rounding adjustment if !path.include? ("credit_payment") if @shop.is_rounding_adj @@ -176,14 +176,14 @@ class Origami::PaymentsController < BaseOrigamiController # For Cashier by Zone # bookings = Booking.where("sale_id='#{sale_id}'") - bookings = Booking.find_by_sale_id(sale_id) + bookings = saleObj.bookings[0] shift = ShiftSale.current_open_shift(current_user) if !shift.nil? cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) else if bookings.dining_facility_id.to_i > 0 - table = DiningFacility.find(bookings.dining_facility_id) + table = bookings.dining_facility cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) @@ -278,7 +278,7 @@ class Origami::PaymentsController < BaseOrigamiController end #card_balance amount for Paymal payment - card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id) + card_balance_amount,transaction_ref = SaleAudit.getCardBalanceAmount(sale_id) # get printer info print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code) @@ -288,7 +288,7 @@ class Origami::PaymentsController < BaseOrigamiController other_amount = SaleItem.calculate_other_charges(sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref) #end end @@ -577,7 +577,7 @@ class Origami::PaymentsController < BaseOrigamiController customer= Customer.find(saleObj.customer_id) #shop detail - #shop_detail = Shop.first + #shop_detail = @shop # get member information rebate = MembershipSetting.find_by_rebate(1) if customer.membership_id != nil && rebate @@ -600,7 +600,7 @@ class Origami::PaymentsController < BaseOrigamiController end #card_balance amount for Paymal payment - card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id) + card_balance_amount,transaction_ref = SaleAudit.getCardBalanceAmount(sale_id) # get printer info print_settings=PrintSetting.find_by_unique_code(unique_code) @@ -612,7 +612,7 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref) result = { :status => true, @@ -686,8 +686,9 @@ class Origami::PaymentsController < BaseOrigamiController customer= Customer.find(saleObj.customer_id) #shop detail - #shop_detail = Shop.first - printer = PrintSetting.where("shop_code='#{@shop.shop_code}'") + + #shop_detail = @shop + printer = PrintSetting.all unique_code="ReceiptBillPdf" if !printer.empty? @@ -711,7 +712,7 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "FOC",nil,nil,other_amount,nil,nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "FOC",nil,nil,other_amount,nil,nil,nil,nil) result = { :status => true, :filepath => filename, diff --git a/app/controllers/origami/paypar_payments_controller.rb b/app/controllers/origami/paypar_payments_controller.rb index 70a3aef5..59ddb912 100755 --- a/app/controllers/origami/paypar_payments_controller.rb +++ b/app/controllers/origami/paypar_payments_controller.rb @@ -7,8 +7,6 @@ class Origami::PayparPaymentsController < BaseOrigamiController payment_method = "paypar" if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - # shop_details = Shop.first - # rounding adjustment if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(saleObj.grand_total) diff --git a/app/controllers/origami/quick_service_controller.rb b/app/controllers/origami/quick_service_controller.rb index f57189d0..8f0c5c92 100644 --- a/app/controllers/origami/quick_service_controller.rb +++ b/app/controllers/origami/quick_service_controller.rb @@ -13,12 +13,12 @@ class Origami::QuickServiceController < ApplicationController # if params[:menu] == "true" @menus = [] @menu = [] - @zone = Zone.all.where("shop_code='#{@shop.shop_code}'") + @zone = Zone.all @customer = Customer.all - @tables = Table.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') - @rooms = Room.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') + @tables = Table.all.active.order('status desc') + @rooms = Room.all.active.order('status desc') @cashier_type = "quick_service" - display_type = Lookup.find_by_lookup_type_and_shop_code("display_type",@shop.shop_code) + display_type = Lookup.find_by_lookup_type("display_type") if !display_type.nil? && display_type.value.to_i ==2 @display_type = display_type.value else @@ -137,10 +137,8 @@ class Origami::QuickServiceController < ApplicationController def get_menu_category () if (params[:id]) - puts params[:id] #Pull this menu @menu = MenuCategory.find_by_id(params[:id]) - # puts @menu.menu_items[1].item_attributes.to_json return @menu else MenuCategory.current_menu @@ -153,7 +151,6 @@ class Origami::QuickServiceController < ApplicationController if (id) #Pull this menu @sub_menu = MenuCategory.where("menu_category_id = #{id}").active - # puts @menu.menu_items[1].item_attributes.to_json return @sub_menu end end @@ -174,7 +171,6 @@ class Origami::QuickServiceController < ApplicationController table = DiningFacility.find(table_id) if table booking = table.get_current_booking - # puts booking if booking if !booking.sale_id.nil? if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new" diff --git a/app/controllers/origami/redeem_payments_controller.rb b/app/controllers/origami/redeem_payments_controller.rb index 4a2d867a..6b7802cf 100755 --- a/app/controllers/origami/redeem_payments_controller.rb +++ b/app/controllers/origami/redeem_payments_controller.rb @@ -5,8 +5,6 @@ class Origami::RedeemPaymentsController < BaseOrigamiController @cashier_type = params[:type] @membership_rebate_balance=0 sale_data = Sale.find_by_sale_id(@sale_id) - - # @shop = Shop.first if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index c23d4964..137aa774 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -8,7 +8,7 @@ class Origami::RequestBillsController < ApplicationController end # Print Request Bill and add to sale tables def print - if !ShiftSale.current_shift(@shop.shop_code).nil? + if !ShiftSale.current_shift.nil? order_id = params[:id] # order_id order = Order.find(order_id) booking = order.booking @@ -45,7 +45,7 @@ class Origami::RequestBillsController < ApplicationController sale_audit = SaleAudit.record_audit_sale(sale_data.sale_id,remark,action_by,type ) # Promotion Activation - Promotion.promo_activate(sale_data,@shop.shop_code) + Promotion.promo_activate(sale_data) #bill channel if ENV["SERVER_MODE"] == 'cloud' @@ -90,7 +90,7 @@ class Origami::RequestBillsController < ApplicationController # Not Use for these printed bill cannot give customer # unique_code = "ReceiptBillPdf" # #shop detail - # shop_details = Shop.find(1) + # shop_details = @shop # # customer= Customer.where('customer_id=' +.customer_id) # customer= Customer.find(@sale_data.customer_id) # # get member information diff --git a/app/controllers/origami/room_invoices_controller.rb b/app/controllers/origami/room_invoices_controller.rb index 8d805771..c73c153a 100755 --- a/app/controllers/origami/room_invoices_controller.rb +++ b/app/controllers/origami/room_invoices_controller.rb @@ -1,10 +1,8 @@ class Origami::RoomInvoicesController < BaseOrigamiController def index @room = DiningFacility.find(params[:room_id]) - puts "room bookig lenght" @sale_array = Array.new @room.bookings.each do |booking| - puts booking.sale_id if booking.sale_id.nil? else diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index c7c19930..a567851f 100755 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -1,8 +1,9 @@ class Origami::RoomsController < BaseOrigamiController def index - @tables = Table.unscoped.all.active.order('status desc') - @rooms = Room.unscoped.all.active.order('status desc') - @complete = Sale.completed_sale("cashier",@shop.shop_code) + + @tables = Table.unscope(:order).all.active.order('status desc') + @rooms = Room.unscope(:order).all.active.order('status desc') + @complete = Sale.completed_sale("cashier") @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @shift = ShiftSale.current_open_shift(current_user) @webview = false @@ -17,9 +18,10 @@ class Origami::RoomsController < BaseOrigamiController @webview = true end - @tables = Table.unscoped.all.active.order('status desc') - @rooms = Room.unscoped.all.active.order('status desc') - @complete = Sale.completed_sale("cashier",@shop.shop_code) + + @tables = Table.unscope(:order).all.active.order('status desc') + @rooms = Room.unscope(:order).all.active.order('status desc') + @complete = Sale.completed_sale("cashier") @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @customers = Customer.pluck("customer_id, name") @room = DiningFacility.find(params[:room_id]) @@ -30,7 +32,8 @@ class Origami::RoomsController < BaseOrigamiController @sale_array = Array.new @membership = MembershipSetting.find_by_shop_code(@shop.shop_code) @payment_methods = PaymentMethodSetting.find_by_shop_code(@shop.shop_code) - + @membership = MembershipSetting::MembershipSetting + @payment_methods = PaymentMethodSetting.all @dining_room = @room.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ") @order_items = Array.new @dining_room.each do |booking| diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index 7c9ec35e..57c1dc93 100755 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -163,8 +163,6 @@ class Origami::SaleEditController < BaseOrigamiController # end # end - sale.compute_by_sale_items(sale.total_discount, nil, order_source) - ProductCommission.edit_product_commission(saleitemObj,sale.shop_code) end diff --git a/app/controllers/origami/sales_controller.rb b/app/controllers/origami/sales_controller.rb index 4e20e293..6aef2b0c 100755 --- a/app/controllers/origami/sales_controller.rb +++ b/app/controllers/origami/sales_controller.rb @@ -5,9 +5,10 @@ class Origami::SalesController < BaseOrigamiController @webview = true end - @tables = Table.unscoped.all.active.order('status desc') - @rooms = Room.unscoped.all.active.order('status desc') - @complete = Sale.completed_sale("cashier",@shop.shop_code) + + @tables = Table.unscope(:order).all.active.order('status desc') + @rooms = Room.unscope(:order).all.active.order('status desc') + @complete = Sale.completed_sale("cashier") @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @customers = Customer.pluck("customer_id, name") @sale = Sale.find(params[:sale_id]) diff --git a/app/controllers/origami/second_display_controller.rb b/app/controllers/origami/second_display_controller.rb index 21c0674d..c8277ef7 100644 --- a/app/controllers/origami/second_display_controller.rb +++ b/app/controllers/origami/second_display_controller.rb @@ -27,7 +27,7 @@ class Origami::SecondDisplayController < BaseOrigamiController #Shop Name in Navbor # helper_method :shop_detail # def shop_detail - # @shop = Shop.first + # # end diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 15f0d2d9..3fcfe704 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -88,7 +88,6 @@ class Origami::ShiftsController < BaseOrigamiController end end end - shop_details = shop_detail #get tax shift_obj = ShiftSale.where('id =?',@shift.id) sale_items = '' @@ -125,7 +124,9 @@ class Origami::ShiftsController < BaseOrigamiController end find_close_cashier_print = Lookup.collection_of('close_cashier_print') if find_close_cashier_print[0][1].to_i > 0 - printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments) + + + printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, @shop,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments) end end end diff --git a/app/controllers/origami/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb index a80a3a4d..80a6070f 100755 --- a/app/controllers/origami/split_bill_controller.rb +++ b/app/controllers/origami/split_bill_controller.rb @@ -158,15 +158,8 @@ class Origami::SplitBillController < BaseOrigamiController end end - # puts order_id - # puts order_ids.count - # puts order_id_count - # puts order_items.count - # puts order_item_count - if !order_id.nil? if order_id_count > 1 - puts "order_id_count > 1" updated_order_id = Array.new arr_order_ids.each do |order| @@ -178,9 +171,6 @@ class Origami::SplitBillController < BaseOrigamiController end end - # puts "updated_order_id" - # puts updated_order_id - if !updated_order_id.empty? order_ids.each do |odr_id| unless updated_order_id.include?(odr_id) @@ -208,8 +198,6 @@ class Origami::SplitBillController < BaseOrigamiController end end - # puts new_order_status - if new_order_status BookingOrder.find_by_order_id(odr_id).delete BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id}) @@ -236,7 +224,6 @@ class Origami::SplitBillController < BaseOrigamiController end end else - # puts "order_id_count < 1" new_order_status = true order_items.each do |order_item| orderItem = OrderItem.find(order_item["id"]) @@ -249,8 +236,6 @@ class Origami::SplitBillController < BaseOrigamiController end end - # puts new_order_status - if new_order_status BookingOrder.find_by_order_id(order_id).delete BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_id}) @@ -334,7 +319,7 @@ class Origami::SplitBillController < BaseOrigamiController end end - Promotion.promo_activate(sale_data,@shop.shop_code) + Promotion.promo_activate(sale_data) if ENV["SERVER_MODE"] == 'cloud' from = request.subdomain + "." + request.domain else @@ -411,5 +396,4 @@ class Origami::SplitBillController < BaseOrigamiController render :json => { status: true } end - end diff --git a/app/controllers/origami/table_invoices_controller.rb b/app/controllers/origami/table_invoices_controller.rb index a5d72b1e..e3265710 100755 --- a/app/controllers/origami/table_invoices_controller.rb +++ b/app/controllers/origami/table_invoices_controller.rb @@ -1,11 +1,8 @@ class Origami::TableInvoicesController < BaseOrigamiController def index @table = DiningFacility.find(params[:table_id]) - # shop = Shop.first - puts "table bookig lenght" @sale_array = Array.new @table.bookings.each do |booking| - puts booking.sale_id if booking.sale_id.nil? else @@ -30,12 +27,10 @@ class Origami::TableInvoicesController < BaseOrigamiController end def show - # puts 'Catch me if you can.......................' @table = DiningFacility.find(params[:table_id]) - @membership = MembershipSetting.find_by_shop_code(@shop.shop_code) - @payment_methods = PaymentMethodSetting.where("shop_code='#{@shop.shop_code}'") - # shop = Shop.first + @membership = MembershipSetting::MembershipSetting + @payment_methods = PaymentMethodSetting.all @sale_array = Array.new @table.bookings.each do |booking| if booking.sale_id.nil? diff --git a/app/controllers/origami/unionpay_controller.rb b/app/controllers/origami/unionpay_controller.rb index aaa05922..2f708af3 100644 --- a/app/controllers/origami/unionpay_controller.rb +++ b/app/controllers/origami/unionpay_controller.rb @@ -11,7 +11,6 @@ class Origami::UnionpayController < BaseOrigamiController end total = 0 @unionpaycount = 0 - # @shop = Shop.first @rounding_adj = 0 @can_unionpay = 0 @member_discount = 0 @@ -61,8 +60,6 @@ class Origami::UnionpayController < BaseOrigamiController ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - # shop_details = Shop.first - # rounding adjustment # if shop_details.is_rounding_adj # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) @@ -81,10 +78,4 @@ class Origami::UnionpayController < BaseOrigamiController @status, @sale = sale_payment.process_payment(saleObj, current_user, cash, "unionpay",ref_no,payment_for) end end - - #Shop Name in Navbor - # helper_method :shop_detail - # def shop_detail - # @shop = Shop.first - # end end diff --git a/app/controllers/origami/visa_controller.rb b/app/controllers/origami/visa_controller.rb index 7463e271..a2e43d5a 100644 --- a/app/controllers/origami/visa_controller.rb +++ b/app/controllers/origami/visa_controller.rb @@ -11,7 +11,6 @@ class Origami::VisaController < BaseOrigamiController end total = 0 @visacount = 0 - # @shop = Shop.first @rounding_adj = 0 @can_visa = 0 @member_discount = 0 @@ -61,8 +60,6 @@ class Origami::VisaController < BaseOrigamiController ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - # shop_details = Shop.first - # rounding adjustment # if shop_details.is_rounding_adj # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) @@ -81,10 +78,4 @@ class Origami::VisaController < BaseOrigamiController @status, @sale = sale_payment.process_payment(saleObj, current_user, cash, "visa",ref_no,payment_for) end end - - #Shop Name in Navbor - # helper_method :shop_detail - # def shop_detail - # @shop = Shop.first - # end end diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 5f5b5352..d0d001c2 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -1,7 +1,6 @@ class Origami::VoidController < BaseOrigamiController authorize_resource :class => false def overall_void - sale_id = params[:sale_id] remark = params[:remark] order_source = params[:type] #tax profile source @@ -114,7 +113,6 @@ class Origami::VoidController < BaseOrigamiController # end customer= Customer.find(sale.customer_id) - # get member information rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code) if customer.membership_id != nil && rebate @@ -145,7 +143,7 @@ class Origami::VoidController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) other_amount = SaleItem.calculate_other_charges(sale.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "VOID",current_balance,nil,other_amount,nil,nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "VOID",current_balance,nil,other_amount,nil,nil,nil,nil) result = { :filepath => filename, :printer_model => print_settings.brand_name, diff --git a/app/controllers/origami/voucher_controller.rb b/app/controllers/origami/voucher_controller.rb index 671eb9fc..196d93c4 100755 --- a/app/controllers/origami/voucher_controller.rb +++ b/app/controllers/origami/voucher_controller.rb @@ -7,8 +7,6 @@ class Origami::VoucherController < BaseOrigamiController total = sale_data.grand_total @vouchercount = 0 others = 0 - - # @shop = Shop.first if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else diff --git a/app/controllers/origami/waste_spoile_controller.rb b/app/controllers/origami/waste_spoile_controller.rb index 82c63d80..13a70728 100755 --- a/app/controllers/origami/waste_spoile_controller.rb +++ b/app/controllers/origami/waste_spoile_controller.rb @@ -1,6 +1,5 @@ class Origami::WasteSpoileController < BaseOrigamiController def waste_and_spoilage - sale_id = params[:sale_id] remark = params[:remark] order_source = params[:type] @@ -87,7 +86,6 @@ class Origami::WasteSpoileController < BaseOrigamiController # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server # unique_code = "ReceiptBillPdf" customer= Customer.find(sale.customer_id) - # get member information rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code) if customer.membership_id != nil && rebate @@ -119,7 +117,7 @@ class Origami::WasteSpoileController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) other_amount = SaleItem.calculate_other_charges(sale.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, remark,current_balance,nil,other_amount,nil,nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, remark,current_balance,nil,other_amount,nil,nil,nil,nil) result = { :filepath => filename, :printer_model => print_settings.brand_name, diff --git a/app/controllers/reports/hourly_saleitem_controller.bk.rb b/app/controllers/reports/hourly_saleitem_controller.bk.rb index 88a61335..ab4f81ea 100644 --- a/app/controllers/reports/hourly_saleitem_controller.bk.rb +++ b/app/controllers/reports/hourly_saleitem_controller.bk.rb @@ -27,9 +27,7 @@ class Reports::HourlySaleitemController < BaseReportController account_type = params[:account_type] @type = params[:sale_type] @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) - logger.debug 'product>>>>>>>>>>>>>>>>>>>>>>>>>>' - # logger.debug @sale_data.group_by {|s| s.date_format }.collect{|key,qty| {"Date" =>key , "total_qty" => qty.sum{|d| d.qty.to_i}}} - + @hourly_total_qty = @sale_data.group_by {|s| s.date_format }.collect{|key,qty| {"date" => key , "total_qty" => qty.sum{|d| d.qty.to_i}}} logger.debug @hourly_total_qty diff --git a/app/controllers/reports/hourly_saleitem_controller.rb b/app/controllers/reports/hourly_saleitem_controller.rb index 97264236..bcb5c877 100644 --- a/app/controllers/reports/hourly_saleitem_controller.rb +++ b/app/controllers/reports/hourly_saleitem_controller.rb @@ -1,7 +1,6 @@ class Reports::HourlySaleitemController < BaseReportController authorize_resource :class => false def index - @account = Account.where("shop_code='#{@shop.shop_code}'") from, to = get_date_range_from_params diff --git a/app/controllers/reports/payment_method_controller.rb b/app/controllers/reports/payment_method_controller.rb index beec5dd9..244e2974 100644 --- a/app/controllers/reports/payment_method_controller.rb +++ b/app/controllers/reports/payment_method_controller.rb @@ -1,11 +1,10 @@ class Reports::PaymentMethodController < BaseReportController # authorize_resource :class => false def index - @payments = [["All Payment",''],["Cash Payment","cash"], ["KBZ Payment", KbzPay::KBZ_PAY], ["Credit Payment","creditnote"], ["FOC Payment","foc"], ["MPU Payment","mpu"], ["Visa Payment","visa"], ["Master Payment","master"], ["JCB Payment","jcb"],["UnionPay Payment","unionpay"], - ["Alipay Payment","alipay"],["Paymal Payment", "paymal"],["Dinga Payment","dinga"], + ["Alipay Payment","alipay"],["Card Payment", "paymal"],["Dinga Payment","dinga"], ["JunctionPay","junctionpay"],["Redeem Payment","paypar"],["Gift Voucher","giftvoucher"]] from, to = get_date_range_from_params diff --git a/app/controllers/reports/product_sale_controller.rb b/app/controllers/reports/product_sale_controller.rb index 9791545e..eb4c6530 100644 --- a/app/controllers/reports/product_sale_controller.rb +++ b/app/controllers/reports/product_sale_controller.rb @@ -7,21 +7,15 @@ class Reports::ProductSaleController < BaseReportController @order_by = params[:order_by] end - @sale_data = Sale.get_menu_item_query(@order_by) + @sale_data = Sale.get_menu_item_query(@order_by) - # get printer info - @print_settings = PrintSetting.get_precision_delimiter() + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() respond_to do |format| format.html - format.json + format.json format.xls end - end - - #Shop Name in Navbor - helper_method :shop_detail - def shop_detail - @shop = Shop.first end end diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb index d8a6416f..5da8f9de 100755 --- a/app/controllers/reports/receipt_no_controller.rb +++ b/app/controllers/reports/receipt_no_controller.rb @@ -76,6 +76,7 @@ authorize_resource :class => false end def sync_data + @orders, @order_items, @sales, @sale_items, @sale_taxes, @sale_payments, @sale_orders, @sale_audits, @bookings, @assigned_order_items, @shift_sales = Booking.get_sync_data(params[:sale_id]) # Here comes to call the sync api @@ -112,7 +113,6 @@ authorize_resource :class => false rescue Net::OpenTimeout response = { status: false, message: "Can't open membership server "} rescue OpenURI::HTTPError - puts "Fire in here" response = { status: false, message: "Can't open membership server "} rescue SocketError response = { status: false, message: "Can't open server "} @@ -121,9 +121,6 @@ authorize_resource :class => false rescue Errno::ECONNREFUSED, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError response = { status: false, message: "Can't open membership server"} end - - puts url - puts response @message = @result.parsed_response['message'] end @@ -183,7 +180,7 @@ authorize_resource :class => false customer= Customer.find(saleObj.customer_id) #shop detail - #shop_detail = Shop.first + #shop_detail = @shop # get member information rebate = MembershipSetting.find_by_rebate(1) if customer.membership_id != nil && rebate @@ -206,7 +203,7 @@ authorize_resource :class => false end #card_balance amount for Paymal payment - card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id) + card_balance_amount,transaction_ref = SaleAudit.getCardBalanceAmount(sale_id) # get printer info print_settings=PrintSetting.find_by_unique_code(unique_code) @@ -218,7 +215,7 @@ authorize_resource :class => false printer = Printer::ReceiptPrinter.new(print_settings) - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref) result = { :status => true, diff --git a/app/controllers/reports/receipt_no_detail_controller.rb b/app/controllers/reports/receipt_no_detail_controller.rb index d3b738c5..59bf70c5 100755 --- a/app/controllers/reports/receipt_no_detail_controller.rb +++ b/app/controllers/reports/receipt_no_detail_controller.rb @@ -10,11 +10,11 @@ authorize_resource :class => false @shift = '' if params[:shift_name].to_i != 0 - @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'") + @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @shift_sale = ShiftSale.find(params[:shift_name]) if to.blank? - @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",@shift_sale.shift_started_at) + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',@shift_sale.shift_started_at) else if @shift_sale.shift_closed_at.blank? @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",@shift_sale.shift_started_at) @@ -25,8 +25,10 @@ authorize_resource :class => false end payment_type = params[:payment_type] + @sale_data = Sale.get_shift_sales_by_receipt_no_detail(@shift_sale_range,@shift,from,to,payment_type).where("sales.shop_code='#{@shop.shop_code}'") + @from = from @to = to # get printer info diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index 57680e07..a9cf0139 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -1,7 +1,6 @@ class Reports::SaleitemController < BaseReportController authorize_resource :class => false def index - @account = Account.where("shop_code='#{@shop.shop_code}'") from, to = get_date_range_from_params diff --git a/app/controllers/reports/shiftsale_controller.rb b/app/controllers/reports/shiftsale_controller.rb index 5f842790..4e9d7f17 100755 --- a/app/controllers/reports/shiftsale_controller.rb +++ b/app/controllers/reports/shiftsale_controller.rb @@ -2,7 +2,7 @@ class Reports::ShiftsaleController < BaseReportController authorize_resource :class => false def index - + from, to = get_date_range_from_params @shift = '' if params[:shift_name].to_i != 0 @@ -26,6 +26,7 @@ class Reports::ShiftsaleController < BaseReportController end def show + from, to = get_date_range_from_params @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'") @@ -49,6 +50,7 @@ class Reports::ShiftsaleController < BaseReportController end def print_close_receipt + shift_id = params[:id] @shift = ShiftSale.find_by_id(shift_id) shift_obj = ShiftSale.where('id =?',shift_id) diff --git a/app/controllers/reports/staff_meal_controller.rb b/app/controllers/reports/staff_meal_controller.rb index 7049ec27..7a478847 100644 --- a/app/controllers/reports/staff_meal_controller.rb +++ b/app/controllers/reports/staff_meal_controller.rb @@ -1,7 +1,7 @@ class Reports::StaffMealController < BaseReportController authorize_resource :class => false def index - + @account = Account.where("shop_code='#{@shop.shop_code}'") from, to = get_date_range_from_params diff --git a/app/controllers/reports/stock_check_controller.rb b/app/controllers/reports/stock_check_controller.rb index 6b6d88d6..48d28f42 100755 --- a/app/controllers/reports/stock_check_controller.rb +++ b/app/controllers/reports/stock_check_controller.rb @@ -2,6 +2,7 @@ class Reports::StockCheckController < BaseReportController # authorize_resource :class => false def index + # from_date = DateTime.now.beginning_of_day.utc.getlocal # to_date = DateTime.now.end_of_day.utc.getlocal # unless params[:daterange].blank? @@ -25,6 +26,7 @@ class Reports::StockCheckController < BaseReportController end def show + from, to = get_date_range_from_params @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'") diff --git a/app/controllers/reports/void_sale_controller.rb b/app/controllers/reports/void_sale_controller.rb index c31b030a..425844b8 100755 --- a/app/controllers/reports/void_sale_controller.rb +++ b/app/controllers/reports/void_sale_controller.rb @@ -1,7 +1,7 @@ class Reports::VoidSaleController < BaseReportController authorize_resource :class => false def index - + from, to = get_date_range_from_params # @shift_sale_range = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) @@ -9,10 +9,10 @@ authorize_resource :class => false if params[:shift_name].to_i != 0 shift_sale = ShiftSale.find(params[:shift_name]) if to.blank? - @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#@shop.shop_code' ",shift_sale.shift_started_at) + @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}' ",shift_sale.shift_started_at) else - @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at = ? and shop_code='#@shop.shop_code' ",shift_sale.shift_started_at, shift_sale.shift_closed_at) + @shift = ShiftSale.where("shift_started_at = ? and shift_closed_at = ? and shop_code='#{@shop.shop_code}' ",shift_sale.shift_started_at, shift_sale.shift_closed_at) end end diff --git a/app/controllers/reports/waste_and_spoilage_controller.rb b/app/controllers/reports/waste_and_spoilage_controller.rb index ccf8a47f..4b15cc01 100755 --- a/app/controllers/reports/waste_and_spoilage_controller.rb +++ b/app/controllers/reports/waste_and_spoilage_controller.rb @@ -1,6 +1,7 @@ class Reports::WasteAndSpoilageController < BaseReportController authorize_resource :class => false def index + from, to = get_date_range_from_params @sale_type = params[:sale_type] @sale_data = Sale.get_wastes_and_spoilages(from,to,@sale_type).where("sales.shop_code='#{@shop.shop_code}'") diff --git a/app/controllers/settings/accounts_controller.rb b/app/controllers/settings/accounts_controller.rb index d46ba093..ca6aa027 100755 --- a/app/controllers/settings/accounts_controller.rb +++ b/app/controllers/settings/accounts_controller.rb @@ -5,6 +5,7 @@ class Settings::AccountsController < ApplicationController # GET /settings/accounts # GET /settings/accounts.json def index + @settings_accounts = Account.all.where("shop_code='#{@shop.shop_code}'") end @@ -25,6 +26,7 @@ class Settings::AccountsController < ApplicationController # POST /settings/accounts # POST /settings/accounts.json def create + @settings_account = Account.new(account_params) @settings_account.shop_code = @shop.shop_code respond_to do |format| diff --git a/app/controllers/settings/cashier_terminals_controller.rb b/app/controllers/settings/cashier_terminals_controller.rb index 29fe202f..cb875a6b 100755 --- a/app/controllers/settings/cashier_terminals_controller.rb +++ b/app/controllers/settings/cashier_terminals_controller.rb @@ -5,7 +5,7 @@ class Settings::CashierTerminalsController < ApplicationController # GET /settings/cashier_terminals # GET /settings/cashier_terminals.json def index - @settings_cashier_terminals = CashierTerminal.all + @settings_cashier_terminals = CashierTerminal.where("shop_code=?",@shop.shop_code) end # GET /settings/cashier_terminals/1 @@ -27,6 +27,7 @@ class Settings::CashierTerminalsController < ApplicationController # POST /settings/cashier_terminals # POST /settings/cashier_terminals.json def create + @settings_cashier_terminal = CashierTerminal.new(settings_cashier_terminal_params) @settings_cashier_terminal.shop_code = @shop.shop_code respond_to do |format| diff --git a/app/controllers/settings/commissioners_controller.rb b/app/controllers/settings/commissioners_controller.rb index 0f93545d..24cc484b 100755 --- a/app/controllers/settings/commissioners_controller.rb +++ b/app/controllers/settings/commissioners_controller.rb @@ -28,6 +28,7 @@ class Settings::CommissionersController < ApplicationController # POST /commissioners # POST /commissioners.json def create + @commissioner = Commissioner.new(commissioner_params) @commissioner.created_by = current_user.id @commissioner.shop_code = @shop.shop_code @@ -37,7 +38,6 @@ class Settings::CommissionersController < ApplicationController unless @commissioner.resigned_date.nil? @commissioner.resigned_date = @commissioner.resigned_date.utc.getlocal.strftime('%Y-%b-%d') end - # puts params[:from_induty].length if (params[:from_induty] != "true") respond_to do |format| if @commissioner.save diff --git a/app/controllers/settings/commissions_controller.rb b/app/controllers/settings/commissions_controller.rb index 519074c7..60778dab 100755 --- a/app/controllers/settings/commissions_controller.rb +++ b/app/controllers/settings/commissions_controller.rb @@ -28,6 +28,7 @@ class Settings::CommissionsController < ApplicationController # POST /commissions # POST /commissions.json def create + @commission = Commission.new(commission_params) @commission.product_type = 'menu_item' @commission.product_code = "[]" diff --git a/app/controllers/settings/employees_controller.rb b/app/controllers/settings/employees_controller.rb index 5c9dae6f..140ff2c0 100755 --- a/app/controllers/settings/employees_controller.rb +++ b/app/controllers/settings/employees_controller.rb @@ -31,7 +31,7 @@ class Settings::EmployeesController < ApplicationController # POST /employees.json def create @employee = Employee.new(employee_params) - @employee.shop_code = @shop.shop_code + @employee.shop_code =current_shop.shop_code respond_to do |format| if @employee.save format.html { redirect_to settings_employees_path, notice: 'Employee was successfully created.' } diff --git a/app/controllers/settings/lookups_controller.rb b/app/controllers/settings/lookups_controller.rb index 87c81842..4390dadd 100755 --- a/app/controllers/settings/lookups_controller.rb +++ b/app/controllers/settings/lookups_controller.rb @@ -25,7 +25,7 @@ class Settings::LookupsController < ApplicationController # POST /settings/lookups.json def create @settings_lookup = Lookup.new(settings_lookup_params) - @settings_lookup.shop_code = @shop.shop_code + @settings_lookup.shop_code = current_shop.shop_code respond_to do |format| if @settings_lookup.save format.html { redirect_to settings_lookups_path, notice: 'Lookup was successfully created.' } diff --git a/app/controllers/settings/membership_actions_controller.rb b/app/controllers/settings/membership_actions_controller.rb index 0f1b8c93..f6eb77bf 100755 --- a/app/controllers/settings/membership_actions_controller.rb +++ b/app/controllers/settings/membership_actions_controller.rb @@ -25,6 +25,7 @@ class Settings::MembershipActionsController < ApplicationController # POST /settings/membership_actions # POST /settings/membership_actions.json def create + @settings_membership_action = MembershipAction.new(settings_membership_action_params) @settings_membership_action.shop_code = @shop.shop_code respond_to do |format| diff --git a/app/controllers/settings/membership_settings_controller.rb b/app/controllers/settings/membership_settings_controller.rb index 698c755c..2e128ce0 100755 --- a/app/controllers/settings/membership_settings_controller.rb +++ b/app/controllers/settings/membership_settings_controller.rb @@ -25,6 +25,7 @@ class Settings::MembershipSettingsController < ApplicationController # POST /settings/membership_settings # POST /settings/membership_settings.json def create + @settings_membership_setting = MembershipSetting.new(settings_membership_setting_params) @settings_membership_setting.shop_code = @shop.shop_code respond_to do |format| diff --git a/app/controllers/settings/menus_controller.rb b/app/controllers/settings/menus_controller.rb index d7cb6b8a..e449dd38 100755 --- a/app/controllers/settings/menus_controller.rb +++ b/app/controllers/settings/menus_controller.rb @@ -5,6 +5,7 @@ class Settings::MenusController < ApplicationController # GET /settings/menus # GET /settings/menus.json def index + @settings_menus = Menu.all.where("shop_code='#{@shop.shop_code}'").page(params[:page]).per(10) respond_to do |format| format.html @@ -30,6 +31,7 @@ class Settings::MenusController < ApplicationController # POST /settings/menus # POST /settings/menus.json def create + @settings_menu = Menu.new(settings_menu_params) @settings_menu.created_by = current_login_employee.name @settings_menu.shop_code = @shop.shop_code @@ -74,6 +76,7 @@ class Settings::MenusController < ApplicationController end def export + @settings_menus = Menu.all.where("shop_code='#{@shop.shop_code}'").page(params[:page]).per(10) menu = Menu.find(params[:id]) diff --git a/app/controllers/settings/order_queue_stations_controller.rb b/app/controllers/settings/order_queue_stations_controller.rb index d28bdd91..aa856801 100755 --- a/app/controllers/settings/order_queue_stations_controller.rb +++ b/app/controllers/settings/order_queue_stations_controller.rb @@ -29,6 +29,7 @@ class Settings::OrderQueueStationsController < ApplicationController # POST /settings/order_queue_stations # POST /settings/order_queue_stations.json def create + @settings_order_queue_station = OrderQueueStation.new(settings_order_queue_station_params) @settings_order_queue_station.created_by = current_login_employee.name @settings_order_queue_station.processing_items = "[]" diff --git a/app/controllers/settings/payment_method_settings_controller.rb b/app/controllers/settings/payment_method_settings_controller.rb index 74b2a10b..e85e7a99 100755 --- a/app/controllers/settings/payment_method_settings_controller.rb +++ b/app/controllers/settings/payment_method_settings_controller.rb @@ -41,7 +41,6 @@ class Settings::PaymentMethodSettingsController < ApplicationController # PATCH/PUT /settings/payment_method_settings/1 # PATCH/PUT /settings/payment_method_settings/1.json def update - puts settings_payment_method_setting_params respond_to do |format| if @settings_payment_method_setting.update(settings_payment_method_setting_params) format.html { redirect_to settings_payment_method_setting_path(@settings_payment_method_setting), notice: 'Payment method setting was successfully updated.' } diff --git a/app/controllers/settings/products_controller.rb b/app/controllers/settings/products_controller.rb index b473a54e..4562d132 100755 --- a/app/controllers/settings/products_controller.rb +++ b/app/controllers/settings/products_controller.rb @@ -26,7 +26,7 @@ load_and_authorize_resource except: [:create] # POST /settings/products # POST /settings/products.json def create - + @settings_product = Product.new(settings_product_params) @settings_product.created_by = current_user.name @settings_product.shop_code = @shop.shop_code diff --git a/app/controllers/settings/promotions_controller.rb b/app/controllers/settings/promotions_controller.rb index 9f3c8fcf..442a2063 100755 --- a/app/controllers/settings/promotions_controller.rb +++ b/app/controllers/settings/promotions_controller.rb @@ -28,6 +28,7 @@ class Settings::PromotionsController < ApplicationController # POST /promotions # POST /promotions.json def create + @promotion = Promotion.new(promotion_params) @promotion.created_by = current_login_employee.id @promotion.shop_code = @shop.shop_code @@ -117,8 +118,6 @@ class Settings::PromotionsController < ApplicationController end res.push({item_inst.menu_item.item_code => arr_inst}) end - puts "res" - p res render json: res end diff --git a/app/controllers/settings/rooms_controller.rb b/app/controllers/settings/rooms_controller.rb index 35e4fcb5..6617720c 100755 --- a/app/controllers/settings/rooms_controller.rb +++ b/app/controllers/settings/rooms_controller.rb @@ -25,6 +25,7 @@ class Settings::RoomsController < ApplicationController # POST /settings/rooms # POST /settings/rooms.json def create + @settings_room = Room.new(settings_room_params) @settings_room.type = DiningFacility::ROOM_TYPE @settings_room.zone_id = params[:zone_id] @@ -35,7 +36,6 @@ class Settings::RoomsController < ApplicationController format.html { redirect_to settings_zone_path(@zone), notice: 'Room was successfully created.' } format.json { render :show, status: :created, location: @settings_room } else - puts "abc" format.html { render :new } format.json { render json: @settings_room.errors, status: :unprocessable_entity } end diff --git a/app/controllers/settings/shops_controller.rb b/app/controllers/settings/shops_controller.rb index ab492bdf..c15cf757 100644 --- a/app/controllers/settings/shops_controller.rb +++ b/app/controllers/settings/shops_controller.rb @@ -56,14 +56,15 @@ class Settings::ShopsController < ApplicationController audio_data = @settings_shop.display_images.find_by_name("order_audio").image delete_path = Rails.root.join("public/#{audio_data}") if File.exists?(delete_path) - File.delete(delete_path) - end - end - save_path = Rails.root.join("public/#{current_shop.shop_code}_#{a.original_filename}") + + File.delete(delete_path) + end + end + save_path = Rails.root.join("public/#{@shop.shop_code}_#{a.original_filename}") File.open(save_path, 'wb') do |f| f.write a.read end - audio_name = "#{current_shop.shop_code}_#{a.original_filename}" + audio_name = "#{@shop.shop_code}_#{a.original_filename}" @settings_shop.display_images.where(:name => "order_audio").destroy_all @display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :name => "order_audio", :image => audio_name) else diff --git a/app/controllers/settings/tables_controller.rb b/app/controllers/settings/tables_controller.rb index 91f35eed..ed4afe37 100755 --- a/app/controllers/settings/tables_controller.rb +++ b/app/controllers/settings/tables_controller.rb @@ -25,6 +25,7 @@ class Settings::TablesController < ApplicationController # POST /settings/tables # POST /settings/tables.json def create + @settings_table = Table.new(settings_table_params) @settings_table.type = DiningFacility::TABLE_TYPE @settings_table.zone_id = params[:zone_id] diff --git a/app/controllers/settings/tax_profiles_controller.rb b/app/controllers/settings/tax_profiles_controller.rb index 298d077d..51a8880f 100755 --- a/app/controllers/settings/tax_profiles_controller.rb +++ b/app/controllers/settings/tax_profiles_controller.rb @@ -45,6 +45,7 @@ class Settings::TaxProfilesController < ApplicationController # POST /settings/tax_profiles # POST /settings/tax_profiles.json def create + @settings_tax_profile = TaxProfile.new(settings_tax_profile_params) @settings_tax_profile.created_by = current_login_employee.name @settings_tax_profile.shop_code = @shop.shop_code diff --git a/app/controllers/settings/zones_controller.rb b/app/controllers/settings/zones_controller.rb index 22b5165d..57ecd577 100755 --- a/app/controllers/settings/zones_controller.rb +++ b/app/controllers/settings/zones_controller.rb @@ -5,6 +5,7 @@ class Settings::ZonesController < ApplicationController # GET /settings/zones # GET /settings/zones.json def index + @settings_zones = Zone.all.where("shop_code='#{@shop.shop_code}' and is_active= true") end @@ -27,6 +28,7 @@ class Settings::ZonesController < ApplicationController # POST /settings/zones # POST /settings/zones.json def create + @settings_zone = Zone.new(settings_zone_params) @settings_zone.shop_code =@shop.shop_code @settings_zone.created_by = current_login_employee.name diff --git a/app/controllers/transactions/bookings_controller.rb b/app/controllers/transactions/bookings_controller.rb index 8bb56249..0a6f7cbb 100644 --- a/app/controllers/transactions/bookings_controller.rb +++ b/app/controllers/transactions/bookings_controller.rb @@ -9,10 +9,10 @@ class Transactions::BookingsController < ApplicationController to = params[:to] if filter.nil? && from.nil? && to.nil? - @bookings = Booking.where("shop_code='#{@shop.shop_code}'").order("sale_id desc") + @bookings = Booking.order("sale_id desc") @bookings = Kaminari.paginate_array(@bookings).page(params[:page]).per(20) else - booking = Booking.search(filter,from,to).where("bookings.shop_code='#{@shop.shop_code}'") + booking = Booking.search(filter,from,to) if booking.count > 0 @bookings = booking @bookings = Kaminari.paginate_array(@bookings).page(params[:page]).per(20) diff --git a/app/controllers/transactions/credit_notes_controller.rb b/app/controllers/transactions/credit_notes_controller.rb index 4042091b..dac22d3e 100755 --- a/app/controllers/transactions/credit_notes_controller.rb +++ b/app/controllers/transactions/credit_notes_controller.rb @@ -6,6 +6,7 @@ class Transactions::CreditNotesController < ApplicationController # GET /transactions/sales # GET /transactions/sales.json def index + @sources = [["All",''], ["Cashier","cashier"],["Quick Service","quick_service"],["Online Order","doemal_order"]] @customers = Customer.all diff --git a/app/controllers/transactions/order_reservations_controller.rb b/app/controllers/transactions/order_reservations_controller.rb index c59688e8..3f035486 100644 --- a/app/controllers/transactions/order_reservations_controller.rb +++ b/app/controllers/transactions/order_reservations_controller.rb @@ -6,6 +6,7 @@ class Transactions::OrderReservationsController < ApplicationController # GET /transactions/order_reservations # GET /transactions/order_reservations.json def index + from, to = get_date_range_from_params filter = params[:filter] diff --git a/app/controllers/transactions/orders_controller.rb b/app/controllers/transactions/orders_controller.rb index 30a82ac4..59b5a106 100755 --- a/app/controllers/transactions/orders_controller.rb +++ b/app/controllers/transactions/orders_controller.rb @@ -3,7 +3,7 @@ class Transactions::OrdersController < ApplicationController before_action :check_user def index - + filter = params[:filter] from = params[:from] to = params[:to] diff --git a/app/controllers/transactions/sales_controller.rb b/app/controllers/transactions/sales_controller.rb index a76c87ce..13e617bb 100755 --- a/app/controllers/transactions/sales_controller.rb +++ b/app/controllers/transactions/sales_controller.rb @@ -18,13 +18,13 @@ class Transactions::SalesController < ApplicationController if receipt_no.nil? && from.nil? && to.nil? if @shift.blank? - @sales = Sale.where("NOT sale_status='new' and shop_code='#{@shop.shop_code}'").order("sale_id desc") + @sales = Sale.where("NOT sale_status='new'").order("sale_id desc") else - @sales = Sale.where("NOT sale_status='new' and shift_sale_id ='#{@shift.id}' and shop_code='#{@shop.shop_code}'").order("sale_id desc") + @sales = Sale.where("NOT sale_status='new' and shift_sale_id ='#{@shift.id}'").order("sale_id desc") end @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) else - sale = Sale.search(receipt_no,from,to,@shift).where("sales.shop_code='#{@shop.shop_code}'") + sale = Sale.search(receipt_no,from,to,@shift) if sale.count > 0 @sales = sale @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) @@ -90,7 +90,7 @@ class Transactions::SalesController < ApplicationController # GET /transactions/sales/1.json def show @membership = MembershipSetting.find_by_shop_code(@shop.shop_code) - @payment_methods = PaymentMethodSetting.where("shop_code='#{@shop.shop_code}' and is_active='1'") + @payment_methods = PaymentMethodSetting.where("is_active='1'") @sale = Sale.find(params[:id]) @order_items = [] @@ -346,7 +346,7 @@ class Transactions::SalesController < ApplicationController customer= Customer.find(sale.customer_id) #shop detail - shop_details = Shop.find_by_id(1) + shop_details = @shop # get member information rebate = MembershipSetting.find_by_rebate(1) if customer.membership_id != nil && rebate @@ -364,7 +364,7 @@ class Transactions::SalesController < ApplicationController other_amount = SaleItem.calculate_other_charges(sale.sale_items) #other charges printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil,other_amount,nil,nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil,other_amount,nil,nil,nil,nil) result = { :filepath => filename, :printer_model => print_settings.brand_name, diff --git a/app/controllers/transactions/shift_sales_controller.rb b/app/controllers/transactions/shift_sales_controller.rb index 7e9684bb..e6565324 100644 --- a/app/controllers/transactions/shift_sales_controller.rb +++ b/app/controllers/transactions/shift_sales_controller.rb @@ -4,6 +4,7 @@ class Transactions::ShiftSalesController < ApplicationController before_action :check_user def index + filter = params[:filter] from = params[:from] @@ -32,7 +33,7 @@ class Transactions::ShiftSalesController < ApplicationController # GET /transactions/shift_sales/1 # GET /transactions/shift_sales/1.json def show - + @shift = ShiftSale.find(params[:id]) #get tax diff --git a/app/controllers/transactions/surveys_controller.rb b/app/controllers/transactions/surveys_controller.rb index 6e75a9de..6f90c040 100644 --- a/app/controllers/transactions/surveys_controller.rb +++ b/app/controllers/transactions/surveys_controller.rb @@ -1,5 +1,6 @@ class Transactions::SurveysController < ApplicationController def index + filter = params[:filter] from = params[:from] to = params[:to] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 27024d75..16e44953 100755 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,6 @@ module ApplicationHelper + include NumberFormattable + def flash_class(level) case level when :notice then "alert alert-info fade-in" @@ -6,5 +8,6 @@ module ApplicationHelper when :error then "alert alert-error fade-in" when :alert then "alert alert-error fade-in" end - end + end + end diff --git a/app/models/ability.rb b/app/models/ability.rb index ddea0ae1..64f783bd 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -29,7 +29,7 @@ class Ability can :manage, Order can :manage, Booking can :manage, Sale - + can :manage, Customer can :manage, DiningQueue @@ -57,8 +57,8 @@ class Ability can :show, :product_sale can :get_customer, Customer - can :add_customer, Customer - can :update_sale_by_customer, Customer + can :add_customer, Customer + can :update_sale_by_customer, Customer can :index, :other_charge can :create, :other_charge @@ -73,11 +73,11 @@ class Ability can :create, :payment can :reprint, :payment can :rounding_adj, :payment - can :foc, :payment - can :print, :payment + can :foc, :payment + can :print, :payment can :change_tax, :payment - can :move_dining, :movetable + can :move_dining, :movetable can :moving, :movetable can :move_dining, :moveroom @@ -123,11 +123,11 @@ class Ability can :print, :print can :print_order_summary, :print - can :read, ShiftSale - can :update, ShiftSale + can :read, ShiftSale + can :update, ShiftSale + + elsif user.role == "cashier" || user.role =="foodcourt_cashier" - elsif user.role == "cashier" - # can :overall_void, :void can :index, :home can :show, :home @@ -136,10 +136,10 @@ class Ability can :update, Order can :manage, Booking can :manage, OrderQueueStation - can :read, Sale - can :update, Sale + can :read, Sale + can :update, Sale - can :manage, Customer + can :manage, Customer can :manage, OrderReservation @@ -160,11 +160,11 @@ class Ability can :create, :payment can :reprint, :payment can :rounding_adj, :payment - can :foc, :payment + can :foc, :payment can :print, :payment can :change_tax, :payment - can :move_dining, :movetable + can :move_dining, :movetable can :moving, :movetable can :move_dining, :moveroom @@ -204,7 +204,7 @@ class Ability can :item_edit, :sale_edit can :overall_void, :void - + elsif user.role == "account" can :index, :dailysale @@ -228,14 +228,14 @@ class Ability elsif user.role == "supervisor" can :manage, Employee - + can :edit, :sale_edit can :item_void, :sale_edit can :item_foc, :sale_edit can :item_edit, :sale_edit can :item_void_cancel, :sale_edit - can :cancel_all_void, :sale_edit - can :apply_void, :sale_edit + can :cancel_all_void, :sale_edit + can :apply_void, :sale_edit can :overall_void, :void can :index, :other_charge @@ -246,7 +246,7 @@ class Ability can :remove_all_discount, :discount can :member_discount, :discount - can :move_dining, :movetable + can :move_dining, :movetable can :moving, :movetable can :move_dining, :moveroom @@ -297,9 +297,9 @@ class Ability elsif user.role == "waiter" can :index, :home - can :show, :home + can :show, :home - can :manage, Customer + can :manage, Customer can :get_customer, Customer can :add_customer, Customer can :update_sale_by_customer, Customer @@ -313,7 +313,7 @@ class Ability can :member_discount, :discount #ability for move table - can :move_dining, :movetable + can :move_dining, :movetable can :moving, :movetable can :move_dining, :moveroom @@ -339,7 +339,7 @@ class Ability can :print_order_summary, :print elsif user.role == "kitchen" - + #oqs Home can :manage, OrderQueueStation can :index, :home diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 10a4cba8..590cdf8d 100755 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,14 @@ class ApplicationRecord < ActiveRecord::Base self.abstract_class = true + + def self.inherited(subclass) + super + + return unless subclass.superclass == self + return unless subclass.column_names.include? 'shop_id' + + subclass.class_eval do + acts_as_tenant(:shop) + end + end end diff --git a/app/models/dining_charge.rb b/app/models/dining_charge.rb index 6f931bcf..3151e88f 100755 --- a/app/models/dining_charge.rb +++ b/app/models/dining_charge.rb @@ -22,7 +22,7 @@ class DiningCharge < ApplicationRecord end return block_count, price else - puts "<<<<<<<< NO" + Rails.logger.info "Params not enough" end end diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index f947a0e8..999bcc0b 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -32,50 +32,27 @@ class DiningFacility < ApplicationRecord end def get_current_booking - checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code) - booking = Booking.where("shop_code='#{self.shop_code}' and dining_facility_id = #{self.id} and booking_status ='assign' and (CASE WHEN checkin_at > '#{DateTime.now.utc}' THEN checkin_at >= '#{DateTime.now.utc}' ELSE checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' END) and checkout_by is null").limit(1) #and checkout_at is null - if booking.count > 0 then - return booking[0] - else - return nil - end + + checkin_time_lookup = Lookup.get_checkin_time_limit + Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first #and checkout_at is null end def get_moved_booking - checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code) - booking = Booking.where("shop_code='#{self.shop_code}' and dining_facility_id = #{self.id} and booking_status ='moved' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1) + checkin_time_lookup = Lookup.get_checkin_time_limit + Booking.where(dining_facility_id: self.id, booking_status: 'moved', checkout_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first - if booking.count > 0 then - return booking[0] - else - return nil - end end def get_new_booking # query for new - # if status - # to ask when req bill booking_status? - booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id is null and checkout_at is null").limit(1) - # else - # booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id not null").limit(1) - # end - - if booking.count > 0 then - return booking[0].booking_id - else - return nil - end + Booking.where(dining_facility_id: self.id, booking_status: 'assign', sale_id: nil, checkout_at: nil).first end def get_current_checkout_booking - checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code) - booking = Booking.where("shop_code='#{self.shop_code}' and dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null").limit(1) - if booking.count > 0 then - return booking[0] - else - return nil - end + + checkin_time_lookup = Lookup.get_checkin_time_limit + Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).where.not(reserved_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first + end def get_checkout_booking @@ -117,8 +94,10 @@ class DiningFacility < ApplicationRecord end def self.get_checkin_booking - checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code) - bookings = Booking.where("shop_code='#{self.shop_code}' and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null") + + checkin_time_lookup = Lookup.get_checkin_time_limit + bookings = Booking.where(booking_status: 'assign', checkout_at: nil).where.not(reserved_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago) + arr_booking = Array.new if bookings lookup_checkout_time = Lookup.where("shop_code='#{self.shop_code}'").collection_of("checkout_alert_time") diff --git a/app/models/employee.rb b/app/models/employee.rb index 67aad0f6..f27adf29 100755 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -3,6 +3,7 @@ class Employee < ApplicationRecord has_many :commissioners has_many :shit_sales belongs_to :order_queue_station + validates_presence_of :name, :role validates_presence_of :password, :on => [:create] validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true @@ -19,9 +20,9 @@ class Employee < ApplicationRecord Employee.select("id, name").map { |e| [e.name, e.id] } end - def self.login(shop,emp_id, password) - user = Employee.find_by_emp_id_and_shop_code(emp_id,shop.shop_code) - expiry_time = login_expiry_time(shop) + def self.login(emp_id, password) + user = Employee.find_by_emp_id(emp_id) + expiry_time = login_expiry_time if (user) #user.authenticate(password) if (user.authenticate(password)) @@ -36,10 +37,10 @@ class Employee < ApplicationRecord end - def self.authenticate_by_token(session_token,shop) + def self.authenticate_by_token(session_token) if (session_token) - user = Employee.find_by_token_session_and_shop_code(session_token,shop.shop_code) - expiry_time = login_expiry_time(shop) + user = Employee.find_by_token_session(session_token) + expiry_time = login_expiry_time if user && user.session_expiry.utc > DateTime.now.utc #Extend the login time each time authenticatation take place @@ -54,9 +55,9 @@ class Employee < ApplicationRecord return false end - def self.logout(shop,session_token) + def self.logout(session_token) if (session_token) - user = Employee.find_by_token_session_and_shop_code(session_token,shop.shop_code) + user = Employee.find_by_token_session(session_token) if user user.token_session = nil @@ -72,9 +73,9 @@ class Employee < ApplicationRecord retry end - def self.login_expiry_time(shop) + def self.login_expiry_time expiry_time = 30 - login_expiry = Lookup.where("shop_code='#{shop.shop_code}'").collection_of('expiry_time') + login_expiry = Lookup.collection_of('expiry_time') if !login_expiry.empty? login_expiry.each do |exp_time| if exp_time[0].downcase == "login" diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb index b7ef3e44..fb00113a 100755 --- a/app/models/inventory_definition.rb +++ b/app/models/inventory_definition.rb @@ -23,34 +23,23 @@ class InventoryDefinition < ApplicationRecord end end - def self.find_product_in_inventory(item,shop_code=nil) - # unless instance_code.empty? - # instance_code = instance_code.to_s - # instance_code[0] = "" - # instance_code = instance_code.chomp("]") - # else - # instance_code = '"0"' - # end - # - # if prod = InventoryDefinition.where("item_code IN(#{instance_code})") - # puts "found prodcut+++++++++++++++++++++++++++++++++++===" - # puts prod.to_json - # end - if product = InventoryDefinition.find_by_item_code_and_shop_code(item.item_instance_code,shop_code) - if stock_check_item = StockCheckItem.find_by_item_code_and_shop_code(item.item_instance_code,shop_code) + + def self.find_product_in_inventory(item) + if product = InventoryDefinition.find_by_item_code_and_shop_code(item.item_instance_code,Shop.current_shop.shop_code) + if stock_check_item = StockCheckItem.find_by_item_code_and_shop_code(item.item_instance_code,Shop.current_shop.shop_code) return true, product end end end def self.check_balance(item, inventory_definition) # item => saleItemOBj - stock = StockJournal.where("shop_code='#{inventory_definition.shop_code}' and item_code=?", item.item_instance_code).order("id DESC").first - unless stock.nil? - modify_balance(item, stock, inventory_definition) - else - puts "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< OUT OF STOCK >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" - StockJournal.add_to_journal(item.item_instance_code, item.qty, 0, "out of stock", inventory_definition, item.id, StockJournal::SALES_TRANS) - end + + stock = StockJournal.where("shop_code='#{inventory_definition.shop_code}' and item_code=?", item.item_instance_code).order("id DESC").first + unless stock.nil? + modify_balance(item, stock, inventory_definition) + else + StockJournal.add_to_journal(item.item_instance_code, item.qty, 0, "out of stock", inventory_definition, item.id, StockJournal::SALES_TRANS) + end end def self.modify_balance(item, stock, inventory_definition) #saleitemObj @@ -75,6 +64,7 @@ class InventoryDefinition < ApplicationRecord elsif item.is_a? SaleItem trans_type = StockJournal::SALES_TRANS end + # StockJournal.add_to_journal(instance_code, qty, stock.balance, remark, inventory_definition, item.id, trans_type) StockJournal.add_to_journal(item.item_instance_code, qty, stock.balance, remark, inventory_definition, item.id, trans_type) check_item.different = check_item.different - qty check_item.save diff --git a/app/models/kbz_pay.rb b/app/models/kbz_pay.rb index 5893e048..523a7fc5 100644 --- a/app/models/kbz_pay.rb +++ b/app/models/kbz_pay.rb @@ -3,13 +3,13 @@ class KbzPay KBZ_PAY = 'KBZPay' def self.pay(amount, receipt_no, url, key, app_id, code) - shop = Shop.first + shop = Shop.current_shop prefix = shop.shop_code receipt_no = "#{prefix}#{receipt_no}" datetime = DateTime.now.strftime("%d%m%Y%H%M") kbz_app_id = app_id - kbz_merch_code = code + kbz_merch_code = code kbz_api_key = key kbz_provider_url = "#{url}/precreate" @@ -58,17 +58,17 @@ class KbzPay # Rails.logger.debug result['Response'] return false, result['Response'] end - + end def self.query(receipt_no, current_user, url, key, app_id, code) - shop = Shop.first + shop = Shop.current_shop prefix = shop.shop_code receipt_no = "#{prefix}#{receipt_no}" amount = 0 datetime = DateTime.now.strftime("%d%m%Y%H%M") kbz_app_id = app_id - kbz_merch_code = code + kbz_merch_code = code kbz_api_key = key kbz_provider_url = "#{url}/queryorder" @@ -122,7 +122,7 @@ class KbzPay # return true, "successfully paid by KBZ PAY" elsif result['Response']['trade_status'] == "PAY_FAILED" - + # return false, "pay failed by KBZ PAY" elsif result['Response']['trade_status'] == "WAIT_PAY" # return false , "Waiting to pay by KBZ PAY" @@ -135,4 +135,4 @@ class KbzPay return amount end -end \ No newline at end of file +end diff --git a/app/models/license.rb b/app/models/license.rb index 9ef7d956..2c550a1e 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -18,22 +18,22 @@ class License if (server != "") self.class.base_uri server end - end + end # For Cloud - def detail_with_local_cache(lookup) + def detail_with_local_cache(lookup) aes = MyAesCrypt.new - aes_key, aes_iv = aes.export_to_file(lookup) - + aes_key, aes_iv = aes.export_to_file(lookup) + ##Check from local redis - if available load local otherwise get from remote - cache_key = "#{lookup}:license:#{aes_key}:hostname" + cache_key = "#{lookup}:license:#{aes_key}:hostname" cache_license = nil ##Get redis connection from connection pool redis = Redis.new - cache_license = redis.get(cache_key) - + cache_license = redis.get(cache_key) + Rails.logger.info "Cache key - " + cache_key.to_s if cache_license.nil? ##change the d/e key @@ -41,12 +41,13 @@ class License @params = { query: { lookup_type: self.server_mode, lookup: lookup, iv_key: aes_iv} } response = self.class.get("/subdomain", @params) @license = response.parsed_response + Rails.logger.info "License Response - " + response.parsed_response.to_s if (@license["status"] == true) assign(aes_key, aes_iv) - # Rails.logger.info "License - " + response.parsed_response.to_s - + #Rails.logger.info "License - " + response.parsed_response.to_s + redis = Redis.new redis.set(cache_key, Marshal.dump(@license)) # redis.sadd("License:cache:keys", cache_key) @@ -59,36 +60,36 @@ class License return true end - else + else @license = Marshal.load(cache_license) assign(aes_key, aes_iv) - # Rails.logger.info 'API License' + # Rails.logger.info 'API License' return true end end # For Local System - def detail_with_local_file() + def detail_with_local_file() renewal_date_str = read_license("renewable_date") - if check_expiring(renewal_date_str) - # return for all ok + if check_expiring(renewal_date_str) + # return for all ok return 1 else has_license = verify_license() if has_license - # return for expiring + # return for expiring return 2 else return 0 end end - # end - end + # end + end # License Activation def license_activate (shop, license_key, db_host, db_schema, db_user, db_password) - aes = MyAesCrypt.new - aes_key, aes_iv = aes.export_key(license_key) + aes = MyAesCrypt.new + aes_key, aes_iv = aes.export_key(license_key) @params = { query: { lookup_type: self.server_mode, iv_key: aes_iv, license_key: license_key } } response = self.class.get("/activate", @params) @@ -96,21 +97,21 @@ class License if (@activate["status"]) ##Check from local redis - if available load local otherwise get from remote - cache_key = "shop:#{@activate["shop_name"]}" + cache_key = "shop:#{@activate["shop_name"]}" - cache_license = nil + cache_license = nil ##Get redis connection from connection pool redis = Redis.new - cache_license = redis.get(cache_key) + cache_license = redis.get(cache_key) Rails.logger.info "Cache key - " + cache_key.to_s - if cache_license.nil? - cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] } + if cache_license.nil? + cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] } redis = Redis.new redis.set(cache_key, Marshal.dump(cache)) - end + end Rails.logger.info "License - " + response.parsed_response.to_s @@ -120,21 +121,21 @@ class License sym_path = File.expand_path("~/symmetric/") response = create_symmetric_config(sym_path, db_host, db_schema, db_user, db_password) - + if(response[:status]) response = run_symmetric(sym_path) end end else response = { "status": false, "message": "Activation Failed! Please contact code2lab call center!"} - end + end return response end - def verify_license - api_token = read_license_no_decrypt("api_token") + def verify_license + api_token = read_license_no_decrypt("api_token") @params = { query: {lookup_type: "application", api_token: api_token} } - + begin response = self.class.get("/verify", @params) @varified = response.parsed_response @@ -145,7 +146,7 @@ class License end else delete_license_file - end + end rescue SocketError => e Rails.logger.debug "In SocketError No Internet connection ! " @@ -159,21 +160,21 @@ class License rescue OpenURI::HTTPError Rails.logger.debug "Can't connect server" return true - end - return false + end + return false end # Check Expired before 30 days - def check_expiring(renewal_date_str) + def check_expiring(renewal_date_str) if !renewal_date_str.empty? - renewal_date = DateTime.parse(renewal_date_str) + renewal_date = DateTime.parse(renewal_date_str) renewal_date > Date.today.advance(:days => 30) end end # Check License expired date from PROVISION SERVER - def check_expired(renewal_date_str) + def check_expired(renewal_date_str) expired_date_str = read_license("renewable_date") renewal_date = DateTime.parse(renewal_date_str) if(renewal_date_str != expired_date_str) @@ -186,32 +187,32 @@ class License return false end end - + # Check License File exists def self.check_license_file - return File.exist?("config/license.yml") + return File.exist?("config/license.yml") end # read line by key for license file - def read_license(key_name) - decrypted_line = "" + def read_license(key_name) + decrypted_line = "" key, iv = get_redis_key() - if File.exist?("config/license.yml") + if File.exist?("config/license.yml") File.open("config/license.yml").each do |line| - if line.include? (key_name) - decrypted_line_array = line.split(": ") + if line.include? (key_name) + decrypted_line_array = line.split(": ") decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(key), decode_str(iv), ENV['CIPHER_TYPE']) end end - end + end return decrypted_line end # read line by key for license file without decrypt def read_license_no_decrypt(key) decrypted_line = "" - if File.exist?("config/license.yml") + if File.exist?("config/license.yml") File.open("config/license.yml").each do |line| if line.include? (key) decrypted_line_array = line.split(": ") @@ -226,18 +227,18 @@ class License def update_license(content, new_content) key, iv = get_redis_key() - if !new_content.include? "==" + if !new_content.include? "==" crypted_str = AESCrypt.encrypt_data(new_content, decode_str(key), decode_str(iv), ENV['CIPHER_TYPE']) end - + content_str = read_license_no_decrypt(content) - if File.exist?("config/license.yml") + if File.exist?("config/license.yml") file_str = File.read("config/license.yml") new_file_str = file_str.gsub(content_str, encode_str(crypted_str)) # To write changes to the file, use: File.open("config/license.yml", "w") {|file| file.puts new_file_str } - + # File.open("config/license.yml").each do |line| # new_file_str = line.gsub(content, crypted_str) # f.put @@ -247,33 +248,33 @@ class License # Re-get keys def get_key - api_token = read_license_no_decrypt("api_token") - shop_name = read_license_no_decrypt("shop_name") + api_token = read_license_no_decrypt("api_token") + shop_name = read_license_no_decrypt("shop_name") @params = { query: {lookup_type: "application", api_token: api_token } } response = self.class.get("/get_key", @params) @data = response.parsed_response - + if (@data["status"]) ##Check from local redis - if available load local otherwise get from remote - cache_key = "shop:#{shop_name.chomp}" + cache_key = "shop:#{shop_name.chomp}" - cache_license = nil + cache_license = nil ##Get redis connection from connection pool redis = Redis.new - cache_license = redis.get(cache_key) + cache_license = redis.get(cache_key) Rails.logger.info "Cache key - " + cache_key.to_s - if cache_license.nil? - cache = {"shop" => shop_name, "key" => @data["secret_key"], "iv" => @data["iv_key"], "renewable_date" => @data["renewable_date"] } + if cache_license.nil? + cache = {"shop" => shop_name, "key" => @data["secret_key"], "iv" => @data["iv_key"], "renewable_date" => @data["renewable_date"] } redis = Redis.new redis.set(cache_key, Marshal.dump(cache)) - end + end return true - end + end return false - end + end private def get_redis_key @@ -281,18 +282,18 @@ class License key = "" shop = read_license_no_decrypt("shop_name") ##Check from local redis - if available load local otherwise get from remote - cache_key = "shop:#{shop.chomp}" + cache_key = "shop:#{shop.chomp}" - cache_shop = nil + cache_shop = nil ##Get redis connection from connection pool redis = Redis.new - cache_shop = redis.get(cache_key) + cache_shop = redis.get(cache_key) - if !cache_shop.nil? - @shop = Marshal.load(cache_shop) - key = @shop["key"] - iv = @shop["iv"] + if !cache_shop.nil? + @shop = Marshal.load(cache_shop) + key = @shop["key"] + iv = @shop["iv"] end return key, iv end @@ -307,13 +308,13 @@ class License # License File Creation def create_license_file(response_data) - if File.exist?("config/license.yml") + if File.exist?("config/license.yml") delete_license_file end begin # Licese File Creation - File.open("config/license.yml", "w") do |f| + File.open("config/license.yml", "w") do |f| f.puts("iv_key: #{response_data['iv_key']}") f.puts("shop_name: #{response_data['shop_name']}") f.puts("email: #{response_data['email']}") @@ -325,11 +326,11 @@ class License f.puts("dbusername: #{response_data['dbusername']}") f.puts("dbpassword: #{response_data['dbpassword']}") f.puts("api_token: #{response_data['api_token']}") - f.puts("app_token: #{response_data['app_token']}") + f.puts("app_token: #{response_data['app_token']}") f.puts("plan_sku: #{response_data['plan_sku']}") f.puts("renewable_date: #{response_data['renewable_date']}") f.puts("plan_name: #{response_data['plan_name']}") - end + end rescue IOError response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} end @@ -352,15 +353,15 @@ class License f.write("group.id=sx\n") f.write("external.id=000\n") f.write("job.purge.period.time.ms=7200000\n") - f.write("job.routing.period.time.ms=5000\n") - f.write("job.push.period.time.ms=10000\n") - f.write("job.pull.period.time.ms=10000\n") - f.write("initial.load.create.first=true\n") + f.write("job.routing.period.time.ms=5000\n") + f.write("job.push.period.time.ms=10000\n") + f.write("job.pull.period.time.ms=10000\n") + f.write("initial.load.create.first=true\n") f.write("initial.load.use.extract.job.enabled=true\n") f.write("rest.api.enable=true\n") - f.close + f.close - # read from license file + # read from license file # shop_name = read_license_no_decrypt("shop_name") shop_name = "cloud" dbhost = read_license("dbhost") @@ -378,12 +379,12 @@ class License f.write("registration.url=http://#{db_host}:31415/sync/sx\n") f.write("group.id=cloud\n") f.write("external.id=001\n") - f.write("job.routing.period.time.ms=5000\n") - f.write("job.push.period.time.ms=10000\n") + f.write("job.routing.period.time.ms=5000\n") + f.write("job.push.period.time.ms=10000\n") f.write("job.pull.period.time.ms=10000\n") f.write("rest.api.enable=true\n") - # f.write("initial.load.create.first=true\n") - # f.write("initial.load.use.extract.job.enabled=true\n") + # f.write("initial.load.create.first=true\n") + # f.write("initial.load.use.extract.job.enabled=true\n") f.close rescue IOError response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} @@ -392,12 +393,12 @@ class License end end - # Run Symmetric + # Run Symmetric def run_symmetric(sym_path) # check_sym_proc_str = `#{sym_path + "bin/sym_service status"}` # check_sym_proc_str = check_sym_proc_str.split("\n") # sym_install_status = check_sym_proc_str[0].split(": ") - + check_sym_proc_str = `#{"sudo service SymmetricDS status"}` # Check Sym Installed @@ -412,7 +413,7 @@ class License check_sym_table = system("sudo " + sym_path + "/bin/symadmin --engine sx create-sym-tables") if check_sym_table sym_sql = Rails.root + "db/sym_master.sql" - + if File.exist? (sym_sql) # Import Sym Sql to db and start sym run_sym_sql = system("sudo " + sym_path + "/bin/dbimport --engine sx " + sym_sql.to_s) @@ -427,7 +428,7 @@ class License else response = { "status": false, "message": "Activation is success but Cannot create Sym Tables. \n Please contact code2lab call center!"} end - else + else response = { "status": false, "message": "Activation is success but Symmetric not running. \n Please contact code2lab call center!"} end end @@ -435,7 +436,7 @@ class License # Check Symmetric Running def check_sym_running(status, sym_path) # Run Sym Service - # if status.include? "Server is already running" + # if status.include? "Server is already running" # return true # elsif status.include? "false" # sym_start_str = `#{sym_path + "bin/sym_service start"}` @@ -443,9 +444,9 @@ class License # return true # else # check_sym_running(sym_start_status[0]) - # end + # end # else - # return true + # return true # end if status.include? "Active: active (running)" || "Active: active (exited)" #"Server is already running" @@ -456,15 +457,15 @@ class License # Delete License File def delete_license_file - File.delete("config/license.yml") if File.exist?("config/license.yml") + File.delete("config/license.yml") if File.exist?("config/license.yml") end # Assign db info for Cloud - def assign(aes_key, aes_iv) + def assign(aes_key, aes_iv) key = Base64.decode64(aes_key) iv = Base64.decode64(aes_iv) - - if (@license["dbhost"] || @license["dbschema"] || @license["dbusername"] || @license["dbpassword"] ) + + if (@license["dbhost"] || @license["dbschema"] || @license["dbusername"] || @license["dbpassword"] ) host = Base64.decode64(@license["dbhost"]) dbschema = Base64.decode64(@license["dbschema"]) dbusername = Base64.decode64(@license["dbusername"]) @@ -473,8 +474,8 @@ class License self.dbhost = AESCrypt.decrypt_data(host, key, iv, ENV['CIPHER_TYPE']) self.dbschema = AESCrypt.decrypt_data(dbschema, key, iv, ENV['CIPHER_TYPE']) self.dbusername = AESCrypt.decrypt_data(dbusername, key, iv, ENV['CIPHER_TYPE']) - self.dbpassword = AESCrypt.decrypt_data(dbpassword, key, iv, ENV['CIPHER_TYPE']) + self.dbpassword = AESCrypt.decrypt_data(dbpassword, key, iv, ENV['CIPHER_TYPE']) end - + end end diff --git a/app/models/lookup.rb b/app/models/lookup.rb index 5aaf3329..bc7f1518 100755 --- a/app/models/lookup.rb +++ b/app/models/lookup.rb @@ -3,6 +3,10 @@ class Lookup < ApplicationRecord has_many :accounts belongs_to :shop + scope :number_formats, -> { where(lookup_type: 'number_format')} + + TIME_LIMIT = 5 + def available_types {'Employee Roles' => 'employee_roles', 'Dining Facilities Status' => 'dining_facilities_status', @@ -22,15 +26,15 @@ class Lookup < ApplicationRecord # Lookup.select("value, name").where("lookup_type = ?", lookup_type ).order("name asc").map { |r| [r.name, r.value] } # end - def self.get_checkin_time_limit(shop_code) - time_limit = 5 - lookup = Lookup.find_by_lookup_type_and_shop_code('checkin_time_limit',shop_code) - if !lookup.nil? - time_limit = lookup.value.to_i - end + def self.time_limit + TIME_LIMIT + end - return time_limit + + def self.get_checkin_time_limit + return RequestStore[:checkin_time_limit] if RequestStore[:checkin_time_limit] + RequestStore[:checkin_time_limit] = Lookup.find_by_lookup_type('checkin_time_limit').value.to_i rescue time_limit end def self.sync_url @@ -57,7 +61,6 @@ class Lookup < ApplicationRecord def self.collection_of(type) Lookup.select("name, value").where("lookup_type" => type ).map { |l| [l.name, l.value] } - end def self.create_shift_sale_lookup(shop_code) diff --git a/app/models/menu.rb b/app/models/menu.rb index de60ef66..a1b6d735 100755 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -141,7 +141,14 @@ class Menu < ApplicationRecord end else # Menu by Menu Import - shop_code= shop.shop_code + "_" + + @shop = Shop.current_shop + shop_code = "" + if !@shop.nil? + if @shop.shop_code + shop_code = @shop.shop_code + "_" + end + end sheet = spreadsheet.sheet(0) menu = sheet.row(1)[1] diff --git a/app/models/order.rb b/app/models/order.rb index b42ef694..6bf30813 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -591,5 +591,19 @@ class Order < ApplicationRecord Rails.logger.debug '...... order sync completed .....' end end + def self.send_message(phone, order_id,shop_name) + url = "http://smspoh.com/api/http/send?key=5QfyN0OtGsFXnOqwtpVAGZCyPGP28nbX_Nm_oPsUw2ybq714T_951ycz3Ypl5URA&message=Your order "+order_id.to_s+" is ready to pick up ,thanks from "+shop_name.to_s+"&recipients="+ phone.to_s + begin + @result = HTTParty.get(url.to_str) + 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 + end end diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 3461c5ea..21608ecc 100755 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -125,42 +125,14 @@ class OrderItem < ApplicationRecord end def update_stock_journal - if self.set_menu_items.present? - puts "set menu itemsssssssss???????????????????????????????" - puts items = JSON.parse(self.set_menu_items) - instance_code = Array.new - count = 0 - items.each { |i| - instance_code.push(i["item_instance_code"]) - } - print instance_code - end - if self.qty != self.qty_before_last_save - found, inventory_definition = InventoryDefinition.find_product_in_inventory(self,self.order.shop_code) - if found - InventoryDefinition.check_balance(self, inventory_definition) + + unless MenuItemInstance.where("item_instance_name <> ''").pluck(:item_instance_code).include?(self.item_instance_code) + if self.qty != self.qty_before_last_save + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + if found + InventoryDefinition.check_balance(self, inventory_definition) + end end end - # if self.qty > self.qty_was - # credit = 0 - # debit = self.qty.to_i - self.qty_was.to_i - # else - # credit = self.qty_was.to_i - self.qty.to_i - # debit = 0 - # end - # if credit != debit - # defination = InventoryDefinition.find_by_item_code(self.item_instance_code) - # stock = StockJournal.where('item_code = ?', self.item_instance_code).order("id DESC").first - # journal = StockJournal.create( - # item_code: self.item_instance_code, - # credit: credit, - # debit: debit, - # balance: stock.balance - debit + credit, - # inventory_definition_id: defination.id, - # remark: 'ok', - # trans_ref: self.order.id, - # trans_type: StockJournal::SALES_TRANS - # ) - # end end end diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index f7d8ab36..ff67c34b 100755 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -297,8 +297,9 @@ class OrderQueueStation < ApplicationRecord @type = (DiningFacility.find(change_to)).type @moved_by = current_user @date = DateTime.now - @shop = Shop.find_by_shop_code(oqs.shop_code) - unique_code = "MoveTablePdf" + + @shop = Shop.current_shop + unique_code = "MoveTablePdf" # pdf_no = PrintSetting.where(:unique_code => unique_code).count print_settings = PrintSetting.find_by_unique_code(unique_code) # printer_array = [] diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index 457566db..60c2a347 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -157,7 +157,8 @@ class OrderReservation < ApplicationRecord def self.update_doemal_payment(order,current_user,receipt_bill) if(Sale.exists?(order.sale_id)) saleObj = Sale.find(order.sale_id) - shop_details = Shop.find_by_shop_code(order.shop_code) + + shop_details = Shop.current_shop # rounding adjustment if shop_details.is_rounding_adj a = saleObj.grand_total % 25 # Modulus @@ -194,7 +195,8 @@ class OrderReservation < ApplicationRecord shift = ShiftSale.find(saleObj.shift_sale_id) cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) - # shop_detail = Shop.first + + shop_detail = Shop.current_shop order_reservation = OrderReservation.get_order_reservation_info(saleObj.sale_id) if !cashier_terminal.nil? # Calculate Food and Beverage Total @@ -203,7 +205,7 @@ class OrderReservation < ApplicationRecord other_amount = SaleItem.calculate_other_charges(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,saleObj.sale_items,saleObj,saleObj.customer.name, item_price_by_accounts, discount_price_by_accounts, nil,nil,shop_details, "Paid",nil,nil,other_amount,nil,nil, order_reservation) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,saleObj.sale_items,saleObj,saleObj.customer.name, item_price_by_accounts, discount_price_by_accounts, nil,nil,shop_details, "Paid",nil,nil,other_amount,nil,nil, order_reservation,nil) #receipt bill pdf setting result = {:status=> true, @@ -400,7 +402,7 @@ class OrderReservation < ApplicationRecord end def self.check_new_order - shop = Shop.find_by_id(1) + shop = Shop.current_shop if !shop.shop_code.nil? shop_code = shop.shop_code else @@ -418,7 +420,7 @@ class OrderReservation < ApplicationRecord end def self.check_order_send_to_kitchen - shop = Shop.find_by_id(1) + shop = Shop.current_shop if !shop.shop_code.nil? shop_code = shop.shop_code else @@ -436,7 +438,7 @@ class OrderReservation < ApplicationRecord end def self.check_order_ready_to_delivery - shop = Shop.find_by_id(1) + shop = Shop.current_shop if !shop.shop_code.nil? shop_code = shop.shop_code else diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index cadba8ce..007d4766 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -38,7 +38,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker end # end - # shop = Shop.first + + # shop = Shop.current_shop directory_name = 'public/orders_'+oqs.shop_code Dir.mkdir(directory_name) unless File.exists?(directory_name) @@ -80,8 +81,10 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker print_setting = PrintSetting.all.order("id ASC") order=print_query('order_summary', order_id) - # shop = Shop.first - directory_name = 'public/orders_'+oqs.shop_code + + # shop = Shop.current_shop + directory_name = 'public/orders_'+ oqs.shop_code + Dir.mkdir(directory_name) unless File.exists?(directory_name) # For Print Per Item @@ -192,7 +195,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker order=print_query('booking_summary', booking_id) - # shop = Shop.first + + # shop = Shop.current_shop directory_name = 'public/orders_'+oqs.shop_code Dir.mkdir(directory_name) unless File.exists?(directory_name) @@ -294,7 +298,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker # Query for OQS with status def print_query(type, id) if type == "order_item" - OrderItem.select("order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name") + OrderItem.select("orders.source,cus.contact_no,rder_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name") .joins("left join orders ON orders.order_id = order_items.order_id left join booking_orders AS bo ON bo.order_id=order_items.order_id left join bookings AS b ON b.booking_id = bo.booking_id @@ -304,7 +308,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker .where("order_items.order_items_id = '#{ id }'") .group("order_items.item_code") elsif type == "order_summary" - OrderItem.select("order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name") + OrderItem.select("orders.source,cus.contact_no,order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name") .joins("left join orders ON orders.order_id = order_items.order_id left join booking_orders AS bo ON bo.order_id=order_items.order_id left join bookings AS b ON b.booking_id = bo.booking_id @@ -315,7 +319,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker .group("order_items.order_items_id") else # order summary for booking - OrderItem.select("order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name") + OrderItem.select("orders.source,cus.contact_no,order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name") .joins("left join orders ON orders.order_id = order_items.order_id left join booking_orders AS bo ON bo.order_id=order_items.order_id left join bookings AS b ON b.booking_id = bo.booking_id diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index a935c3b0..9b51e4f3 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -188,20 +188,20 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end #Bill Receipt Print - def print_receipt_bill(printer_settings, kbz_pay_status, qr_code, cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,order_reservation) + def print_receipt_bill(printer_settings, kbz_pay_status, qr_code, cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,order_reservation,transaction_ref) #Use CUPS service #Generate PDF #Print if !printer_settings.nil? if !printer_settings.unique_code.strip.downcase.include? ("receiptbillorder") - pdf = ReceiptBillPdf.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) + pdf = ReceiptBillPdf.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,transaction_ref) settings = PrintSetting.where("shop_code='#{shop_details.shop_code}'") if !settings.nil? settings.each do |setting| if setting.unique_code == 'ReceiptBillPdf' - pdf = ReceiptBillPdf.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) + pdf = ReceiptBillPdf.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,transaction_ref) elsif setting.unique_code == 'ReceiptBillStarPdf' - pdf = ReceiptBillStarPdf.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) + pdf = ReceiptBillStarPdf.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,transaction_ref) end end end @@ -211,7 +211,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker receipt_bill_a5_pdf.each do |receipt_bilA5| if receipt_bilA5[0] == 'ReceiptBillA5Pdf' if receipt_bilA5[1] == '1' - pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) + pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,transaction_ref) # else # pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) end diff --git a/app/models/promotion.rb b/app/models/promotion.rb index 3e657e63..9359510a 100755 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -15,11 +15,11 @@ class Promotion < ApplicationRecord promo_day.include? Date.today.wday.to_s end - def self.promo_activate(saleObj,shop_code) + def self.promo_activate(saleObj) current_day = Time.now.strftime("%Y-%m-%d") current_time = Time.now.strftime('%H:%M:%S') day = Date.today.wday - promoList = is_between_promo_datetime(current_day,current_time,shop_code) + promoList = is_between_promo_datetime(current_day,current_time) promoList.each do |promo| if promo.is_promo_day @@ -30,8 +30,8 @@ class Promotion < ApplicationRecord end end - def self.is_between_promo_datetime(current_day,current_time,shop_code) #database is not local time - promoList = Promotion.where("shop_code='#{shop_code}' and (Date_Format(promo_start_date, '%Y-%m-%d') <=? AND Date_Format(promo_end_date, '%Y-%m-%d') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time) + def self.is_between_promo_datetime(current_day,current_time) #database is not local time + promoList = Promotion.where("(Date_Format(promo_start_date, '%Y-%m-%d') <=? AND Date_Format(promo_end_date, '%Y-%m-%d') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time) return promoList end diff --git a/app/models/room.rb b/app/models/room.rb index 87f232e9..63c548ec 100755 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -1,4 +1,3 @@ class Room < DiningFacility - has_many :bookings, :foreign_key => 'dining_facility_id' end diff --git a/app/models/sale.rb b/app/models/sale.rb index 9e0ab2de..90ed9f73 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1,4 +1,5 @@ class Sale < ApplicationRecord + include NumberFormattable self.primary_key = "sale_id" #primary key - need to be unique generated for multiple shops @@ -7,12 +8,15 @@ class Sale < ApplicationRecord belongs_to :cashier, foreign_key: "cashier_id", class_name: "Employee" belongs_to :customer, :optional => true belongs_to :shift_sale + has_one :survey, foreign_key: "receipt_no" + has_many :sale_audits has_many :sale_items has_many :sale_discount_items has_many :sale_discounts has_many :sale_taxes has_many :sale_payments has_many :sale_orders + has_many :sale_payments_for_credits, through: :sale_audits has_many :orders, through: :sale_orders has_many :order_items, through: :sale_orders has_many :bookings @@ -25,10 +29,11 @@ class Sale < ApplicationRecord scope :complete_sale, -> { where("sale_status = 'completed' and receipt_date BETWEEN '#{DateTime.now.utc.beginning_of_day}' AND '#{DateTime.now.utc.end_of_day}'") } scope :paid, -> { where(payment_status: 'paid')} scope :completed, -> { where(sale_status: 'completed') } - scope :date_on, -> (date) { where("DATE(CONVERT_TZ(receipt_date, '+00:00', ?)) = ?", Time.zone.formatted_offset, date) } - scope :date_between, -> (from, to) { where("DATE(CONVERT_TZ(receipt_date, '+00:00', ?)) BETWEEN ? AND ?", Time.zone.formatted_offset, from, to) } - scope :time_between, -> (from, to) { where("TIME(CONVERT_TZ(receipt_date, '+00:00', ?)) BETWEEN ? AND ?", Time.zone.formatted_offset, from, to) } - scope :along_with_sale_payments_except_void, -> { joins("LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND DATE(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30')) = DATE(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'))") } + + scope :receipt_date_between, -> (from, to) { where(receipt_date: from..to) } + scope :along_with_sale_payments_except_void_between, -> (from, to) { joins(sanitize_sql_array(["LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND sale_payments.created_at BETWEEN ? and ?", from, to])) } + + def qty_of(item_instance_code) order_items.select(:order_items_id, :item_instance_code, 'SUM(qty) as qty').where(item_instance_code: item_instance_code).group(:item_instance_code).first end @@ -135,8 +140,8 @@ class Sale < ApplicationRecord order = Order.find(order_id) # current cashier login - open_cashier = Employee.where("shop_code='#{order.shop_code}' and role = 'cashier' AND token_session <> ''") - current_shift = ShiftSale.current_shift(order.shop_code) + open_cashier = Employee.where("role = 'cashier' AND token_session <> ''") + current_shift = ShiftSale.current_shift # shift with terminal zone # set cashier @@ -144,12 +149,12 @@ class Sale < ApplicationRecord if !booking.dining_facility_id.nil? table = DiningFacility.find(booking.dining_facility_id) cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) - shift = ShiftSale.where("shop_code='#{order.shop_code}' and shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first + shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first #for multiple zone with terminal if shift.nil? multiple_zone = CashierTerminalByZone.where("zone_id = #{table.zone_id}") multiple_zone.each do |zone| - shift = ShiftSale.where("shop_code='#{order.shop_code}' and shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first + shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first if !shift.nil? then break end @@ -187,7 +192,7 @@ class Sale < ApplicationRecord self.requested_by = requested_by.name self.requested_at = DateTime.now.utc.getlocal - self.shop_code = order.shop_code + self.shop_code = Shop.current_shop.shop_code Rails.logger.debug "Order -> #{order.id} | order_status -> #{order.status}" if order self.customer_id = order.customer_id @@ -233,7 +238,7 @@ class Sale < ApplicationRecord #fOR Quick Service pay and create def self.request_bill(order,current_user,current_login_employee) - if !ShiftSale.current_shift(order.shop_code).nil? + if !ShiftSale.current_shift.nil? order_id = order.order_id # order_id bk_order = BookingOrder.find_by_order_id(order_id) check_booking = Booking.find_by_booking_id(bk_order.booking_id) @@ -250,7 +255,7 @@ class Sale < ApplicationRecord # @sale_data.save # Promotion Activation - Promotion.promo_activate(@sale_data,order.shop_code) + Promotion.promo_activate(@sale_data) @status = true return @status, @sale_data else @@ -435,7 +440,8 @@ class Sale < ApplicationRecord #compute - invoice total def compute_by_sale_items(total_discount, discount_type=nil, order_source=nil, tax_type=nil, type=nil) - # shop = Shop.first + + shop = Shop.current_shop #Computation Fields subtotal_price = 0 @@ -502,7 +508,8 @@ class Sale < ApplicationRecord # Tax Re-Calculte def compute_tax(total_taxable, total_discount = 0, order_source = nil, tax_type=nil) - shop = Shop.find_by_shop_code(self.shop_code) + + shop = Shop.current_shop #if tax is not apply create new record # SaleTax.where("sale_id='#{sale.sale_id}'").find_each do |existing_tax| @@ -524,7 +531,7 @@ class Sale < ApplicationRecord tax_profiles = unique_tax_profiles(order_source, self.customer_id) # #Creat new tax records - if self.payment_status != 'foc' + if self.payment_status != 'foc' && tax_type.to_s == "all" tax_profiles.each do |tax| sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name @@ -539,16 +546,82 @@ class Sale < ApplicationRecord divided_value = (100 + rate)/rate sale_tax.tax_payable_amount = total_tax / divided_value else - sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + end + + sale_tax.inclusive = tax.inclusive + sale_tax.save + + if !tax.inclusive total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount end + #new taxable amount is standard rule for step by step if shop.calc_tax_order total_taxable = total_taxable + sale_tax.tax_payable_amount end + end + elsif tax_type.to_s == "no_tax" + tax_profiles.each do |tax| + sale_tax = SaleTax.new(:sale => self) + sale_tax.tax_name = tax.name + sale_tax.tax_rate = 0 + sale_tax.tax_payable_amount = 0 sale_tax.inclusive = tax.inclusive sale_tax.save end + elsif tax_type.to_s == "Commercial Tax" + tax_profiles.each do |tax| + if tax.name == tax_type.to_s + sale_tax = SaleTax.new(:sale => self) + sale_tax.tax_name = tax.name + sale_tax.tax_rate = tax.rate + # substract , to give after discount + total_tax = total_taxable - total_discount + #include or execulive + if tax.inclusive + tax_incl_exec = "inclusive" + rate = tax.rate + divided_value = (100 + rate)/rate + sale_tax.tax_payable_amount = total_tax / divided_value + else + sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount + end + #new taxable amount is standard rule for step by step + if shop.calc_tax_order + total_taxable = total_taxable + sale_tax.tax_payable_amount + end + sale_tax.inclusive = tax.inclusive + sale_tax.save + end + end + elsif tax_type.to_s == "Service Charges" + tax_profiles.each do |tax| + if tax.name == tax_type.to_s + sale_tax = SaleTax.new(:sale => self) + sale_tax.tax_name = tax.name + sale_tax.tax_rate = tax.rate + # substract , to give after discount + total_tax = total_taxable - total_discount + #include or execulive + if tax.inclusive + tax_incl_exec = "inclusive" + rate = tax.rate + divided_value = (100 + rate)/rate + sale_tax.tax_payable_amount = total_tax / divided_value + else + sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount + end + #new taxable amount is standard rule for step by step + if shop.calc_tax_order + total_taxable = total_taxable + sale_tax.tax_payable_amount + end + sale_tax.inclusive = tax.inclusive + sale_tax.save + end + end end self.tax_type = tax_incl_exec self.total_tax = total_tax_amount @@ -556,7 +629,8 @@ class Sale < ApplicationRecord # Tax Calculate def apply_tax(total_taxable, order_source = nil, tax_type = nil) - shop = Shop.find_by_shop_code(self.shop_code) + + shop = Shop.current_shop #if tax is not apply create new record # SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax| @@ -574,7 +648,7 @@ class Sale < ApplicationRecord order_source = "cashier" end - # tax_data = TaxProfile.unscoped.where("group_type=?",order_source).pluck(:id) + # tax_data = TaxProfile.unscope(:order).where("group_type=?",order_source).pluck(:id) # customer = Customer.find(self.customer_id).tax_profiles tax_profiles = unique_tax_profiles(order_source, self.customer_id) @@ -595,6 +669,12 @@ class Sale < ApplicationRecord sale_tax.tax_payable_amount = total_tax / divided_value else sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + end + + sale_tax.inclusive = tax.inclusive + sale_tax.save + + if !tax.inclusive total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount end @@ -602,9 +682,6 @@ class Sale < ApplicationRecord if shop.calc_tax_order total_taxable = total_taxable + sale_tax.tax_payable_amount end - - sale_tax.inclusive = tax.inclusive - sale_tax.save end self.tax_type = tax_incl_exec self.total_tax = total_tax_amount @@ -636,7 +713,8 @@ class Sale < ApplicationRecord end def adjust_rounding - shop_details = Shop.find_by_shop_code(self.shop_code) + + shop_details = Shop.current_shop # rounding adjustment if shop_details.is_rounding_adj new_total = Sale.get_rounding_adjustment(self.grand_total) @@ -652,7 +730,8 @@ class Sale < ApplicationRecord #Generate new Receipt No when it is not assigned def generate_receipt_no #shop_code and client_code - shop_details = Shop.find_by_shop_code(self.shop_code) + + shop_details = Shop.current_shop #Date-Shift- if self.receipt_no.nil? prefix = DateTime.now().utc @@ -773,8 +852,8 @@ def self.daily_sales_list(from,to,shop_code) ELSE 0 END as credit_amount, SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount, SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") - .along_with_sale_payments_except_void - .where("shop_code='#{shop_code}' and (sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to) + .along_with_sale_payments_except_void_between(from, to) + .where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to) .group("sale_id").to_sql daily_total = connection.select_all("SELECT @@ -974,19 +1053,19 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou product = self.get_product_sale() if shift.present? - query = query.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a) + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a) if type.nil? || type == 'all' || type == "other" - other_charges = other_charges.where("sales.shop_code='#{shop_code}' and 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) end - product = product.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) - discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) - change_amount = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) + 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) sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") - .where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a) + .where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a) sale_cash.each do |s_c| total_cash_amount += s_c.cash_amount.to_f total_card_amount += s_c.card_amount.to_f @@ -997,19 +1076,19 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou ### => get all sales range in shift_sales elsif shift_sale_range.present? - query = query.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift_sale_range.to_a) + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift_sale_range.to_a) if type.nil? || type == 'all' || type == "other" - other_charges = other_charges.where("sales.shop_code='#{shop_code}' and 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) end - product = product.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) - discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) - change_amount = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) + 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) sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") - .where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a) + .where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a) sale_cash.each do |s_c| total_cash_amount += s_c.cash_amount.to_f total_card_amount += s_c.card_amount.to_f @@ -1020,20 +1099,20 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f else - query = query.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? #{account_type} and sale_status='completed'",from,to) + query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed'",from,to) if type.nil? || type == 'all' || type == "other" - other_charges = other_charges.where("sales.shop_code='#{shop_code}' and 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) end product = product.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) - discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) - change_amount = Sale.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) + 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) sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") - .where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to) + .where("sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to) sale_cash.each do |s_c| total_cash_amount += s_c.cash_amount.to_f total_card_amount += s_c.card_amount.to_f @@ -1079,19 +1158,19 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status,account_ product = self.get_product_sale() if shift.present? - query = query.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",shift.to_a) + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",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.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) - discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) - change_amount = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) + 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) sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") - .where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a) + .where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a) sale_cash.each do |s_c| total_cash_amount += s_c.cash_amount.to_f total_card_amount += s_c.card_amount.to_f @@ -1102,12 +1181,12 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status,account_ ### => get all sales range in shift_sales elsif shift_sale_range.present? - query = query.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",shift_sale_range.to_a) + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",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.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) - discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) + 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.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, @@ -1165,7 +1244,7 @@ end #product sale report query def self.get_menu_item_query(order_by) - query = MenuItem.unscoped.select("acc.id as account_id, + query = MenuItem.unscope(:order).select("acc.id as account_id, acc.title as account_name, mii.item_instance_code as item_code, " + "(CASE WHEN si.qty IS NOT NULL THEN SUM(si.qty) ELSE 0 END) as total_item," + @@ -1194,7 +1273,7 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_ty payment_type = " and sale_payments.payment_method = '#{payment_type}'" end - query = Sale.all.select("sales.*,sale_payments.*,df.name,df.type") + query = Sale.includes(:sale_items).select("sales.*,sale_payments.*,df.name,df.type") .where("sale_status= 'completed' and sale_payments.payment_amount != 0 #{payment_type}") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .joins("join bookings on bookings.sale_id = sales.sale_id") @@ -1212,17 +1291,16 @@ end def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,payment_type) ## => left join -> show all sales although no orders - if payment_type.blank? - payment_type = '' - else - payment_type = " and sale_payments.payment_method = '#{payment_type}'" - end - query = Sale.select("sales.*,bookings.dining_facility_id as table_id") - .where("sale_status= 'completed' and sale_payments.payment_amount != 0 #{payment_type}") - .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") - .joins("join bookings on bookings.sale_id = sales.sale_id") - .group("sales.sale_id") + query = Sale.includes([:customer, :survey, :sale_payments]) + .includes(:bookings => :dining_facility) + .select("sales.*, SUM(sale_payments.payment_amount) AS payments_for_credits_amount") + .joins(:bookings) + .left_joins(:sale_payments_for_credits) + .completed + .where.not(total_amount: 0) + .group(:sale_id) + .order(:receipt_date) if shift.present? query = query.where("sales.shift_sale_id in (?)", shift.to_a) elsif shift_sale_range.present? @@ -1230,6 +1308,9 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay else query = query.where("sales.receipt_date between ? and ?",from,to) end + + ActiveRecord::Associations::Preloader.new.preload(query, :sale_items, SaleItem.where.not(price: 0)) + return query end @@ -1502,173 +1583,130 @@ end return tax end - def self.top_bottom_products(today,current_user,from,to,from_time,to_time,type,shop) - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - query = Sale.top_bottom(shop,today,nil,from,to,from_time,to_time) - if type == "top" - query = query.group('i.product_name') - .order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.group('i.product_name') - .order("SUM(i.qty) ASC").limit(20) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = Sale.top_bottom(shop,today,nil,from,to,from_time,to_time) - if type == "top" - query = query.group('i.product_name') - .order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.group('i.product_name') - .order("SUM(i.qty) ASC").limit(20) - end - else - shift = ShiftSale.current_open_shift(current_user) - if !shift.nil? - query = Sale.top_bottom(shop,today,shift,from,to,from_time,to_time) - if type == "top" - query = query.group('i.product_name') - .order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.group('i.product_name') - .order("SUM(i.qty) ASC").limit(20) - end - end - end - end + def self.top_bottom_products(current_user,from,to,type,current_shop) + query = Sale.joins("JOIN sale_items ON sale_items.sale_id = sales.sale_id") + .completed + .where("qty > 0 AND price > 0 AND shop_code='#{current_shop.shop_code}'") + .group("SUBSTRING_INDEX(product_name, ' - ', 1)") + + if !from.nil? && !to.nil? + query = query.receipt_date_between(from, to) else - if current_user.nil? - query = Sale.top_bottom(shop,today).group('i.product_name') + query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day) + end + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("shift_sale_id='#{shift.id}'") - if type == "top" - query = query.order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.order("SUM(i.qty) ASC").limit(20) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = Sale.top_bottom(shop,today).group('i.product_name') - if type == "top" - query = query.order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.order("SUM(i.qty) ASC").limit(20) - end - else - shift = ShiftSale.current_open_shift(current_user) - if !shift.nil? - query = Sale.top_bottom(shop,today,shift).group('i.product_name') - if type == "top" - query = query.order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.order("SUM(i.qty) ASC").limit(20) - end - end - end end end + + if type == "top" + query = query.order("SUM(qty) DESC") + else + query = query.order("SUM(qty) ASC") + end + + query.limit(20).sum('qty') end - def self.hourly_sales(today,current_user,from,to,from_time,to_time,shop) - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - query = Sale.hourly_sale_data(shop,today,nil,from,to,from_time,to_time) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = Sale.hourly_sale_data(shop,today,nil,from,to,from_time,to_time) - else - shift = ShiftSale.current_open_shift(current_user) - if !shift.nil? - query = Sale.hourly_sale_data(shop,today,shift,from,to,from_time,to_time) - end - end - end + + def self.hourly_sales(current_user,from,to, current_shop) + query = Sale.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '#{Time.zone.formatted_offset}'), '%I %p')") + .order('receipt_date').completed + + if !from.nil? && !to.nil? + query = query.receipt_date_between(from, to) else - if current_user.nil? - query = Sale.hourly_sale_data(shop,today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = Sale.hourly_sale_data(shop,today) - else - shift = ShiftSale.current_open_shift(current_user) - if !shift.nil? - query = Sale.hourly_sale_data(shop,today,shift) - end - end + query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day) + end + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("shift_sale_id='#{shift.id}'") end end + + query.sum(:grand_total) end - def self.employee_sales(today,current_user,from,to,from_time,to_time,shop) + + def self.employee_sales(current_user,from,to, current_shop) + shift = if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') ShiftSale.current_open_shift(current_user) end payments_for_credits = SalePayment.joins(:sale_audit).to_sql - query = employee_sale(shop,today, shift, from, to, from_time, to_time) + + query = employee_sale(shift, from, to, current_shop) .joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id") .select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount, CASE WHEN sale_payments.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sale_payments.payment_method END AS payment_method, employees.name AS e_name") end - def self.total_trans(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,shop) - query = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count") - .where("sale_status = 'completed' AND shop_code='#{shop.shop_code}'") - if (!from.nil? && !to.nil?) && (from != "" && to!="") - query = query.date_between(from, to) - if !from_time.nil? && !to_time.nil? - query = query.time_between(from_time, to_time) - end + def self.total_trans(current_user=nil,from=nil,to=nil) + query = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count") + .where('sale_status = "completed"') + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + else - query = query.date_on(today) + query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day) end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user) query = query.where("sales.shift_sale_id = ?", shift.id) end end + return query end - def self.total_card_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,shop) + + def self.total_card_sale(current_user=nil,from=nil,to=nil) query = Sale.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") - .where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and (sp.payment_method = 'mpu' or sp.payment_method = 'visa' or sp.payment_method = 'master' or sp.payment_method = 'jcb' or sp.payment_method = 'unionpay' or sp.payment_method = 'alipay' or sp.payment_method = 'paymal' or sp.payment_method = 'dinga' or sp.payment_method = 'JunctionPay')") - if (!from.nil? && !to.nil?) && (from != "" && to!="") - query = query.date_between(from, to) - if !from_time.nil? && !to_time.nil? - query = query.time_between(from_time, to_time) - end + .where('sales.sale_status = "completed" and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")') + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + else - query = query.date_on(today) + query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day) end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user) query = query.where("sales.shift_sale_id = ?", shift.id) end end + query = query.sum("sp.payment_amount") end - def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,shop) + + def self.credit_payment(current_user=nil,from=nil,to=nil, current_shop) + payments_for_credits = SalePayment.joins(:sale_audit).to_sql query = SalePayment.credits .joins(:sale) .joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sale_payments.sale_id") - .where("sale_payments.payment_method= ? AND sales.sale_status = ? AND sales.shop_code=?", 'creditnote', 'completed',shop.shop_code) + .where("sale_payments.payment_method= ? AND sales.sale_status = ? AND sales.shop_code=?", 'creditnote', 'completed',current_shop.shop_code) - if (!from.nil? && !to.nil?) && (from != "" && to!="") - query = query.merge(Sale.date_between(from, to)) - if !from_time.nil? && !to_time.nil? - query = query.merge(Sale.time_between(from_time, to_time)) - end + if (!from.nil? && !to.nil?) + query = query.merge(Sale.receipt_date_between(from, to)) else - query = query.merge(Sale.date_on(today)) + query = query.merge(Sale.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)) end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user) query = query.where("sales.shift_sale_id = ?", shift.id) @@ -1678,52 +1716,57 @@ end return query.sum("sale_payments.payment_amount - IFNULL(payments_for_credits.payment_amount, 0)") end - def self.summary_sale_receipt(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + + def self.summary_sale_receipt(current_user=nil,from=nil,to=nil) query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') - .where("shop_code='#{shop.shop_code}' and sale_status = 'completed'") - if (!from.nil? && !to.nil?) && (from != "" && to!="") - query = query.date_between(from, to) - if !from_time.nil? && !to_time.nil? - query = query.time_between(from_time, to_time) - end + .where('sale_status = "completed"') + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + else - query = query.date_on(today) + query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day) end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user) query = query.where("sales.shift_sale_id = ?", shift.id) end end + query = query.first() end - def self.total_payment_methods(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - query = Sale.select("distinct sp.payment_method") - .where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed'") + + def self.total_payment_methods(current_user=nil,from=nil,to=nil) + query = Sale.select("CASE WHEN sp.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sp.payment_method END as payment_method") + .where("sales.sale_status = 'completed'") .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") - if (!from.nil? && !to.nil?) && (from != "" && to!="") - query = query.date_between(from, to) - if !from_time.nil? && !to_time.nil? - query = query.time_between(from_time, to_time) - end + .group("CASE WHEN sp.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sp.payment_method END") + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) else - query = query.date_on(today) + query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day) end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user) query = query.where("sales.shift_sale_id = ?", shift.id) end end + return query end - def self.payment_sale(shop,payment_method, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + + def self.payment_sale(payment_method, current_user=nil,from=nil,to=nil) + payments_for_credits = SalePayment.joins(:sale_audit).to_sql query = Sale.select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount") .joins(:sale_payments) .joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id") - .where("sales.shop_code='#{shop.shop_code}'") .completed if payment_method == 'card' @@ -1732,13 +1775,10 @@ end query = query.where("sale_payments.payment_method = ?", payment_method) end - if (!from.nil? && !to.nil?) && (from != "" && to!="") - query = query.date_between(from, to) - if !from_time.nil? && !to_time.nil? - query = query.time_between(from_time,to_time) - end + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) else - query = query.date_on(today) + query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day) end if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') @@ -1746,25 +1786,35 @@ end query = query.where("sales.shift_sale_id = ?", shift.id) end end + query.first end - def self.total_customer(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - total_dinein_takeaway = self.total_dinein_takeaway(shop,today,current_user,from,to,from_time,to_time) + + def self.total_customer(current_user=nil,from=nil,to=nil) + total_dinein_takeaway = self.total_dinein_takeaway(current_user,from,to) + dinein_cnt = 0 takeaway_cnt = 0 + if !total_dinein_takeaway.nil? if total_dinein_takeaway[0] dinein_cnt = total_dinein_takeaway[0].total_dinein_cus takeaway_cnt = total_dinein_takeaway[0].total_take_cus end end - membership_cnt = self.total_membership(shop,today,current_user,from,to,from_time,to_time) + + + membership_cnt = self.total_membership(current_user,from,to) + member_cnt = 0 + if !membership_cnt.nil? member_cnt = membership_cnt.total_memb_cus end + total_cus = 0 + if dinein_cnt > dinein_cnt || takeaway_cnt > 0 || !membership_cnt.nil? total_cus = dinein_cnt.to_int + takeaway_cnt.to_int + member_cnt.to_int end @@ -1772,43 +1822,47 @@ end return total_cus, dinein_cnt, takeaway_cnt, member_cnt end - def self.total_dinein_takeaway(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + + def self.total_dinein_takeaway(current_user=nil,from=nil,to=nil) query = Sale.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and c.membership_id is null") - if (!from.nil? && !to.nil?) && (from != "" && to!="") - query = query.date_between(from, to) - if !from_time.nil? && !to_time.nil? - query = query.time_between(from_time, to_time) - end + .where('sales.sale_status = "completed" and c.membership_id is null') + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + else - query = query.date_on(today) + query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day) end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user) query = query.where("sales.shift_sale_id = ?", shift.id) end end + query = query.first() end - def self.total_membership(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + + def self.total_membership(current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and ((c.customer_type = 'Dinein' and c.membership_id is not null) or (c.customer_type = 'Takeaway' and c.membership_id is not null))") - if (!from.nil? && !to.nil?) && (from != "" && to!="") - query = query.date_between(from, to) - if !from_time.nil? && !to_time.nil? - query = query.time_between(from_time, to_time) - end + .where('sales.sale_status = "completed" and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))') + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + else - query = query.date_on(today) + query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day) end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user) query = query.where("sales.shift_sale_id = ?", shift.id) end end + query = query.first() end @@ -1858,18 +1912,18 @@ end # query = query.first() # end - def self.total_order(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + + def self.total_order(current_user=nil,from=nil,to=nil, current_shop) + query = Sale.select("count(distinct sale_orders.order_id) as total_order") .joins(:sale_orders) - .where("shop_code='#{shop.shop_code}'") + .where("shop_code='#{current_shop.shop_code}'") .completed - if (!from.nil? && !to.nil?) && (from != "" && to!="") - query = query.date_between(from, to) - if !from_time.nil? && !to_time.nil? - query = query.time_between(from_time, to_time) - end + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) else - query = query.date_on(today) + query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day) end if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') @@ -1881,85 +1935,70 @@ end query = query.first end - def self.total_account(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - query = Sale.select("distinct b.id as account_id, b.title as title") - .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .joins("JOIN accounts as b ON b.id = a.account_id") - .where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed'") - if (!from.nil? && !to.nil?) && (from != "" && to!="") - query = query.date_between(from, to) - if !from_time.nil? && !to_time.nil? - query = query.time_between(from_time, to_time) - end - else - query = query.date_on(today) - end - if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') - if shift = ShiftSale.current_open_shift(current_user) - query = query.where("sales.shift_sale_id = ?", shift.id) - end - end - return query - end - def self.account_data(shop,account_id, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.account_data(account_id, current_user=nil,from=nil,to=nil) query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and a.account_id ='#{account_id}'") - if (!from.nil? && !to.nil?) && (from != "" && to!="") - query = query.date_between(from, to) - if !from_time.nil? && !to_time.nil? - query = query.time_between(from_time, to_time) - end + .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}'") + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + else - query = query.date_on(today) + query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day) end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user) query = query.where("sales.shift_sale_id = ?", shift.id) end end + query = query.first end - def self.top_items(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + + def self.top_items(current_user=nil,from=nil,to=nil) query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("sales.shop_code='#{shop.shop_code}' and (a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed'") - if (!from.nil? && !to.nil?) && (from != "" && to!="") - query = query.date_between(from, to) - if !from_time.nil? && !to_time.nil? - query = query.time_between(from_time, to_time) - end + .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed'") + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + else - query = query.date_on(today) + query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day) end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user) query = query.where("sales.shift_sale_id = ?", shift.id) end end + query = query.group("a.product_code") .order("SUM(a.qty) DESC") .first() end - def self.total_foc_items(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + + def self.total_foc_items(current_user=nil,from=nil,to=nil) query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and a.status='foc' and a.product_name like '%FOC%'") - if (!from.nil? && !to.nil?) && (from != "" && to!="") - query = query.date_between(from, to) - if !from_time.nil? && !to_time.nil? - query = query.time_between(from_time, to_time) - end + .where("sales.sale_status = 'completed' and a.status='foc' and a.product_name like '%FOC%'") + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + else - query = query.date_on(today) + query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day) end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user) query = query.where("sales.shift_sale_id = ?", shift.id) end end + query = query.count() end @@ -2018,17 +2057,17 @@ end query = query.where("bookings.booking_status = 'assign' AND orders.status = 'new' AND orders.source =? ","#{type}") .group("bookings.booking_id") end - def self.completed_sale(type,shop_code) + def self.completed_sale(type) if type == "cashier" type = "and orders.source = 'emenu' or orders.source = 'cashier'" else type = "and orders.source = '#{type}'" end - query = Sale.where("sales.shop_code='#{shop_code}'") + query = Sale.all query = query.joins("join sale_orders as sale_orders on sale_orders.sale_id = sales.sale_id") .joins("join orders as orders on orders.order_id = sale_orders.order_id") query = query.where("sales.sale_status != 'new' AND orders.status = 'billed' #{type}") - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? ",DateTime.now.strftime('%Y-%m-%d')) + query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day) .group("sales.sale_id") end @@ -2087,8 +2126,7 @@ def self.get_sale_data_for_other_payment_credit(sale_id) end def unique_tax_profiles(order_source, customer_id) - tax_data = TaxProfile.where(group_type: order_source,shop_code: self.shop_code) - + tax_data = TaxProfile.where(group_type: order_source) customer_tax_profiles = Customer.select(:tax_profiles).where(customer_id: customer_id).first if customer_tax_profiles.present? tax_data = tax_data.where(id: customer_tax_profiles.tax_profiles) @@ -2097,71 +2135,16 @@ def unique_tax_profiles(order_source, customer_id) return tax_data end -def self.top_bottom(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) - if !from.nil? && !to.nil? - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + - " i.price as unit_price,i.product_name") - .joins("JOIN sale_items i ON i.sale_id = sales.sale_id") - if !from_time.nil? && !to_time.nil? - query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ - " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") - else - query = query.where("shop_code='#{shop.shop_code}' and (i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ - " and sale_status= 'completed'") - end - if !shift.nil? - query = query.where("shift_sale_id='#{shift.id}'") - end - else - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + - " i.price as unit_price,i.product_name") - .joins("JOIN sale_items i ON i.sale_id = sales.sale_id") - .where("shop_code='#{shop.shop_code}' and (i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ - " and sale_status= 'completed'") - if !shift.nil? - query = query.where("shift_sale_id='#{shift.id}'") - end - end - return query -end -def self.hourly_sale_data(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) - if !from.nil? && !to.nil? - query = Sale.select("grand_total") - if !from_time.nil? && !to_time.nil? - query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) - else - query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - if !shift.nil? - query = query.where("shift_sale_id='#{shift.id}'") - end - query = query.where("shop_code='#{shop.shop_code}'").group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") - .order('receipt_date') - else - query = Sale.select("grand_total") - .where("shop_code='#{shop.shop_code}' and sale_status = 'completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = ?",today) - if !shift.nil? - query = query.where("shift_sale_id='#{shift.id}'") - end - query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") - .order('receipt_date') - end +def self.employee_sale(shift=nil,from=nil,to=nil,from_time=nil,to_time=nil, current_shop) - return query -end - -def self.employee_sale(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.joins(:cashier) .joins(:sale_payments) - .paid.completed.where("sales.shop_code='#{shop.shop_code}'") + .paid.completed if !from.nil? && !to.nil? - query = query.date_between(from, to) - if !from_time.nil? && !to_time.nil? - query = query.time_between(from_time, to_time) - end + query = query.receipt_date_between(from, to) else - query = query.date_on(today) + query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day) end if !shift.nil? @@ -2196,19 +2179,19 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco product = self.get_product_sale() if shift.present? - query = query.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a) + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a) if type.nil? || type == 'all' || type == "other" - other_charges = other_charges.where("sales.shop_code='#{shop_code}' and 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) end - product = product.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) - discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) - change_amount = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) + 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) sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") - .where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a) + .where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a) sale_cash.each do |s_c| total_cash_amount += s_c.cash_amount.to_f total_card_amount += s_c.card_amount.to_f @@ -2219,19 +2202,19 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco ### => get all sales range in shift_sales elsif shift_sale_range.present? - query = query.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift_sale_range.to_a) + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift_sale_range.to_a) if type.nil? || type == 'all' || type == "other" - other_charges = other_charges.where("sales.shop_code='#{shop_code}' and 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) end - product = product.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) - discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) - change_amount = Sale.where("sales.shop_code='#{shop_code}' and sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) + 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) sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") - .where("sales.shop_code='#{shop_code}' and sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a) + .where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a) sale_cash.each do |s_c| total_cash_amount += s_c.cash_amount.to_f total_card_amount += s_c.card_amount.to_f @@ -2242,20 +2225,20 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f else - query = query.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? #{account_type} and sale_status='completed'",from,to) + query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed'",from,to) if type.nil? || type == 'all' || type == "other" - other_charges = other_charges.where("sales.shop_code='#{shop_code}' and 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) end - product = product.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status='completed'",from,to) + product = product.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) - discount_query = Sale.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) - change_amount = Sale.where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) + 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) sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") - .where("sales.shop_code='#{shop_code}' and sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to) + .where("sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to) sale_cash.each do |s_c| total_cash_amount += s_c.cash_amount.to_f total_card_amount += s_c.card_amount.to_f @@ -2314,7 +2297,7 @@ end def grand_total_round print_settings = PrintSetting.get_precision_delimiter() if !print_settings.nil? - self.grand_total =self.grand_total.round(print_settings.precision.to_i) + self.grand_total =self.grand_total.round(precision) end end @@ -2447,7 +2430,48 @@ def self.get_check_sale_data(transaction_date) .where("DATE(sales.receipt_date) = ? AND sales.sale_status != ?", transaction_date, :void) .group("sales.receipt_no,sales.sale_status") end +def paymal_payment_void + puts self.sale_payments.to_json + membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",self.shop_code) + membership_actions_data = MembershipAction.find_by_membership_type_and_shop_code("void",self.shop_code) + if !membership_actions_data.nil? + sale_payments =self.sale_payments.where("payment_reference is not null") + account_no =sale_payments[0].payment_reference + url = membership_setting.gateway_url.to_s + membership_actions_data.gateway_url.to_s + merchant_uid = membership_actions_data.merchant_account_id + auth_token = membership_actions_data.auth_token + params = { receipt_no:self.receipt_no, + account_no:account_no, + merchant_uid:merchant_uid, + auth_token:auth_token}.to_json + # Control for Paypar Cloud + begin + response = HTTParty.post(url, + :body => params, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json; version=3' + }, + :timeout => 10 + ) + rescue Errno::ECONNREFUSED + response = { "status" => false, "message" => "Can't open membership server"} + rescue Net::OpenTimeout + response = { "status" => false, "message" => "No internet connection " } + rescue OpenURI::HTTPError + response = { "status" => false, "message" => "No internet connection "} + rescue SocketError + response = { "status" => false, "message" => "No internet connection "} + end + else + response = { "status" => false} + end + + Rails.logger.debug "Void Payment response" + Rails.logger.debug response.to_json + return response; +end # Loader Service SFTP End private @@ -2461,8 +2485,6 @@ private def round_to_precision if (self.total_amount != self.total_amount_was || self.total_discount != self.total_discount_was || self.total_tax != self.total_tax_was) if (self.total_amount % 1 > 0 || self.total_discount % 1 > 0 || self.total_tax % 1 > 0) - precision = PrintSetting.get_precision_delimiter().precision.to_i - self.total_amount = self.total_amount.round(precision) self.total_discount = self.total_discount.round(precision) self.total_tax = self.total_tax.round(precision) @@ -2475,7 +2497,7 @@ private def update_stock_journal if self.sale_status == "void" && self.sale_status_before_last_save != "void" self.sale_items.each do |item| - found, inventory_definition = InventoryDefinition.find_product_in_inventory(item,self.shop_code) + found, inventory_definition = InventoryDefinition.find_product_in_inventory(item) if found stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first unless stock.nil? @@ -2488,10 +2510,14 @@ private end elsif self.sale_status == "waste" || self.sale_status == "spoile" || (self.payment_status == "foc" && self.payment_status_was != "foc") self.bookings.first.order_items.each do |item| - found, inventory_definition = InventoryDefinition.find_product_in_inventory(item,self.shop_code) + found, inventory_definition = InventoryDefinition.find_product_in_inventory(item) if found if stock_journal = StockJournal.find_by_trans_ref(item.order_items_id) - stock_journal.update(remark: self.sale_status) + if self.payment_status == "foc" && self.payment_status_was != "foc" + stock_journal.update(remark: self.payment_status) + else + stock_journal.update(remark: self.sale_status) + end end end end diff --git a/app/models/sale_audit.rb b/app/models/sale_audit.rb index 1488cad1..d77d59e3 100755 --- a/app/models/sale_audit.rb +++ b/app/models/sale_audit.rb @@ -6,7 +6,7 @@ class SaleAudit < ApplicationRecord belongs_to :sale - belongs_to :credit_payment, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id", class_name: "SalePayment" + belongs_to :sale_payments_for_credit, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id", class_name: "SalePayment" def self.sync_sale_audit_records(sale_audits) if !sale_audits.nil? @@ -150,6 +150,7 @@ class SaleAudit < ApplicationRecord def self.getCardBalanceAmount(sale_id) card_balance_amount = 0 + transaction_ref ='' sale_audits = SaleAudit.where("sale_id='#{sale_id}' AND action='PAYMAL'") if !sale_audits.nil? sale_audits.each do |sale_audit| @@ -159,6 +160,7 @@ class SaleAudit < ApplicationRecord if remark[0] if remark[0]["status"] card_balance_amount = remark[0]["card_balance_amount"] + transaction_ref = remark[0]["transaction_ref"] end end end @@ -166,7 +168,7 @@ class SaleAudit < ApplicationRecord end end - return card_balance_amount + return card_balance_amount,transaction_ref end def self.valid_json(json) diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index c6b19926..177ce1f6 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -1,4 +1,5 @@ class SaleItem < ApplicationRecord + include NumberFormattable self.primary_key = "sale_item_id" #primary key - need to be unique generated for multiple shops @@ -13,6 +14,7 @@ class SaleItem < ApplicationRecord before_validation :round_to_precision after_update :update_stock_journal + after_save :update_stock_journal_set_item # Add Sale Items def self.add_sale_items(sale_items) @@ -293,8 +295,6 @@ class SaleItem < ApplicationRecord if self.unit_price != self.unit_price_was || self.price != self.price_was if unit_price_fraction > 0 || price_fraction > 0 if ['Discount', 'promotion'].include?(self.status) - precision = PrintSetting.get_precision_delimiter().precision.to_i - self.unit_price = self.unit_price.round(precision) self.price = (self.unit_price * self.qty).round(precision) self.taxable_price = self.price @@ -304,40 +304,42 @@ class SaleItem < ApplicationRecord end def update_stock_journal - is_void = self.status == "void" && self.status_before_last_save != "void" - cancel_void = self.status_before_last_save == "void" && self.status.nil? - is_edit = self.qty >= 0 && self.qty != self.qty_before_last_save - is_foc = self.status == "foc" && self.status_before_last_save != "foc" - cancel_foc = self.status_before_last_save == "foc" + unless MenuItemInstance.where("item_instance_name <> ''").pluck(:item_instance_code).include?(self.item_instance_code) + is_void = self.status == "void" && self.status_before_last_save != "void" + cancel_void = self.status_before_last_save == "void" && self.status.nil? + is_edit = self.qty >= 0 && self.qty != self.qty_before_last_save + is_foc = self.status == "foc" && self.status_before_last_save != "foc" + cancel_foc = self.status_before_last_save == "foc" - if is_void or cancel_void or is_edit or is_foc or cancel_foc - found, inventory_definition = InventoryDefinition.find_product_in_inventory(self,self.sale.shop_code) - if found - stock = StockJournal.where("shop_code='#{self.sale.shop_code}' and item_code=?", self.item_instance_code).order("id DESC").first - unless stock.nil? - check_item = StockCheckItem.where("shop_code='#{self.sale.shop_code}' and item_code=?", self.item_instance_code).order("id DESC").first - if is_void or cancel_void or is_edit - if is_void - qty = -self.qty - remark = "void" - elsif cancel_void - qty = self.qty - remark = "cancel void" - elsif is_edit - qty = self.qty - self.qty_before_last_save - remark = "edit" - end - StockJournal.add_to_journal(self.item_instance_code, qty, stock.balance, remark, inventory_definition, self.id, StockJournal::SALES_TRANS) - check_item.different = check_item.different + qty - check_item.save - else is_foc or cancel_foc - qty = StockJournal.where(trans_ref: self.sale_item_id).sum("credit-debit") - if order_item_id = self.sale.bookings.first.order_items.where(item_instance_code: self.item_instance_code, qty: self.qty + qty).select(:order_items_id).first.order_items_id - if stock_journal = StockJournal.find_by_trans_ref(order_item_id) - if is_foc - stock_journal.update(remark: "foc") - elsif cancel_foc - stock_journal.update(remark: "cancel_foc") + if is_void or cancel_void or is_edit or is_foc or cancel_foc + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + if found + stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first + unless stock.nil? + check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first + if is_void or cancel_void or is_edit + if is_void + qty = -self.qty + remark = "void" + elsif cancel_void + qty = self.qty + remark = "cancel void" + elsif is_edit + qty = self.qty - self.qty_before_last_save + remark = "edit" + end + StockJournal.add_to_journal(self.item_instance_code, qty, stock.balance, remark, inventory_definition, self.id, StockJournal::SALES_TRANS) + check_item.different = check_item.different + qty + check_item.save + else is_foc or cancel_foc + qty = StockJournal.where(trans_ref: self.sale_item_id).sum("credit-debit") + if order_item_id = self.sale.bookings.first.order_items.where(item_instance_code: self.item_instance_code, qty: self.qty + qty).select(:order_items_id).first.order_items_id + if stock_journal = StockJournal.find_by_trans_ref(order_item_id) + if is_foc + stock_journal.update(remark: "foc") + elsif cancel_foc + stock_journal.update(remark: "cancel_foc") + end end end end @@ -346,4 +348,80 @@ class SaleItem < ApplicationRecord end end end + + def update_stock_journal_set_item + is_void = self.status == "void" && self.status_before_last_save != "void" && self.qty > 0 + cancel_void = self.status_before_last_save == "void" && self.status.nil? + is_edit = self.qty >= 0 && self.qty != self.qty_before_last_save + is_foc = self.status == "foc" && self.status_before_last_save != "foc" + cancel_foc = self.status_before_last_save == "foc" + + is_waste = self.status == "waste" + is_spoile = self.status == "spoile" + + if MenuItemInstance.where("item_instance_name <> ''").pluck(:item_instance_code).include?(self.item_instance_code) + if self.qty == 1 && self.qty != self.qty_before_last_save + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + if found + stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first + unless stock.nil? + check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first + if self.qty.to_i >= 0 + qty = self.qty - self.qty_was + if stock.balance.to_i >= qty + Rails.logger.info ">> stock is greater than order qty" + remark = "ok" + else + Rails.logger.info " << stock is less than order qty" + remark = "out of stock" + end + end + StockJournal.add_to_journal(self.item_instance_code, qty, stock.balance, remark, inventory_definition, self.id, StockJournal::SALES_TRANS) + check_item.different = check_item.different - qty + check_item.save + else + StockJournal.add_to_journal(self.item_instance_code, self.qty, 0, "out of stock", inventory_definition, self.id, StockJournal::SALES_TRANS) + end + end + elsif is_void or cancel_void or is_edit + if is_void + qty = -self.qty + remark = "void" + elsif cancel_void + qty = self.qty + remark = "cancel void" + elsif is_edit + qty = self.qty - self.qty_before_last_save + remark = "edit" + end + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + if found + stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first + unless stock.nil? + check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first + + StockJournal.add_to_journal(self.item_instance_code, qty, stock.balance, remark, inventory_definition, self.id, StockJournal::SALES_TRANS) + check_item.different = check_item.different + qty + check_item.save + end + end + elsif is_foc or cancel_foc + qty = StockJournal.where(trans_ref: self.sale_item_id).sum("credit-debit") + if stock_journal = StockJournal.where(trans_ref: self.sale_item_id, item_code: self.item_instance_code).order(id: :desc).first + if is_foc + stock_journal.update(remark: "foc") + elsif cancel_foc + stock_journal.update(remark: "cancel_foc") + end + end + elsif is_waste or is_spoile + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + if found + if stock_journal = StockJournal.where(trans_ref: self.sale_item_id, item_code: self.item_instance_code) + stock_journal.update(remark: self.status) + end + end + end + end + end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index d01b2069..96be1d56 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -70,8 +70,6 @@ class SalePayment < ApplicationRecord self.sale = invoice self.received_amount = cash_amount self.payment_reference = remark - # puts action_by - # puts "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" self.action_by = action_by #get all payment for this invoices if payment_for @@ -87,7 +85,7 @@ class SalePayment < ApplicationRecord amount_due = amount_due - payment.payment_amount end end - if (amount_due >= 0) + if (amount_due > 0) payment_status = false membership_data = nil #route to payment type @@ -227,14 +225,14 @@ class SalePayment < ApplicationRecord 'Accept' => 'application/json; version=3' }, :timeout => 10 ) + rescue Errno::ECONNREFUSED + response = { "status" => false, "message" => "Can't open membership server"} rescue Net::OpenTimeout - response = { status: false } - + response = { "status" => false, "message" => "No internet connection " } rescue OpenURI::HTTPError - response = { status: false} - + response = { "status" => false, "message" => "No internet connection "} rescue SocketError - response = { status: false} + response = { "status" => false, "message" => "No internet connection "} end Rails.logger.debug "Get Paypar Account " Rails.logger.debug response.to_json @@ -242,10 +240,7 @@ class SalePayment < ApplicationRecord end def self.redeem(paypar_url,token,membership_id,received_amount,sale_id) - # membership_actions_data = MembershipAction.find_by_membership_type("redeem"); membership_actions_data = PaymentMethodSetting.find_by_payment_method("Redeem") - puts "This is membership_actions_data" - puts membership_actions_data.to_json if !membership_actions_data.nil? url = paypar_url.to_s + membership_actions_data.gateway_url.to_s @@ -335,7 +330,6 @@ class SalePayment < ApplicationRecord auth_token:auth_token}.to_json end - puts params # Control for Paypar Cloud begin response = HTTParty.post(url, @@ -539,11 +533,8 @@ class SalePayment < ApplicationRecord payment_status = false #Next time - validate if the vochure number is valid - within - # customer_data = Customer.find_by_customer_id(self.sale.customer_id) account_no = self.payment_reference - # if account_no.to_i <= 0 - # account_no = customer_data.membership_id - # end + # self.sale.customer.update_attributes(paypar_account_no: ) membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",self.sale.shop_code) membership_data = SalePayment.create_payment(membership_setting.gateway_url,"PAYMAL",account_no,self.received_amount,self.sale.sale_id) @@ -554,7 +545,7 @@ class SalePayment < ApplicationRecord if membership_data["status"]==true self.payment_method = "paymal" self.payment_amount = self.received_amount - self.payment_reference = self.voucher_no + # self.payment_reference = self.voucher_no self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f self.payment_status = "paid" payment_status = self.save! @@ -783,27 +774,14 @@ class SalePayment < ApplicationRecord def table_update_status(sale_obj) status = true sale_count = 0 - booking = Booking.find_by_sale_id(sale_obj.id) - if booking + if booking = sale_obj.bookings[0] if booking.dining_facility_id.to_i > 0 - table = DiningFacility.find(booking.dining_facility_id) - bookings = table.bookings - bookings.each do |tablebooking| - if tablebooking.booking_status != 'moved' - if tablebooking.sale_id - if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void' && tablebooking.sale.sale_status != 'spoile' && tablebooking.sale.sale_status != 'waste' - status = false - sale_count += 1 - else - status = true - end - else - status = false - sale_count += 1 - end - end + table = booking.dining_facility + if Booking.left_joins(:sale).where(dining_facility_id: booking.dining_facility_id).where.not(booking_status: 'moved').where("sales.sale_status NOT IN ('completed', 'void', 'spoile', 'waste') OR sales.sale_status IS NULL").exists? + status = false end - if status && sale_count == 0 + + if status table.update_attributes(status: "available") # table.status = "available" # table.save @@ -975,38 +953,34 @@ class SalePayment < ApplicationRecord end #credit payment query + def self.get_credit_sales(params,shop_code) - receipt_no = "" - customer = "" - if !params["receipt_no"].blank? - receipt_no = " and s.receipt_no LIKE '%#{params["receipt_no"]}%'" + payments = SalePayment.select("sale_payments.sale_id, sale_payments.sale_payment_id, sale_payments.payment_method, sale_payments.payment_amount") + .select("SUM(sale_payments.payment_amount) OVER (PARTITION BY sale_payments.sale_id) total_payment_amount") + + credit_sales = Sale.select("sales.sale_id, sales.receipt_no, sales.receipt_date as sale_date, sales.cashier_name") + .select("sale_payments.sale_payment_id, sale_payments.payment_amount").select("customers.name as customer_name") + .joins("JOIN (#{payments.to_sql}) AS sale_payments ON sale_payments.sale_id = sales.sale_id").joins(:customer).joins(:orders) + .completed.paid.where("sale_payments.payment_method = 'creditnote' AND sales.grand_total > sale_payments.total_payment_amount - sale_payments.payment_amount and sales.shop_code=?",shop_code) + .group(:receipt_no) + .order(:receipt_date).order(:receipt_no) + + if params["receipt_no"].present? + credit_sales = credit_sales.where("sales.receipt_no LIKE ?", "%#{params["receipt_no"]}%") + end - if !params["customer_id"].blank? - customer = " and s.customer_id = '#{params["customer_id"]}'" + if params["customer_id"].present? + credit_sales = credit_sales.where("sales.customer_id = ?", params["customer_id"]) end - order_source_query = "(select orders.source FROM orders JOIN sale_orders so ON so.order_id=orders.order_id WHERE so.sale_id=s.sale_id GROUP BY so.sale_id)" - - query = SalePayment.select("s.receipt_no, sale_payments.sale_payment_id, - sale_payments.payment_method, - SUM(sale_payments.payment_amount) as payment_amount, - s.receipt_date as sale_date, - s.sale_id, - s.cashier_name as cashier_name, c.name as customer_name") - .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - .joins("INNER JOIN customers c ON c.customer_id = s.customer_id") - - if params[:type].nil? - query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}") - elsif params[:type] == "cashier" - query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' AND #{order_source_query}='#{params[:type]}' OR #{order_source_query}='emenu' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}") - else - query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' AND #{order_source_query}='#{params[:type]}' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}") + if params[:type].present? + sources = [] + sources << params[:type] + sources << 'emenu' if params[:type] == 'cashier' + credit_sales = credit_sales.where("orders.source IN (?)", sources) end - query = query.where("s.shop_code='#{shop_code}'").group("s.receipt_no") - .order("s.receipt_date ASC, s.receipt_no ASC") - return query + end def self.get_credit_amount_due_left(sale_id) diff --git a/app/models/sale_tax.rb b/app/models/sale_tax.rb index 6baa3f47..e84aa434 100755 --- a/app/models/sale_tax.rb +++ b/app/models/sale_tax.rb @@ -1,4 +1,5 @@ class SaleTax < ApplicationRecord + include NumberFormattable self.primary_key = "sale_tax_id" #primary key - need to be unique generated for multiple shops @@ -44,7 +45,6 @@ class SaleTax < ApplicationRecord def round_to_precision if self.tax_payable_amount != self.tax_payable_amount_was if self.tax_payable_amount % 1 > 0 - precision = PrintSetting.get_precision_delimiter().precision.to_i self.tax_payable_amount = self.tax_payable_amount.round(precision) end end diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 3125ca8d..3c13bf6a 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -16,11 +16,10 @@ class ShiftSale < ApplicationRecord belongs_to :cashier_terminal belongs_to :employee, :foreign_key => 'employee_id' has_many :sales - belongs_to :shop - def self.current_shift(shop_code) + def self.current_shift # today_date = DateTime.now.strftime("%Y-%m-%d") - shift = ShiftSale.where("shop_code='#{shop_code}' and shift_started_at is not null and shift_closed_at is null").first + shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null").first return shift end @@ -84,6 +83,7 @@ class ShiftSale < ApplicationRecord self.shift_started_at = DateTime.now self.employee_id = current_user.id self.opening_balance = opening_balance + self.shop_code = current_user.shop_code self.other_sales = 0 self.save end diff --git a/app/models/shop.rb b/app/models/shop.rb index d12986a1..a9b672b1 100755 --- a/app/models/shop.rb +++ b/app/models/shop.rb @@ -1,12 +1,18 @@ class Shop < ApplicationRecord - #ShopDetail = Shop.find_by_id(1) + #ShopDetail = Shop.current_shop # Shop Image Uploader + mount_uploader :logo, ShopImageUploader has_many :display_images + accepts_nested_attributes_for :display_images def file_data=(input_data) self.data = input_data.read end + + def self.current_shop + ActsAsTenant.current_tenant + end end diff --git a/app/models/stock_journal.rb b/app/models/stock_journal.rb index d70ca051..2250b23a 100755 --- a/app/models/stock_journal.rb +++ b/app/models/stock_journal.rb @@ -4,6 +4,8 @@ class StockJournal < ApplicationRecord ORDER_TRANS = "order" STOCK_CHECK_TRANS = "stock_check" + scope :created_at_between, -> (from, to) { where(created_at: from..to)} + def self.add_to_journal(item_instance_code, qty, old_balance, stock_message, inventory_definition, trans_ref, trans_type) # item => saleObj | balance => Stock journal balance = calculate_balance(old_balance, qty) @@ -56,23 +58,14 @@ class StockJournal < ApplicationRecord journal.save end - def self.inventory_balances(today,from,to,from_time,to_time,shop) + + def self.inventory_balances(from,to, current_shop) + query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") + .joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code") + .group("mii.item_instance_name") + .order("mii.item_instance_name ASC") if !from.nil? && !to.nil? - query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") - .joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code") - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'") - else - query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'") - end - query = query.where("shop_code='#{shop.shop_code}'").group("mii.item_instance_name") - .order("mii.item_instance_name ASC") - else - query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") - .joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code") - .where("shop_code='#{shop.shop_code}' and DATE_FORMAT(stock_journals.created_at,'%Y-%m-%d') = '#{today}'") - .group("mii.item_instance_name") - .order("mii.item_instance_name ASC") + query = query.created_at_between(from, to) end end diff --git a/app/models/verify_number.rb b/app/models/verify_number.rb index 26c57057..50b0fcca 100644 --- a/app/models/verify_number.rb +++ b/app/models/verify_number.rb @@ -1,10 +1,9 @@ -class VerifyNumber < ApplicationRecord +class VerifyNumber def self.send_message(phone, pin) - url = "http://smspoh.com/api/http/send?key=5QfyN0OtGsFXnOqwtpVAGZCyPGP28nbX_Nm_oPsUw2ybq714T_951ycz3Ypl5URA&message=Doemal,+Pin+Code:+"+pin.to_s+"&recipients="+ phone.to_s + url = "http://smspoh.com/api/http/send?key=5QfyN0OtGsFXnOqwtpVAGZCyPGP28nbX_Nm_oPsUw2ybq714T_951ycz3Ypl5URA&message=Local Kitchen,+Pin+Code:+"+pin.to_s+"&recipients="+ phone.to_s - puts url begin @result = HTTParty.get(url.to_str) @@ -18,7 +17,6 @@ class VerifyNumber < ApplicationRecord response = { status: false, message: "Can't open membership server "} end puts @result - puts "<><><><><><<><>><><" end end diff --git a/app/pdf/check_in_out_pdf.rb b/app/pdf/check_in_out_pdf.rb index 08b9eba8..dfc40c2c 100644 --- a/app/pdf/check_in_out_pdf.rb +++ b/app/pdf/check_in_out_pdf.rb @@ -1,5 +1,5 @@ class CheckInOutPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:order_no_font_size, :item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,booking, table) self.page_width = print_settings.page_width diff --git a/app/pdf/close_cashier_customise_pdf.rb b/app/pdf/close_cashier_customise_pdf.rb index 2b05394d..f23ae950 100644 --- a/app/pdf/close_cashier_customise_pdf.rb +++ b/app/pdf/close_cashier_customise_pdf.rb @@ -1,5 +1,5 @@ class CloseCashierCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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,:text_width def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) @@ -39,22 +39,11 @@ class CloseCashierCustomisePdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - #check delimiter - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header( shop_details) stroke_horizontal_rule - shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) end def header (shop_details) @@ -103,13 +92,13 @@ class CloseCashierCustomisePdf < Prawn::Document bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do text "#{ shift_sale.shift_closed_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left end - + y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do text "Opening Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + text "#{ number_format(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left end y_position = cursor @@ -117,8 +106,8 @@ class CloseCashierCustomisePdf < Prawn::Document text "Closing Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left - # text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}" + text "#{ number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + # text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}" end @@ -135,7 +124,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Received Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end @@ -144,7 +133,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Cash In :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -152,7 +141,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Cash Out :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end move_down -5 @@ -165,7 +154,7 @@ class CloseCashierCustomisePdf < Prawn::Document total_discount_account = total_discount_account.to_f + amount.total_price.to_f end - #end total amount by Account + #end total amount by Account #start total FOC amount @total_foc = 0 @@ -173,7 +162,7 @@ class CloseCashierCustomisePdf < Prawn::Document @total_foc = other.foc_amount.round(2) end - #end total FOC amount + #end total FOC amount total_grand_total = shift_sale.grand_total + @total_foc.to_f + shift_sale.total_void.to_f - total_discount_account.to_f # @total_grand_total = @shift_sale.grand_total + @overall + @total_foc + @shift_sale.total_void y_position = cursor @@ -181,21 +170,21 @@ class CloseCashierCustomisePdf < Prawn::Document text "Grand Total :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(total_grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(total_grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end #start total amount by Account Like Food / Beverage /.. total_discount_by_account.each do |amount| - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Discount:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{ number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end - #end total amount by Account + #end total amount by Account y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do @@ -205,8 +194,8 @@ class CloseCashierCustomisePdf < Prawn::Document @total_foc = 0 end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right - end + text "(#{ number_format(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + end y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do @@ -218,7 +207,7 @@ class CloseCashierCustomisePdf < Prawn::Document move_down -5 stroke_horizontal_rule - move_down 7 + move_down 7 @total_foc = 0 y_position = cursor @@ -226,7 +215,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Cash Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -234,9 +223,9 @@ class CloseCashierCustomisePdf < Prawn::Document text "Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right end - #start other payment details + #start other payment details if shift_sale.other_sales > 0 other_payment.each do |other| @total_foc = other.foc_amount.round(2) @@ -246,7 +235,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "MPU Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -256,7 +245,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "VISA Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -266,7 +255,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Master Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -276,7 +265,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "JCB Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -286,7 +275,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "UNIONPAY Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -296,7 +285,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Alipay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -306,7 +295,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "JunctionPay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -316,7 +305,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Dinga Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -326,17 +315,17 @@ class CloseCashierCustomisePdf < Prawn::Document text "Redeem Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end if other.paymal_amount && other.paymal_amount.to_f > 0 y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Paymal Payment :", :size => self.item_font_size, :align => :right + text "Card Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -346,7 +335,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "GiftVoucher Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end end @@ -356,7 +345,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Other Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -365,8 +354,8 @@ class CloseCashierCustomisePdf < Prawn::Document text "Rounding Adjustments :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - + text "#{ number_format(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end y_position = cursor @@ -374,14 +363,14 @@ class CloseCashierCustomisePdf < Prawn::Document text "Gross Sale :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right + text "#{ number_format(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right end - # end other payment details + # end other payment details move_down -5 stroke_horizontal_rule move_down 7 - + # start Dinein and Takeaway y_position = cursor @@ -392,7 +381,7 @@ class CloseCashierCustomisePdf < Prawn::Document total_dinein = 0 end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_dinein, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(total_dinein, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -401,11 +390,11 @@ class CloseCashierCustomisePdf < Prawn::Document end if total_takeway.nil? total_takeway = 0 - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_takeway, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end - + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_format(total_takeway, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + # stop Dinein and Takeaway move_down -5 @@ -419,7 +408,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "#{tax.tax_name} :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -428,7 +417,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Total Taxes :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -436,7 +425,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Net Sales :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right + text "#{number_format(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right end if total_credit_payments && total_credit_payments.to_f > 0 @@ -445,7 +434,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Total Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end #end for service charges and commercial tax @@ -463,16 +452,16 @@ class CloseCashierCustomisePdf < Prawn::Document move_down 7 #start total amount by Account Like Food / Beverage /.. # total_discount_by_account.each do |amount| - + # y_position = cursor # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do # text "Total #{amount.account_name} Discount:", :size => self.item_font_size, :align => :right # end # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - # text "#{ number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + # text "#{ number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right # end # end - #end total amount by Account + #end total amount by Account # y_position = cursor # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do @@ -481,19 +470,19 @@ class CloseCashierCustomisePdf < Prawn::Document # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do # text "#{shift_sale.grand_total}", :size => self.item_font_size, :align => :right # end - + #start total amount by Account Like Food / Beverage /.. - total_amount_by_account.each do |amount| + total_amount_by_account.each do |amount| y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end - #end total amount by Account + #end total amount by Account #start total other charges amount if total_other_charges.present? @@ -502,9 +491,9 @@ class CloseCashierCustomisePdf < Prawn::Document text "Total Other Charges :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_other_charges, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(total_other_charges, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end - end + end #end total other charges amount move_down -5 @@ -513,32 +502,32 @@ class CloseCashierCustomisePdf < Prawn::Document #start total over all discount if total_member_discount[0].member_discount.present? - @member_discount = total_member_discount[0].member_discount rescue 0.0 + @member_discount = total_member_discount[0].member_discount rescue 0.0 @overall = shift_sale.total_discounts - @member_discount - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Member Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end - else - @overall = shift_sale.total_discounts + else + @overall = shift_sale.total_discounts end - + if @overall > 0 y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "-#{ number_with_precision(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end + text "-#{ number_format(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end move_down -5 stroke_horizontal_rule move_down 7 - end + end #end total over all discount if total_waste.to_f > 0 @@ -547,7 +536,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Total Waste :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end end @@ -557,7 +546,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Total Spoile :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end end @@ -591,4 +580,3 @@ class CloseCashierCustomisePdf < Prawn::Document move_down 5 end end - diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index d4564291..095f1de6 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -1,5 +1,5 @@ class CloseCashierPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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,:text_width def initialize(printer_settings, shift_sale, sale_items, total_other_charges_info, acc_cate_count, menu_cate_count, total_by_acc, shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) @@ -39,25 +39,14 @@ class CloseCashierPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - #check delimiter - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header( shop_details) stroke_horizontal_rule - shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments) + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments) if !sale_items.nil? or !sale_items.blank? - sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc, total_other_charges_info) + sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc, total_other_charges_info) end end @@ -107,13 +96,13 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do text "#{ shift_sale.shift_closed_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left end - + y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do text "Opening Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + text "#{ number_format(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left end y_position = cursor @@ -121,8 +110,8 @@ class CloseCashierPdf < Prawn::Document text "Closing Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left - # text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}" + text "#{ number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + # text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}" end @@ -139,7 +128,7 @@ class CloseCashierPdf < Prawn::Document text "Received Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end @@ -148,7 +137,7 @@ class CloseCashierPdf < Prawn::Document text "Cash In:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -156,7 +145,7 @@ class CloseCashierPdf < Prawn::Document text "Cash Out:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end move_down -5 @@ -169,7 +158,7 @@ class CloseCashierPdf < Prawn::Document text "Cash Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -177,10 +166,10 @@ class CloseCashierPdf < Prawn::Document text "Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right end - #start other payment details + #start other payment details if shift_sale.other_sales > 0 other_payment.each do |other| @total_foc = other.foc_amount.round(2) @@ -190,7 +179,7 @@ class CloseCashierPdf < Prawn::Document text "MPU Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -200,7 +189,7 @@ class CloseCashierPdf < Prawn::Document text "VISA Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -210,7 +199,7 @@ class CloseCashierPdf < Prawn::Document text "Master Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -220,7 +209,7 @@ class CloseCashierPdf < Prawn::Document text "JCB Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -230,7 +219,7 @@ class CloseCashierPdf < Prawn::Document text "UNIONPAY Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -240,7 +229,7 @@ class CloseCashierPdf < Prawn::Document text "Alipay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -250,7 +239,7 @@ class CloseCashierPdf < Prawn::Document text "KBZ Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.kbzpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.kbzpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -260,7 +249,7 @@ class CloseCashierPdf < Prawn::Document text "JunctionPay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -270,7 +259,7 @@ class CloseCashierPdf < Prawn::Document text "Dinga Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -280,17 +269,17 @@ class CloseCashierPdf < Prawn::Document text "Redeem Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end if other.paymal_amount && other.paymal_amount.to_f > 0 y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Paymal Payment :", :size => self.item_font_size, :align => :right + text "Card Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -300,7 +289,7 @@ class CloseCashierPdf < Prawn::Document text "GiftVoucher Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end end @@ -310,7 +299,7 @@ class CloseCashierPdf < Prawn::Document text "Other Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -319,7 +308,7 @@ class CloseCashierPdf < Prawn::Document text "Rounding Adjustments :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -327,10 +316,10 @@ class CloseCashierPdf < Prawn::Document text "Total :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right + text "#{ number_format(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right end - # end other payment details + # end other payment details move_down -5 stroke_horizontal_rule move_down 7 @@ -342,7 +331,7 @@ class CloseCashierPdf < Prawn::Document text "#{tax.tax_name} :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -351,7 +340,7 @@ class CloseCashierPdf < Prawn::Document text "Total Taxes :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -359,7 +348,7 @@ class CloseCashierPdf < Prawn::Document text "Net Sales :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right + text "#{number_format(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right end if total_credit_payments && total_credit_payments.to_f > 0 @@ -368,7 +357,7 @@ class CloseCashierPdf < Prawn::Document text "Total Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end #end for service charges and commercial tax @@ -386,30 +375,30 @@ class CloseCashierPdf < Prawn::Document move_down 7 #start total amount by Account Like Food / Beverage /.. total_discount_by_account.each do |amount| - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Discount:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{ number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end - #end total amount by Account + #end total amount by Account if total_member_discount[0].member_discount.present? - @member_discount = total_member_discount[0].member_discount rescue 0.0 + @member_discount = total_member_discount[0].member_discount rescue 0.0 @overall = shift_sale.total_discounts - @member_discount - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Member Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end - else - @overall = shift_sale.total_discounts + else + @overall = shift_sale.total_discounts end y_position = cursor @@ -417,18 +406,18 @@ class CloseCashierPdf < Prawn::Document text "Total Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end + text "#{ number_format(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total FOC :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right - end + text "(#{ number_format(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + end - y_position = cursor + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Void :", :size => self.item_font_size, :align => :right end @@ -441,7 +430,7 @@ class CloseCashierPdf < Prawn::Document text "Total Waste :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end y_position = cursor @@ -449,7 +438,7 @@ class CloseCashierPdf < Prawn::Document text "Total Spoile :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end # y_position = cursor @@ -459,19 +448,19 @@ class CloseCashierPdf < Prawn::Document # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do # text "#{shift_sale.grand_total}", :size => self.item_font_size, :align => :right # end - + move_down -5 stroke_horizontal_rule move_down 7 #start total amount by Account Like Food / Beverage /.. - total_amount_by_account.each do |amount| + total_amount_by_account.each do |amount| y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end @@ -482,7 +471,7 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{total_other_charges}", :size => self.item_font_size, :align => :right end - #end total amount by Account + #end total amount by Account y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do @@ -532,7 +521,7 @@ class CloseCashierPdf < Prawn::Document sale_items.each do |item| if !arr.include?(item['menu_category_id']) - + if flag == true move_down 5 stroke_horizontal_rule @@ -567,7 +556,7 @@ class CloseCashierPdf < Prawn::Document # text_box "#{item['grand_total'].to_i}", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix # } add_item_line(item['product_name'], item['unit_price'].to_i, item['total_item'].to_i, item['grand_total'].to_i) - + if item['total_item'].to_i > 0 or item['status_type'] == 'foc' or item['status_type'] == 'void' total_qty += item['total_item'].to_i total_items += item['total_item'].to_i @@ -657,4 +646,4 @@ class CloseCashierPdf < Prawn::Document text_box "#{sub_total.to_i}", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix } end -end \ No newline at end of file +end diff --git a/app/pdf/close_cashier_pdf_v1.rb b/app/pdf/close_cashier_pdf_v1.rb index 687f0aa8..eb87aa5b 100644 --- a/app/pdf/close_cashier_pdf_v1.rb +++ b/app/pdf/close_cashier_pdf_v1.rb @@ -1,5 +1,5 @@ class CloseCashierPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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,:text_width def initialize(printer_settings, shift_sale, total_by_acc, shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) @@ -39,22 +39,11 @@ class CloseCashierPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - #check delimiter - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header( shop_details) stroke_horizontal_rule - shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments) + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments) end @@ -104,13 +93,13 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do text "#{ shift_sale.shift_closed_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left end - + y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do text "Opening Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + text "#{ number_format(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left end y_position = cursor @@ -118,8 +107,8 @@ class CloseCashierPdf < Prawn::Document text "Closing Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left - # text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}" + text "#{ number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + # text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}" end @@ -136,7 +125,7 @@ class CloseCashierPdf < Prawn::Document text "Received Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end @@ -145,7 +134,7 @@ class CloseCashierPdf < Prawn::Document text "Cash In:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -153,7 +142,7 @@ class CloseCashierPdf < Prawn::Document text "Cash Out:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end move_down -5 @@ -166,7 +155,7 @@ class CloseCashierPdf < Prawn::Document text "Cash Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -174,10 +163,10 @@ class CloseCashierPdf < Prawn::Document text "Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right end - #start other payment details + #start other payment details if shift_sale.other_sales > 0 other_payment.each do |other| @total_foc = other.foc_amount.round(2) @@ -187,7 +176,7 @@ class CloseCashierPdf < Prawn::Document text "MPU Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -197,7 +186,7 @@ class CloseCashierPdf < Prawn::Document text "VISA Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -207,7 +196,7 @@ class CloseCashierPdf < Prawn::Document text "Master Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -217,7 +206,7 @@ class CloseCashierPdf < Prawn::Document text "JCB Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -227,7 +216,7 @@ class CloseCashierPdf < Prawn::Document text "UNIONPAY Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -237,7 +226,7 @@ class CloseCashierPdf < Prawn::Document text "Alipay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -247,7 +236,7 @@ class CloseCashierPdf < Prawn::Document text "JunctionPay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -257,7 +246,7 @@ class CloseCashierPdf < Prawn::Document text "Dinga Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -267,17 +256,17 @@ class CloseCashierPdf < Prawn::Document text "Redeem Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end if other.paymal_amount && other.paymal_amount.to_f > 0 y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Paymal Payment :", :size => self.item_font_size, :align => :right + text "Card Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -287,7 +276,7 @@ class CloseCashierPdf < Prawn::Document text "GiftVoucher Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end end @@ -297,7 +286,7 @@ class CloseCashierPdf < Prawn::Document text "Other Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -306,7 +295,7 @@ class CloseCashierPdf < Prawn::Document text "Rounding Adjustments :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -314,10 +303,10 @@ class CloseCashierPdf < Prawn::Document text "Total :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right + text "#{ number_format(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right end - # end other payment details + # end other payment details move_down -5 stroke_horizontal_rule move_down 7 @@ -329,7 +318,7 @@ class CloseCashierPdf < Prawn::Document text "#{tax.tax_name} :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -338,7 +327,7 @@ class CloseCashierPdf < Prawn::Document text "Total Taxes :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -346,7 +335,7 @@ class CloseCashierPdf < Prawn::Document text "Net Sales :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right + text "#{number_format(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right end if total_credit_payments && total_credit_payments.to_f > 0 @@ -355,7 +344,7 @@ class CloseCashierPdf < Prawn::Document text "Total Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end #end for service charges and commercial tax @@ -373,30 +362,30 @@ class CloseCashierPdf < Prawn::Document move_down 7 #start total amount by Account Like Food / Beverage /.. total_discount_by_account.each do |amount| - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Discount:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{ number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end - #end total amount by Account + #end total amount by Account if total_member_discount[0].member_discount.present? - @member_discount = total_member_discount[0].member_discount rescue 0.0 + @member_discount = total_member_discount[0].member_discount rescue 0.0 @overall = shift_sale.total_discounts - @member_discount - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Member Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end - else - @overall = shift_sale.total_discounts + else + @overall = shift_sale.total_discounts end y_position = cursor @@ -404,18 +393,18 @@ class CloseCashierPdf < Prawn::Document text "Total Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end + text "#{ number_format(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total FOC :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right - end + text "(#{ number_format(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + end - y_position = cursor + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Void :", :size => self.item_font_size, :align => :right end @@ -428,7 +417,7 @@ class CloseCashierPdf < Prawn::Document text "Total Waste :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end y_position = cursor @@ -436,7 +425,7 @@ class CloseCashierPdf < Prawn::Document text "Total Spoile :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end # y_position = cursor @@ -446,19 +435,19 @@ class CloseCashierPdf < Prawn::Document # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do # text "#{shift_sale.grand_total}", :size => self.item_font_size, :align => :right # end - + move_down -5 stroke_horizontal_rule move_down 7 #start total amount by Account Like Food / Beverage /.. - total_amount_by_account.each do |amount| + total_amount_by_account.each do |amount| y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end @@ -469,7 +458,7 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{total_other_charges}", :size => self.item_font_size, :align => :right end - #end total amount by Account + #end total amount by Account y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do @@ -502,4 +491,4 @@ class CloseCashierPdf < Prawn::Document end -end \ No newline at end of file +end diff --git a/app/pdf/move_table_pdf.rb b/app/pdf/move_table_pdf.rb index 5d44b393..dc55eedc 100644 --- a/app/pdf/move_table_pdf.rb +++ b/app/pdf/move_table_pdf.rb @@ -1,5 +1,5 @@ class MoveTablePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :margin_top, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(printer_settings,to,from,shop_detail,date,type,moved_by,order_items) self.page_width = printer_settings.page_width @@ -39,7 +39,7 @@ class MoveTablePdf < Prawn::Document stroke_horizontal_rule move_down 5 - add_lining_item(order_items, printer_settings.precision) + add_lining_item(order_items, precision) move_down 5 stroke_horizontal_rule @@ -98,7 +98,7 @@ class MoveTablePdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "#{number_with_precision(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left + text "#{number_format(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do diff --git a/app/pdf/move_table_star_pdf.rb b/app/pdf/move_table_star_pdf.rb index 0467cbab..88ea4ef1 100644 --- a/app/pdf/move_table_star_pdf.rb +++ b/app/pdf/move_table_star_pdf.rb @@ -1,5 +1,5 @@ class MoveTableStarPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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,to,from,shop_detail,date,type,moved_by,order_items) self.page_width = printer_settings.page_width @@ -38,7 +38,7 @@ class MoveTableStarPdf < Prawn::Document stroke_horizontal_rule move_down 5 - add_lining_item(order_items, printer_settings.precision) + add_lining_item(order_items, precision) move_down 5 stroke_horizontal_rule @@ -97,7 +97,7 @@ class MoveTableStarPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "#{number_with_precision(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left + text "#{number_format(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do diff --git a/app/pdf/order_item_customise_pdf.rb b/app/pdf/order_item_customise_pdf.rb index b509a01a..6277fbe1 100644 --- a/app/pdf/order_item_customise_pdf.rb +++ b/app/pdf/order_item_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderItemCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:order_no_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order_item, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width @@ -34,20 +34,25 @@ class OrderItemCustomisePdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" #font "public/fonts/Chinese.ttf" - if !order_item.dining.nil? - text "#{ order_item.type + '-' + order_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 - else - text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 - end - - stroke_horizontal_rule - move_down 3 + if order_item.source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{order_item.contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end + if !order_item.dining.nil? + text "#{ order_item.type + '-' + order_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + else + text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + end + stroke_horizontal_rule + move_down 3 #order_info order_info(order_item.order_id, order_item.order_by,order_item.order_at) # order items - order_items(order_item, options, alt_name, print_settings.precision, before_updated_qty) + order_items(order_item, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF @@ -107,7 +112,7 @@ class OrderItemCustomisePdf < Prawn::Document end bounding_box([self.item_width - 10,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right + text "[#{number_format(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right end bounding_box([0,y_position], :width => self.item_width) do @@ -146,7 +151,7 @@ class OrderItemCustomisePdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.page_width) do - text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index ed079aeb..7475bb46 100755 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -1,5 +1,5 @@ class OrderItemPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :margin_top, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order_item, print_status, options, alt_name, before_updated_qty) @@ -32,23 +32,28 @@ class OrderItemPdf < Prawn::Document font "#{print_settings.font}" fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end - # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - #font "public/fonts/Chinese.ttf" - if !order_item.dining.nil? - text "#{ order_item.type + '-' + order_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 - else - text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 - end - - stroke_horizontal_rule - move_down 3 + # font "public/fonts/Zawgyi-One.ttf" + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" + if order_item.source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{order_item.contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end + if !order_item.dining.nil? + text "#{ order_item.type + '-' + order_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + else + text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + end + stroke_horizontal_rule + move_down 3 #order_info order_info(order_item.order_id, order_item.order_by,order_item.order_at) # order items - order_items(order_item, options, alt_name, print_settings.precision, before_updated_qty) + order_items(order_item, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF @@ -108,7 +113,7 @@ class OrderItemPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "[#{number_format(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do @@ -147,7 +152,7 @@ class OrderItemPdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_item_slim_customise_pdf.rb b/app/pdf/order_item_slim_customise_pdf.rb index c4b1e5c5..e1f0b0bc 100644 --- a/app/pdf/order_item_slim_customise_pdf.rb +++ b/app/pdf/order_item_slim_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderItemSlimCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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, :item_slim_font_size def initialize(print_settings,order_item_slim, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width @@ -11,9 +11,9 @@ class OrderItemSlimCustomisePdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 self.item_slim_font_size=8 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -29,53 +29,58 @@ class OrderItemSlimCustomisePdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - #font "public/fonts/Chinese.ttf" - if !order_item_slim.dining.nil? - text "#{ order_item_slim.type + '-' + order_item_slim.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 - else - text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 - end - - stroke_horizontal_rule - move_down 1 + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" + if order_item_slim.source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{order_item_slim.contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end + if !order_item_slim.dining.nil? + text "#{ order_item_slim.type + '-' + order_item_slim.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + else + text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + end + stroke_horizontal_rule + move_down 1 #order_info order_info(order_item_slim.order_id, order_item_slim.order_by,order_item_slim.order_at) # order items slim - order_items_slim(order_item_slim, options, alt_name, print_settings.precision, before_updated_qty) + order_items_slim(order_item_slim, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_slim_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_slim_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.item_slim_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_slim_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_slim_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_slim_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_slim_font_size,:align => :left + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_slim_font_size,:align => :left end stroke_horizontal_rule @@ -88,7 +93,7 @@ class OrderItemSlimCustomisePdf < Prawn::Document def order_items_slim(order_item_slim, options, alt_name, precision, before_updated_qty) y_position = cursor - #Add Order Item + #Add Order Item add_order_items_slim(order_item_slim, options, alt_name, precision) dash(1, :space => 1, :phase => 1) @@ -108,7 +113,7 @@ class OrderItemSlimCustomisePdf < Prawn::Document end bounding_box([self.item_width - 5,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_item_slim.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right + text "[#{number_format(order_item_slim.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right end bounding_box([0,y_position], :width => self.item_width) do @@ -146,7 +151,7 @@ class OrderItemSlimCustomisePdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.page_width) do - text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_item_slim_pdf.rb b/app/pdf/order_item_slim_pdf.rb index 3e39644f..31c8dac9 100755 --- a/app/pdf/order_item_slim_pdf.rb +++ b/app/pdf/order_item_slim_pdf.rb @@ -1,7 +1,7 @@ class OrderItemSlimPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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(print_settings,order_item_slim, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width self.page_height = print_settings.page_height @@ -12,9 +12,9 @@ class OrderItemSlimPdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) # super(:margin => [10, 5, 30, 5], :page_size => [200,400]) @@ -29,53 +29,59 @@ class OrderItemSlimPdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - #font "public/fonts/Chinese.ttf" - if !order_item_slim.dining.nil? - text "#{ order_item_slim.type + '-' + order_item_slim.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 - else - text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 - end - - stroke_horizontal_rule - move_down 1 + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" + if order_item_slim.source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{order_item_slim.contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end + if !order_item_slim.dining.nil? + text "#{ order_item_slim.type + '-' + order_item_slim.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + else + text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + end + + stroke_horizontal_rule + move_down 1 #order_info order_info(order_item_slim.order_id, order_item_slim.order_by,order_item_slim.order_at) # order items slim - order_items_slim(order_item_slim, options, alt_name, print_settings.precision, before_updated_qty) + order_items_slim(order_item_slim, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left end stroke_horizontal_rule @@ -87,7 +93,7 @@ class OrderItemSlimPdf < Prawn::Document def order_items_slim(order_item_slim, options, alt_name, precision, before_updated_qty) y_position = cursor - #Add Order Item + #Add Order Item add_order_items_slim(order_item_slim, options, alt_name, precision) puts options puts '............PDF OPTIONS...............' @@ -108,7 +114,7 @@ class OrderItemSlimPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_item_slim.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "[#{number_format(order_item_slim.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do @@ -146,7 +152,7 @@ class OrderItemSlimPdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_item_star_pdf.rb b/app/pdf/order_item_star_pdf.rb index 2686efd7..2115f234 100644 --- a/app/pdf/order_item_star_pdf.rb +++ b/app/pdf/order_item_star_pdf.rb @@ -1,5 +1,5 @@ class OrderItemStarPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :margin_top, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order_item, print_status, options, alt_name, before_updated_qty) @@ -35,20 +35,26 @@ class OrderItemStarPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" #font "public/fonts/Chinese.ttf" - if !order_item.dining.nil? - text "#{ order_item.type + '-' + order_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 - else - text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 - end + if order_item.source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{order_item.contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end + if !order_item.dining.nil? + text "#{ order_item.type + '-' + order_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + else + text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + end - stroke_horizontal_rule - move_down 3 + stroke_horizontal_rule + move_down 3 #order_info order_info(order_item.order_id, order_item.order_by,order_item.order_at) # order items - order_items(order_item, options, alt_name, print_settings.precision, before_updated_qty) + order_items(order_item, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF @@ -108,7 +114,7 @@ class OrderItemStarPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "[#{number_format(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do @@ -147,7 +153,7 @@ class OrderItemStarPdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_set_item_customise_pdf.rb b/app/pdf/order_set_item_customise_pdf.rb index 2e1d0a2c..47b9a155 100644 --- a/app/pdf/order_set_item_customise_pdf.rb +++ b/app/pdf/order_set_item_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderSetItemCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:order_no_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order_set_item, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width @@ -12,9 +12,9 @@ class OrderSetItemCustomisePdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) # super(:margin => [10, 5, 30, 5], :page_size => [200,400]) @@ -29,52 +29,58 @@ class OrderSetItemCustomisePdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - #font "public/fonts/Chinese.ttf" - if !order_set_item.dining.nil? - text "#{ order_set_item.type + '-' + order_set_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 - else - text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 - end - stroke_horizontal_rule - move_down 3 + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" + if order_set_item.source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{order_set_item.contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end + if !order_set_item.dining.nil? + text "#{ order_set_item.type + '-' + order_set_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + else + text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + end + stroke_horizontal_rule + move_down 3 #order_info order_info(order_set_item.order_id, order_set_item.order_by,order_set_item.order_at) # order items - order_set_items(order_set_item, options, alt_name, print_settings.precision, before_updated_qty) + order_set_items(order_set_item, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.order_no_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.order_no_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.order_no_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.order_no_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.order_no_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.order_no_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.order_no_font_size,:align => :left + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.order_no_font_size,:align => :left end stroke_horizontal_rule @@ -86,7 +92,7 @@ class OrderSetItemCustomisePdf < Prawn::Document def order_set_items(order_set_item, options, alt_name, precision, before_updated_qty) y_position = cursor - #Add Order Item + #Add Order Item add_order_set_items(order_set_item, options, alt_name, precision) dash(1, :space => 1, :phase => 1) @@ -106,7 +112,7 @@ class OrderSetItemCustomisePdf < Prawn::Document end bounding_box([self.item_width - 5,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_set_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right + text "[#{number_format(order_set_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right end bounding_box([0,y_position], :width => self.item_width) do @@ -161,7 +167,7 @@ class OrderSetItemCustomisePdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.page_width) do - text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_set_item_pdf.rb b/app/pdf/order_set_item_pdf.rb index 09cdc6db..abffe96a 100755 --- a/app/pdf/order_set_item_pdf.rb +++ b/app/pdf/order_set_item_pdf.rb @@ -1,5 +1,5 @@ class OrderSetItemPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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(print_settings,order_set_item, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width @@ -11,9 +11,9 @@ class OrderSetItemPdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) # super(:margin => [10, 5, 30, 5], :page_size => [200,400]) @@ -28,52 +28,58 @@ class OrderSetItemPdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - #font "public/fonts/Chinese.ttf" - if !order_set_item.dining.nil? - text "#{ order_set_item.type + '-' + order_set_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 - else - text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 - end - stroke_horizontal_rule - move_down 3 + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" + if order_set_item.source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{order_set_item.contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end + if !order_set_item.dining.nil? + text "#{ order_set_item.type + '-' + order_set_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + else + text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + end + stroke_horizontal_rule + move_down 3 #order_info order_info(order_set_item.order_id, order_set_item.order_by,order_set_item.order_at) # order items - order_set_items(order_set_item, options, alt_name, print_settings.precision, before_updated_qty) + order_set_items(order_set_item, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left end move_down 2 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left end move_down 2 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left end move_down 2 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left end stroke_horizontal_rule @@ -85,7 +91,7 @@ class OrderSetItemPdf < Prawn::Document def order_set_items(order_set_item, options, alt_name, precision, before_updated_qty) y_position = cursor - #Add Order Item + #Add Order Item add_order_set_items(order_set_item, options, alt_name, precision) dash(1, :space => 1, :phase => 1) @@ -105,7 +111,7 @@ class OrderSetItemPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_set_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "[#{number_format(order_set_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do @@ -160,7 +166,7 @@ class OrderSetItemPdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_summary_customise_pdf.rb b/app/pdf/order_summary_customise_pdf.rb index 8ffedca0..c6bec6e1 100644 --- a/app/pdf/order_summary_customise_pdf.rb +++ b/app/pdf/order_summary_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderSummaryCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:order_no_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width @@ -34,6 +34,12 @@ class OrderSummaryCustomisePdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" + if order[0].source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{order[0].contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end if !order[0].dining.nil? text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 else @@ -48,9 +54,9 @@ class OrderSummaryCustomisePdf < Prawn::Document # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end @@ -113,7 +119,7 @@ class OrderSummaryCustomisePdf < Prawn::Document end bounding_box([self.item_width - 10,y_position], :width => self.qty_width) do - text " [#{number_with_precision(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text " [#{number_format(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index fd446131..c0aa7c5f 100755 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -1,5 +1,5 @@ class OrderSummaryPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width @@ -11,9 +11,9 @@ class OrderSummaryPdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -27,58 +27,62 @@ class OrderSummaryPdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - + if order[0].source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{order[0].contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end if !order[0].dining.nil? text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 else text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 end - + stroke_horizontal_rule move_down 5 - #order_info order_info(order[0].order_id, order[0].order_by,order[0].order_at) # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left - end - - move_down 5 - y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no}", :size => self.item_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left end move_down 5 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + text "OrderNo: #{order_no}", :size => self.item_font_size,:align => :left end move_down 5 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + end + + move_down 5 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left end stroke_horizontal_rule @@ -103,7 +107,7 @@ class OrderSummaryPdf < Prawn::Document #Add Order Item add_order_items(order_item, alt_name, precision) - + end # Add order items under order info @@ -113,7 +117,7 @@ class OrderSummaryPdf < Prawn::Document move_down 5 order_item.each do|odi| - # check for item not to show + # check for item not to show # if odi.price != 0 y_position = cursor @@ -123,14 +127,14 @@ class OrderSummaryPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "#{number_with_precision(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left + text "#{number_format(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do text "#{odi.item_code} - #{odi.item_name}", :size => self.item_font_size,:align => :left end - + if alt_name if !(odi.alt_name).empty? move_down 4 @@ -138,15 +142,15 @@ class OrderSummaryPdf < Prawn::Document text "(#{odi.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true # end end - + end # add option options = odi.options == "[]"? "" : odi.options - + if options != "" move_down 5 - + y_position = cursor bounding_box([0,y_position], :width => self.item_width) do text "#{options}", :size => self.item_font_size,:align => :left @@ -161,7 +165,7 @@ class OrderSummaryPdf < Prawn::Document stroke_horizontal_line 0, (self.page_width - self.margin) move_down 5 # end - end + end end def get_booking_id(order_no) diff --git a/app/pdf/order_summary_set_customise_pdf.rb b/app/pdf/order_summary_set_customise_pdf.rb index 0e33d314..56008dd2 100644 --- a/app/pdf/order_summary_set_customise_pdf.rb +++ b/app/pdf/order_summary_set_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderSummarySetCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:order_no_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width @@ -12,9 +12,9 @@ class OrderSummarySetCustomisePdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -33,52 +33,58 @@ class OrderSummarySetCustomisePdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" + + if order[0].source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{order[0].contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end if !order[0].dining.nil? text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 else text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 end - + stroke_horizontal_rule move_down 5 - #order_info order_info(order[0].order_id, order[0].order_by,order[0].order_at) # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.order_no_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.order_no_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.order_no_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.order_no_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.order_no_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.order_no_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.order_no_font_size,:align => :left + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.order_no_font_size,:align => :left end stroke_horizontal_rule @@ -92,7 +98,7 @@ class OrderSummarySetCustomisePdf < Prawn::Document #Add Order Item add_order_items(order_item, alt_name, precision) - + end # Add order items under order info @@ -102,7 +108,7 @@ class OrderSummarySetCustomisePdf < Prawn::Document move_down 5 order_item.each do|odi| - # check for item not to show + # check for item not to show # if odi.price != 0 y_position = cursor @@ -112,14 +118,14 @@ class OrderSummarySetCustomisePdf < Prawn::Document end bounding_box([self.item_width - 5,y_position], :width => self.qty_width) do - text "[#{number_with_precision(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "[#{number_format(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do text "#{odi.item_code} - #{odi.item_name}", :size => self.item_font_size,:align => :left end - + if alt_name if !(odi.alt_name).empty? move_down 4 @@ -127,7 +133,7 @@ class OrderSummarySetCustomisePdf < Prawn::Document text "(#{odi.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true # end end - + end #add set menu items @@ -148,10 +154,10 @@ class OrderSummarySetCustomisePdf < Prawn::Document # add option options = odi.options == "[]"? "" : odi.options - + if options != "" move_down 5 - + y_position = cursor bounding_box([0,y_position], :width => self.item_width) do text "#{options}", :size => self.item_font_size,:align => :left @@ -166,7 +172,7 @@ class OrderSummarySetCustomisePdf < Prawn::Document stroke_horizontal_line 0, (self.page_width - self.margin) move_down 5 # end - end + end end def get_booking_id(order_no) diff --git a/app/pdf/order_summary_set_pdf.rb b/app/pdf/order_summary_set_pdf.rb index 5e27f82b..6e905b47 100755 --- a/app/pdf/order_summary_set_pdf.rb +++ b/app/pdf/order_summary_set_pdf.rb @@ -1,5 +1,5 @@ class OrderSummarySetPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width @@ -11,9 +11,9 @@ class OrderSummarySetPdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -32,52 +32,58 @@ class OrderSummarySetPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" + + if order[0].source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{order[0].contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end if !order[0].dining.nil? text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 else text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 end - + stroke_horizontal_rule move_down 5 - #order_info order_info(order[0].order_id, order[0].order_by,order[0].order_at) # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left - end - - move_down 5 - y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left end move_down 5 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left end move_down 5 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + end + + move_down 5 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left end stroke_horizontal_rule @@ -102,7 +108,7 @@ class OrderSummarySetPdf < Prawn::Document #Add Order Item add_order_items(order_item, alt_name, precision) - + end # Add order items under order info @@ -112,7 +118,7 @@ class OrderSummarySetPdf < Prawn::Document move_down 5 order_item.each do|odi| - # check for item not to show + # check for item not to show # if odi.price != 0 y_position = cursor @@ -122,14 +128,14 @@ class OrderSummarySetPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "#{number_with_precision(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left + text "#{number_format(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do text "#{odi.item_code} - #{odi.item_name}", :size => self.item_font_size,:align => :left end - + if alt_name if !(odi.alt_name).empty? move_down 4 @@ -137,7 +143,7 @@ class OrderSummarySetPdf < Prawn::Document text "(#{odi.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true # end end - + end #add set menu items @@ -158,10 +164,10 @@ class OrderSummarySetPdf < Prawn::Document # add option options = odi.options == "[]"? "" : odi.options - + if options != "" move_down 5 - + y_position = cursor bounding_box([0,y_position], :width => self.item_width) do text "#{options}", :size => self.item_font_size,:align => :left @@ -176,7 +182,7 @@ class OrderSummarySetPdf < Prawn::Document stroke_horizontal_line 0, (self.page_width - self.margin) move_down 5 # end - end + end end def get_booking_id(order_no) diff --git a/app/pdf/order_summary_slim_customise_pdf.rb b/app/pdf/order_summary_slim_customise_pdf.rb index c641b0c8..9f4ad23e 100644 --- a/app/pdf/order_summary_slim_customise_pdf.rb +++ b/app/pdf/order_summary_slim_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderSummarySlimCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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,:item_slim_font_size def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width @@ -11,10 +11,10 @@ class OrderSummarySlimCustomisePdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 - self.item_slim_font_size=8 + self.label_width=90 + self.item_slim_font_size=8 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -33,12 +33,18 @@ class OrderSummarySlimCustomisePdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" + if order[0].source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{order[0].contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end if !order[0].dining.nil? text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 else text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 end - + stroke_horizontal_rule move_down 1 @@ -47,38 +53,38 @@ class OrderSummarySlimCustomisePdf < Prawn::Document # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_slim_font_size,:align => :left - end - - move_down 1 - y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.item_slim_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_slim_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_slim_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_slim_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_slim_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_slim_font_size,:align => :left + end + + move_down 1 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_slim_font_size,:align => :left end stroke_horizontal_rule @@ -95,7 +101,7 @@ class OrderSummarySlimCustomisePdf < Prawn::Document #Add Order Item add_order_items(order_item, alt_name, precision) - + end # Add order items under order info @@ -105,7 +111,7 @@ class OrderSummarySlimCustomisePdf < Prawn::Document move_down 1 order_item.each do|odi| - # check for item not to show + # check for item not to show # if odi.price != 0 y_position = cursor @@ -115,14 +121,14 @@ class OrderSummarySlimCustomisePdf < Prawn::Document end bounding_box([self.item_width - 5,y_position], :width => self.qty_width) do - text "[#{number_with_precision(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "[#{number_format(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do text "#{odi.item_name}", :size => self.item_font_size,:align => :left end - + if alt_name if !(odi.alt_name).empty? move_down 1 @@ -134,7 +140,7 @@ class OrderSummarySlimCustomisePdf < Prawn::Document # add option options = odi.options == "[]"? "" : odi.options - + if options != "" move_down 1 @@ -152,7 +158,7 @@ class OrderSummarySlimCustomisePdf < Prawn::Document stroke_horizontal_line 0, (self.page_width - self.margin) move_down 1 # end - end + end end def get_booking_id(order_no) diff --git a/app/pdf/order_summary_slim_pdf.rb b/app/pdf/order_summary_slim_pdf.rb index 1b78cf23..ac1bc87f 100755 --- a/app/pdf/order_summary_slim_pdf.rb +++ b/app/pdf/order_summary_slim_pdf.rb @@ -1,5 +1,5 @@ class OrderSummarySlimPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width @@ -11,9 +11,9 @@ class OrderSummarySlimPdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -32,12 +32,18 @@ class OrderSummarySlimPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" + if order[0].source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{order[0].contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end if !order[0].dining.nil? text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 else text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 end - + stroke_horizontal_rule move_down 1 @@ -46,38 +52,38 @@ class OrderSummarySlimPdf < Prawn::Document # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left - end - - move_down 1 - y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + end + + move_down 1 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left end stroke_horizontal_rule @@ -102,7 +108,7 @@ class OrderSummarySlimPdf < Prawn::Document #Add Order Item add_order_items(order_item, alt_name, precision) - + end # Add order items under order info @@ -112,7 +118,7 @@ class OrderSummarySlimPdf < Prawn::Document move_down 1 order_item.each do|odi| - # check for item not to show + # check for item not to show # if odi.price != 0 y_position = cursor @@ -122,14 +128,14 @@ class OrderSummarySlimPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "#{number_with_precision(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left + text "#{number_format(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do text "#{odi.item_name}", :size => self.item_font_size,:align => :left end - + if alt_name if !(odi.alt_name).empty? move_down 1 @@ -141,7 +147,7 @@ class OrderSummarySlimPdf < Prawn::Document # add option options = odi.options == "[]"? "" : odi.options - + if options != "" move_down 1 @@ -159,7 +165,7 @@ class OrderSummarySlimPdf < Prawn::Document stroke_horizontal_line 0, (self.page_width - self.margin) move_down 1 # end - end + end end def get_booking_id(order_no) diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 02443c0c..a5ab093c 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -1,8 +1,8 @@ class ReceiptBillA5Pdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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, :description_width, :price_num_width, :line_move - def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data,other_charges_amount,latest_order_no,card_balance_amount) + def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data,other_charges_amount,latest_order_no,card_balance_amount,transaction_ref) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height self.header_font_size = printer_settings.header_font_size.to_i @@ -26,11 +26,6 @@ class ReceiptBillA5Pdf < Prawn::Document #setting page margin and width super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - # db font setup if printer_settings.font != "" font_families.update("#{printer_settings.font}" => { @@ -46,23 +41,22 @@ class ReceiptBillA5Pdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header(shop_details) - + if sale_data.orders[0].source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{sale_data.customer.contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end stroke_horizontal_rule cashier_info(sale_data, customer_name, latest_order_no) - line_items(sale_items,printer_settings.precision,delimiter) - all_total(sale_data,printer_settings.precision,delimiter) + line_items(sale_items,precision,delimiter) + all_total(sale_data,precision,delimiter) if member_info != nil - member_info(member_info,customer_name,rebate_amount,sale_data,printer_settings.precision,delimiter,current_balance) + member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance) end customer(customer_name) @@ -73,25 +67,26 @@ class ReceiptBillA5Pdf < Prawn::Document end #end card sale trans data #start card blanace amount - if !card_balance_amount.nil? + if !card_balance_amount.nil? && card_balance_amount >0 card_balance_data(card_balance_amount) + card_transaction_ref(transaction_ref) end #end card blanace amount - + if discount_price_by_accounts.length > 0 && shop_details.show_account_info - discount_account(discount_price_by_accounts,printer_settings.precision,delimiter) + discount_account(discount_price_by_accounts,precision,delimiter) end if shop_details.show_account_info - items_account(item_price_by_accounts,printer_settings.precision,delimiter) + items_account(item_price_by_accounts,precision,delimiter) if other_charges_amount - show_other_charges_amount(other_charges_amount,printer_settings.precision,delimiter) + show_other_charges_amount(other_charges_amount,precision,delimiter) end end #start for individual payment if !sale_data.equal_persons.nil? - individual_payment(sale_data, printer_settings.precision, delimiter) + individual_payment(sale_data, precision, delimiter) end #end for individual payment @@ -100,7 +95,7 @@ class ReceiptBillA5Pdf < Prawn::Document if shop_details.note && !shop_details.note.nil? shop_note(printed_status) end - + footer(printed_status) end @@ -130,7 +125,7 @@ class ReceiptBillA5Pdf < Prawn::Document text "OrderNo : #{ latest_order_no }", :size => self.header_font_size+2,:align => :left end move_down line_move - + # move_down 2 y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do @@ -154,7 +149,7 @@ class ReceiptBillA5Pdf < Prawn::Document bounding_box([self.item_description_width, y_position], :width =>self.item_description_width, :height => self.item_height) do text "W: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left - end + end bounding_box([self.item_description_width - 2,y_position], :width =>self.item_description_width, :height => self.item_height) do text "C: #{sale_data.cashier_name}", :size => self.item_font_size,:align => :right end @@ -172,7 +167,7 @@ class ReceiptBillA5Pdf < Prawn::Document # bounding_box([self.item_description_width,y_position], :width =>self.label_width+5) do - # text "(#{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } + # text "(#{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } # - #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') })" , # :size => self.item_font_size,:align => :right # end @@ -209,7 +204,7 @@ class ReceiptBillA5Pdf < Prawn::Document end def add_line_item_row(sale_items,precision,delimiter) - + if precision.to_i > 0 item_name_width = (self.item_width+self.price_width) item_qty_front_width = (self.item_width+self.price_width) + 5 @@ -229,17 +224,17 @@ class ReceiptBillA5Pdf < Prawn::Document sub_total = 0.0 total_qty = 0.0 sale_items.each do |item| - # check for item not to show + # check for item not to show show_price = Lookup.find_by_lookup_type("show_price") sub_total += item.price #(item.qty*item.unit_price) - comment for room charges if item.status != 'Discount' && item.qty > 0 if !show_price.nil? && show_price.value.to_i > 0 && item.price == 0 - total_qty += item.qty + total_qty += item.qty else if item.price != 0 - total_qty += item.qty + total_qty += item.qty end end end @@ -265,14 +260,15 @@ class ReceiptBillA5Pdf < Prawn::Document text "Sub Total", :size => self.item_font_size,:align => :left end # bounding_box([self.item_width + self.price_width + 11,y_position], :width =>self.qty_width, :height => self.item_height) do - # text "#{number_with_precision(total_qty, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :center + # text "#{number_format(total_qty, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :center # end # bounding_box([self.item_width + self.price_width + 8,y_position], :width =>self.total_width, :height => self.item_height) do - # text "#{number_with_precision(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + # text "#{number_format(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right # end - text_box "#{number_with_precision(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - + + text_box "#{number_format(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + end def item_row(item,precision,delimiter,product_name,price,qty ,total_price) @@ -297,10 +293,12 @@ class ReceiptBillA5Pdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_width) do text "#{product_name}", :size => self.item_font_size,:align => :left end - # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size - text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size + + text_box "#{number_format(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + if show_alt_name if !(item.product_alt_name).empty? @@ -328,7 +326,7 @@ class ReceiptBillA5Pdf < Prawn::Document text "#{ dis_type }", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "( #{number_with_precision(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right + text "( #{number_format(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right end if sale_data.sale_taxes.length > 0 @@ -344,7 +342,7 @@ class ReceiptBillA5Pdf < Prawn::Document text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end else @@ -370,7 +368,7 @@ class ReceiptBillA5Pdf < Prawn::Document end bounding_box([self.description_width,y_position], :width =>self.label_width) do text "#{sale_data.rounding_adjustment}", :size => self.item_font_size,:align => :right - end + end end move_down line_move @@ -380,15 +378,15 @@ class ReceiptBillA5Pdf < Prawn::Document text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right + text "#{number_format(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right end move_down line_move - + sale_payment(sale_data,precision,delimiter) - + end - def sale_payment(sale_data,precision,delimiter) + def sale_payment(sale_data,precision,delimiter) stroke_horizontal_rule # move_down 10 sql = "SELECT SUM(payment_amount) @@ -412,35 +410,39 @@ class ReceiptBillA5Pdf < Prawn::Document y_position = cursor if payment.payment_method == "paypar" bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do - text "Redeem Payment", :size => self.item_font_size,:align => :left - end + text "Redeem Payment", :size => self.item_font_size,:align => :left + end else + payment_method = payment.payment_method.capitalize + if payment.payment_method == "paymal" + payment_method ='Card' + end bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do - text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left + text "#{payment_method} Payment", :size => self.item_font_size,:align => :left + end end - end - + bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end - if sale_data.amount_received > 0 + if sale_data.amount_received > 0 y_position = cursor move_down line_move bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do text "Change Amount", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end #move_down line_move - end + end end # show member information def member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance) - if rebate_amount != nil + if rebate_amount != nil if rebate_amount["status"] == true stroke_horizontal_rule total = 0 @@ -467,10 +469,10 @@ class ReceiptBillA5Pdf < Prawn::Document text "Rebate Earn", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end - - end + + end # Total Rebate Amount if birthday if res["receipt_no"]== sale_data.receipt_no && res["account_status"]== "RebatebonusAccount" && res["status"]== "Rebate" rebate_balance = rebate_balance + res["deposit"] @@ -480,9 +482,9 @@ class ReceiptBillA5Pdf < Prawn::Document text "Rebate Earn Bonus", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end - end + end #end Total rebate if birthday end @@ -492,7 +494,7 @@ class ReceiptBillA5Pdf < Prawn::Document text "Redeem Amount", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end if current_balance != nil @@ -502,10 +504,10 @@ class ReceiptBillA5Pdf < Prawn::Document text "Old Balance", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end - + end end @@ -515,7 +517,7 @@ class ReceiptBillA5Pdf < Prawn::Document if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount" total_balance = total_balance + res["balance"] - + end end move_down line_move @@ -524,10 +526,10 @@ class ReceiptBillA5Pdf < Prawn::Document text "Total Balance", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end - + end def customer(customer_name) @@ -554,8 +556,9 @@ class ReceiptBillA5Pdf < Prawn::Document text "#{ 'Total ' + ipa[:name] + ' Discounts' }", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "(" + "#{ number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right - end + + text "(" + "#{ number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right + end move_down line_move end end @@ -570,8 +573,10 @@ class ReceiptBillA5Pdf < Prawn::Document text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.description_width) do - text "#{number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right - end + + text "#{number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + + end move_down line_move end end @@ -582,9 +587,9 @@ class ReceiptBillA5Pdf < Prawn::Document text "Other Charges", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - text "#{number_with_precision(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end - move_down line_move + move_down line_move end #individual payment per person @@ -604,7 +609,7 @@ class ReceiptBillA5Pdf < Prawn::Document bounding_box([self.label_width,y_position], :width =>self.item_description_width) do move_down 15 - text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end @@ -623,17 +628,17 @@ class ReceiptBillA5Pdf < Prawn::Document JOIN sale_audits sa ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payment_id where sa.sale_id='#{sale_data.sale_id}')) = 0 - THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id).each do |payment| + THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id).each do |payment| if payment.payment_method == "creditnote" y_position = cursor stroke_horizontal_rule - + bounding_box([self.label_width,y_position], :width =>self.description_width) do move_down 70 stroke_horizontal_rule end - + bounding_box([self.label_width,y_position], :width =>self.description_width) do move_down 73 text "Approved By" , :size => self.item_font_size,:align => :center @@ -650,8 +655,8 @@ class ReceiptBillA5Pdf < Prawn::Document move_down 70 stroke_horizontal_rule end - - if sale_data.payment_status == "foc" + + if sale_data.payment_status == "foc" bounding_box([self.label_width,y_position], :width =>self.description_width) do move_down 73 text "Acknowledged By" , :size => self.item_font_size,:align => :center @@ -661,10 +666,10 @@ class ReceiptBillA5Pdf < Prawn::Document move_down 73 text "Approved By" , :size => self.item_font_size,:align => :center end - end - - end - + end + + end + end def shop_note(shop) @@ -674,8 +679,8 @@ class ReceiptBillA5Pdf < Prawn::Document move_down line_move y_position = cursor - - text "#{shop.note}", :size => self.item_font_size,:align => :left + + text "#{shop.note}", :size => self.item_font_size,:align => :left move_down line_move end @@ -688,10 +693,10 @@ class ReceiptBillA5Pdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.item_description_width) do text "#{printed_status}",:style => :bold, :size => header_font_size,:align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.item_description_width, :height => self.item_height) do text "Thank You! See you Again", :left_margin => -5, :size => self.item_font_size,:align => :right - end + end move_down line_move end @@ -721,7 +726,6 @@ class ReceiptBillA5Pdf < Prawn::Document #start card balance data def card_balance_data(card_balance_amount) - if card_balance_amount > 0 move_down line_move stroke_horizontal_rule move_down line_move @@ -729,11 +733,24 @@ class ReceiptBillA5Pdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width) do text "Card Balance: ",:style => :bold, :size => header_font_size,:align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{card_balance_amount}" , :size => self.item_font_size,:align => :right end - end + end + #start card transaction_ref + def card_transaction_ref(transaction_ref) + move_down line_move + stroke_horizontal_rule + move_down line_move + + y_position = cursor + bounding_box([0, y_position], :width =>self.label_width) do + text "Transaction ref: ",:style => :bold, :size => header_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{transaction_ref}" , :size => self.item_font_size,:align => :right + end end #check ReceiptBillAltName included @@ -753,4 +770,4 @@ class ReceiptBillA5Pdf < Prawn::Document end return status end -end \ No newline at end of file +end diff --git a/app/pdf/receipt_bill_order_pdf.rb b/app/pdf/receipt_bill_order_pdf.rb index e66cb37e..2f4efc5f 100644 --- a/app/pdf/receipt_bill_order_pdf.rb +++ b/app/pdf/receipt_bill_order_pdf.rb @@ -1,5 +1,5 @@ class ReceiptBillOrderPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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, :description_width, :price_num_width, :line_move @@ -27,11 +27,6 @@ class ReceiptBillOrderPdf < Prawn::Document #setting page margin and width super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - # db font setup if printer_settings.font != "" font_families.update("#{printer_settings.font}" => { @@ -47,19 +42,18 @@ class ReceiptBillOrderPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header(shop_details) - + if sale_data.orders[0].source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{sale_data.customer.contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end stroke_horizontal_rule cashier_info(sale_data, customer_name, latest_order_no,order_reservation) - line_items(sale_items,printer_settings.precision,delimiter,order_reservation) - all_total(sale_data,printer_settings.precision,delimiter,order_reservation) + line_items(sale_items,precision,delimiter,order_reservation) + all_total(sale_data,precision,delimiter,order_reservation) footer(printed_status) end @@ -78,13 +72,13 @@ class ReceiptBillOrderPdf < Prawn::Document def cashier_info(sale_data, customer_name, latest_order_no,order_reservation) move_down line_move - + # move_down 2 - + y_position = cursor bounding_box([0, y_position], :width =>self.label_width , :height => self.item_height) do text "Order Date " , :size => self.item_font_size, :align => :left - end + end bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do text "#{order_reservation.created_at.strftime('%d-%m-%Y %H:%M %p')}", :size => self.item_font_size,:align => :right end @@ -92,7 +86,7 @@ class ReceiptBillOrderPdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width , :height => self.item_height) do text "Requested Date Time " , :size => self.item_font_size, :align => :left - end + end bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do text "#{order_reservation.requested_time.strftime('%d-%m-%Y %H:%M %p')}", :size => self.item_font_size,:align => :right end @@ -100,7 +94,7 @@ class ReceiptBillOrderPdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width , :height => self.item_height) do text "Payment Type" , :size => self.item_font_size, :align => :left - end + end bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do text "#{order_reservation.payment_type}", :size => self.item_font_size,:align => :right end @@ -108,7 +102,7 @@ class ReceiptBillOrderPdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width , :height => self.item_height) do text "#{customer_name} " , :size => self.item_font_size, :align => :left - end + end bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do text "Online Order", :size => self.item_font_size,:align => :right end @@ -167,14 +161,14 @@ class ReceiptBillOrderPdf < Prawn::Document total_qty = 0.0 show_price = Lookup.find_by_lookup_type("show_price") sale_items.each do |item| - # check for item not to show + # check for item not to show if item.status != 'Discount' && item.qty > 0 if !show_price.nil? && show_price.value.to_i > 0 && item.price == 0 - total_qty += item.qty + total_qty += item.qty else if item.price != 0 - total_qty += item.qty + total_qty += item.qty end end end @@ -191,7 +185,7 @@ class ReceiptBillOrderPdf < Prawn::Document qty = item.qty total_price = item.price #item.qty*item.unit_price - comment for room charges price = item.unit_price - + # end if !show_price.nil? && show_price.value.to_i>0 item_row(item,precision,delimiter,product_name,price,qty ,total_price) @@ -209,8 +203,8 @@ class ReceiptBillOrderPdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_width + self.price_width, :height => self.item_height) do text "Sub Total", :size => self.item_font_size,:align => :left end - text_box "#{number_with_precision(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(order_reservation.total_amount, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(order_reservation.total_amount, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix if !order_reservation.delivery_type.nil? && order_reservation.delivery_fee.to_f > 0 y_position = cursor @@ -219,27 +213,31 @@ class ReceiptBillOrderPdf < Prawn::Document end bounding_box([self.description_width - 48,y_position], :width =>self.label_width, :height => self.item_height) do - text "#{number_with_precision(order_reservation.delivery_fee, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right - end + + text "#{number_format(order_reservation.delivery_fee, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + + end end if order_reservation.total_tax > 0 y_position = cursor bounding_box([0, y_position], :width =>self.item_description_width , :height => self.item_height) do text "Tax " , :size => self.item_font_size, :align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.label_width, :height => self.item_height) do - text "#{number_with_precision(order_reservation.total_tax, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right - end - end + + text "#{number_format(order_reservation.total_tax, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + + end + end y_position = cursor bounding_box([0, y_position], :width =>self.item_description_width , :height => self.item_height) do text "Convenience Charges " , :size => self.item_font_size, :align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.label_width, :height => self.item_height) do - text "#{number_with_precision(order_reservation.convenience_charge, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(order_reservation.convenience_charge, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end if order_reservation.discount_amount > 0 @@ -249,9 +247,11 @@ class ReceiptBillOrderPdf < Prawn::Document end bounding_box([self.item_description_width,y_position], :width =>self.label_width, :height => self.item_height) do - text "#{number_with_precision(order_reservation.discount_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right - end - end + + text "#{number_format(order_reservation.discount_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + + end + end end #Change items rows @@ -277,10 +277,12 @@ class ReceiptBillOrderPdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_width) do text "#{product_name}", :size => self.item_font_size,:align => :left end - # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size - text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size + + text_box "#{number_format(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + if show_alt_name if !(item.product_alt_name).empty? @@ -309,11 +311,13 @@ class ReceiptBillOrderPdf < Prawn::Document end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(order_reservation.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right - end + + text "#{number_format(order_reservation.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right + + end move_down line_move - # sale_payment(sale_data,precision,delimiter) + # sale_payment(sale_data,precision,delimiter) end #Change Footer @@ -326,10 +330,10 @@ class ReceiptBillOrderPdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width) do text "#{printed_status}",:style => :bold, :size => header_font_size - 1,:align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.item_description_width, :height => self.item_height) do text "Thank You! See you Again", :left_margin => -5, :size => self.item_font_size - 1,:align => :left - end + end move_down line_move end @@ -351,4 +355,4 @@ class ReceiptBillOrderPdf < Prawn::Document end return status end -end \ No newline at end of file +end diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 2a99e9f9..1bab0c30 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -1,11 +1,11 @@ # require 'prawn/qrcode' require 'prawn/measurement_extensions' class ReceiptBillPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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, :description_width, :price_num_width, :line_move - def initialize(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data,other_charges_amount,latest_order_no,card_balance_amount) + def initialize(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data,other_charges_amount,latest_order_no,card_balance_amount,transaction_ref) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height self.header_font_size = printer_settings.header_font_size.to_i @@ -29,11 +29,6 @@ class ReceiptBillPdf < Prawn::Document #setting page margin and width super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - # db font setup if printer_settings.font != "" font_families.update("#{printer_settings.font}" => { @@ -49,23 +44,22 @@ class ReceiptBillPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header(shop_details) - + if sale_data.orders[0].source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{sale_data.customer.contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end stroke_horizontal_rule cashier_info(sale_data, customer_name, latest_order_no) - line_items(sale_items,printer_settings.precision,delimiter) - all_total(sale_data,printer_settings.precision,delimiter) + line_items(sale_items,precision,delimiter) + all_total(sale_data,precision,delimiter) if member_info != nil - member_info(member_info,customer_name,rebate_amount,sale_data,printer_settings.precision,delimiter,current_balance) + member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance) end customer(customer_name) @@ -76,25 +70,26 @@ class ReceiptBillPdf < Prawn::Document end #end card sale trans data #start card blanace amount - if !card_balance_amount.nil? + if !card_balance_amount.nil? && card_balance_amount >0 card_balance_data(card_balance_amount) + card_transaction_ref(transaction_ref) end #end card blanace amount if discount_price_by_accounts.length > 0 && shop_details.show_account_info - discount_account(discount_price_by_accounts,printer_settings.precision,delimiter) + discount_account(discount_price_by_accounts,precision,delimiter) end if shop_details.show_account_info - items_account(item_price_by_accounts,printer_settings.precision,delimiter) + items_account(item_price_by_accounts,precision,delimiter) if other_charges_amount - show_other_charges_amount(other_charges_amount,printer_settings.precision,delimiter) + show_other_charges_amount(other_charges_amount,precision,delimiter) end end #start for individual payment if !sale_data.equal_persons.nil? - individual_payment(sale_data,sale_data.equal_persons, printer_settings.precision, delimiter) + individual_payment(sale_data,sale_data.equal_persons, precision, delimiter) end #end for individual payment @@ -273,8 +268,8 @@ class ReceiptBillPdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_width + self.price_width, :height => self.item_height) do text "Sub Total", :size => self.item_font_size,:align => :left end - text_box "#{number_with_precision(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(@sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(@sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix end def item_row(item,precision,delimiter,product_name,price,qty ,total_price) @@ -298,9 +293,9 @@ class ReceiptBillPdf < Prawn::Document text "#{product_name}", :size => self.item_font_size,:align => :left end # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size - text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix if show_alt_name if !(item.product_alt_name).empty? @@ -330,7 +325,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ dis_type }", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "( #{number_with_precision(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right + text "( #{number_format(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right end service_tax_desc = "" @@ -355,14 +350,14 @@ class ReceiptBillPdf < Prawn::Document sale_data.sale_taxes.each do |st| if (st.tax_name.include? "Service") service_tax_desc = st.tax_name - service_tax_amount = number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter) + service_tax_amount = st.tax_payable_amount if incl_tax service_tax_rate = st.tax_rate.to_i end end if (st.tax_name.include? "Commercial") com_tax_desc = st.tax_name - com_tax_amount = number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter) + com_tax_amount = st.tax_payable_amount if incl_tax com_tax_rate = st.tax_rate.to_i end @@ -374,7 +369,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ service_tax_desc } (#{incl_tax} #{ service_tax_rate }%)", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(service_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(service_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move y_position = cursor @@ -391,7 +386,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ com_tax_desc } (#{incl_tax} #{ com_tax_rate.to_i }%)", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(com_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(com_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end else sale_data.sale_taxes.each do |st| @@ -402,7 +397,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end end @@ -439,7 +434,7 @@ class ReceiptBillPdf < Prawn::Document text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right + text "#{number_format(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right end move_down line_move @@ -474,13 +469,17 @@ class ReceiptBillPdf < Prawn::Document text "Redeem Payment", :size => self.item_font_size,:align => :left end else + payment_method = payment.payment_method.capitalize + if payment.payment_method == "paymal" + payment_method ='Card' + end bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left + text "#{payment_method} Payment", :size => self.item_font_size,:align => :left end end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -491,7 +490,7 @@ class ReceiptBillPdf < Prawn::Document text "Change Amount", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end # move_down line_move end @@ -526,7 +525,7 @@ class ReceiptBillPdf < Prawn::Document text "Rebate Earn", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end @@ -539,7 +538,7 @@ class ReceiptBillPdf < Prawn::Document text "Rebate Earn Bonus", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end #end Total rebate if birthday @@ -551,7 +550,7 @@ class ReceiptBillPdf < Prawn::Document text "Redeem Amount", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end if current_balance != nil @@ -561,7 +560,7 @@ class ReceiptBillPdf < Prawn::Document text "Old Balance", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end @@ -583,7 +582,7 @@ class ReceiptBillPdf < Prawn::Document text "Total Balance", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end @@ -615,7 +614,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ 'Total ' + ipa[:name] + ' Discounts' }", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "(" + "#{ number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right + text "(" + "#{ number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -631,7 +630,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - text "#{number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -643,7 +642,7 @@ class ReceiptBillPdf < Prawn::Document text "Other Charges", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - text "#{number_with_precision(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -666,7 +665,7 @@ class ReceiptBillPdf < Prawn::Document bounding_box([self.label_width,y_position], :width =>self.item_description_width) do move_down 15 - text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end @@ -797,7 +796,6 @@ class ReceiptBillPdf < Prawn::Document #start card balance data def card_balance_data(card_balance_amount) - if card_balance_amount > 0 move_down line_move stroke_horizontal_rule move_down line_move @@ -809,6 +807,19 @@ class ReceiptBillPdf < Prawn::Document bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{card_balance_amount}" , :size => self.item_font_size,:align => :right end + end + #start card transaction_ref + def card_transaction_ref(transaction_ref) + move_down line_move + stroke_horizontal_rule + move_down line_move + + y_position = cursor + bounding_box([0, y_position], :width =>self.label_width) do + text "Transaction ref: ",:style => :bold, :size => header_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{transaction_ref}" , :size => self.item_font_size,:align => :right end end diff --git a/app/pdf/receipt_bill_star_pdf.rb b/app/pdf/receipt_bill_star_pdf.rb index 0b1f8ce2..1cdb9aac 100644 --- a/app/pdf/receipt_bill_star_pdf.rb +++ b/app/pdf/receipt_bill_star_pdf.rb @@ -1,9 +1,9 @@ class ReceiptBillStarPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :margin_top, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width, :line_move - def initialize(printer_settings, status, qr , sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data,other_charges_amount,latest_order_no,card_balance_amount) + def initialize(printer_settings, status, qr , sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data,other_charges_amount,latest_order_no,card_balance_amount,transaction_ref) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height self.header_font_size = printer_settings.header_font_size.to_i @@ -28,11 +28,6 @@ class ReceiptBillStarPdf < Prawn::Document #setting page margin and width super(:margin => [self.margin_top, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - # db font setup if printer_settings.font != "" font_families.update("#{printer_settings.font}" => { @@ -48,23 +43,22 @@ class ReceiptBillStarPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header(shop_details) - + if sale_data.orders[0].source =='app' + text "Mobile Order", :size => self.header_font_size,:align => :left + move_down 1 + text "Customer Ph : #{sale_data.customer.contact_no}", :size => self.header_font_size,:align => :left + move_down 1 + end stroke_horizontal_rule cashier_info(sale_data, customer_name, latest_order_no) - line_items(sale_items,printer_settings.precision,delimiter) - all_total(sale_data,printer_settings.precision,delimiter) + line_items(sale_items,precision,delimiter) + all_total(sale_data,precision,delimiter) if member_info != nil - member_info(member_info,customer_name,rebate_amount,sale_data,printer_settings.precision,delimiter,current_balance) + member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance) end customer(customer_name) @@ -75,25 +69,26 @@ class ReceiptBillStarPdf < Prawn::Document end #end card sale trans data #start card blanace amount - if !card_balance_amount.nil? + if !card_balance_amount.nil? && card_balance_amount >0 card_balance_data(card_balance_amount) + card_transaction_ref(transaction_ref) end #end card blanace amount if discount_price_by_accounts.length > 0 && shop_details.show_account_info - discount_account(discount_price_by_accounts,printer_settings.precision,delimiter) + discount_account(discount_price_by_accounts,precision,delimiter) end if shop_details.show_account_info - items_account(item_price_by_accounts,printer_settings.precision,delimiter) + items_account(item_price_by_accounts,precision,delimiter) if other_charges_amount - show_other_charges_amount(other_charges_amount,printer_settings.precision,delimiter) + show_other_charges_amount(other_charges_amount,precision,delimiter) end end #start for individual payment if !sale_data.equal_persons.nil? - individual_payment(sale_data,sale_data.equal_persons, printer_settings.precision, delimiter) + individual_payment(sale_data,sale_data.equal_persons, precision, delimiter) end #end for individual payment @@ -268,8 +263,8 @@ class ReceiptBillStarPdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_width + self.price_width, :height => self.item_height) do text "Sub Total", :size => self.item_font_size,:align => :left end - text_box "#{number_with_precision(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix end def item_row(item,precision,delimiter,product_name,price,qty ,total_price) @@ -293,9 +288,9 @@ class ReceiptBillStarPdf < Prawn::Document text "#{product_name}", :size => self.item_font_size,:align => :left end # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size - text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix if show_alt_name if !(item.product_alt_name).empty? @@ -325,7 +320,7 @@ class ReceiptBillStarPdf < Prawn::Document text "#{ dis_type }", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "( #{number_with_precision(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right + text "( #{number_format(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right end if sale_data.sale_taxes.length > 0 @@ -342,7 +337,7 @@ class ReceiptBillStarPdf < Prawn::Document text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end else @@ -378,7 +373,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right + text "#{number_format(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right end move_down line_move @@ -413,13 +408,17 @@ class ReceiptBillStarPdf < Prawn::Document text "Redeem Payment", :size => self.item_font_size,:align => :left end else + payment_method = payment.payment_method.capitalize + if payment.payment_method == "paymal" + payment_method ='Card' + end bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left + text "#{payment_method} Payment", :size => self.item_font_size,:align => :left end end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -430,7 +429,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Change Amount", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end # move_down line_move end @@ -465,7 +464,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Rebate Earn", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end @@ -478,7 +477,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Rebate Earn Bonus", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end #end Total rebate if birthday @@ -490,7 +489,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Redeem Amount", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end if current_balance != nil @@ -500,7 +499,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Old Balance", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end @@ -522,7 +521,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Total Balance", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end @@ -554,7 +553,7 @@ class ReceiptBillStarPdf < Prawn::Document text "#{ 'Total ' + ipa[:name] + ' Discounts' }", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "(" + "#{ number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right + text "(" + "#{ number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -570,7 +569,7 @@ class ReceiptBillStarPdf < Prawn::Document text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - text "#{number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -582,7 +581,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Other Charges", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - text "#{number_with_precision(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -605,7 +604,7 @@ class ReceiptBillStarPdf < Prawn::Document bounding_box([self.label_width,y_position], :width =>self.item_description_width) do move_down 15 - text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end @@ -722,19 +721,32 @@ class ReceiptBillStarPdf < Prawn::Document #start card balance data def card_balance_data(card_balance_amount) - if card_balance_amount > 0 - move_down line_move - stroke_horizontal_rule - move_down line_move + move_down line_move + stroke_horizontal_rule + move_down line_move - y_position = cursor - bounding_box([0, y_position], :width =>self.label_width) do - text "Card Balance: ",:style => :bold, :size => header_font_size,:align => :left - end - bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{card_balance_amount}" , :size => self.item_font_size,:align => :right - end - end + y_position = cursor + bounding_box([0, y_position], :width =>self.label_width) do + text "Card Balance: ",:style => :bold, :size => header_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{card_balance_amount}" , :size => self.item_font_size,:align => :right + end + end + + #start card balance data + def card_transaction_ref(transaction_ref) + move_down line_move + stroke_horizontal_rule + move_down line_move + + y_position = cursor + bounding_box([0, y_position], :width =>self.label_width) do + text "Transaction ref: ",:style => :bold, :size => header_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{transaction_ref}" , :size => self.item_font_size,:align => :right + end end #check ReceiptBillAltName included diff --git a/app/pdf/sale_items_pdf.rb b/app/pdf/sale_items_pdf.rb index 657b7fe1..af76c427 100644 --- a/app/pdf/sale_items_pdf.rb +++ b/app/pdf/sale_items_pdf.rb @@ -1,5 +1,5 @@ class SaleItemsPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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,:text_width def initialize(printer_settings, shop_details, period, type, account, from_date, to_date, shift, sale_items, total_other_charges) @@ -41,17 +41,6 @@ class SaleItemsPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - #check delimiter - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header( shop_details) stroke_horizontal_rule diff --git a/app/pdf/sale_items_star_pdf.rb b/app/pdf/sale_items_star_pdf.rb index 6860b341..a1181e13 100644 --- a/app/pdf/sale_items_star_pdf.rb +++ b/app/pdf/sale_items_star_pdf.rb @@ -1,5 +1,5 @@ class SaleItemsStarPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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,:text_width def initialize(printer_settings, shop_details, period, type, account, from_date, to_date, shift, sale_items, total_other_charges) @@ -41,17 +41,6 @@ class SaleItemsStarPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - #check delimiter - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header( shop_details) stroke_horizontal_rule diff --git a/app/uploaders/commissioner_image_uploader.rb b/app/uploaders/commissioner_image_uploader.rb index 9b65e4a8..42e90a16 100644 --- a/app/uploaders/commissioner_image_uploader.rb +++ b/app/uploaders/commissioner_image_uploader.rb @@ -20,11 +20,11 @@ class CommissionerImageUploader < CarrierWave::Uploader::Base end def filename - if Shop.first.shop_code.nil? - "#{original_filename}" if original_filename.present? + if Shop.current_shop.shop_code.nil? + "#{original_filename}" if original_filename.present? else - "#{Shop.first.shop_code}_#{original_filename}" if original_filename.present? - end + "#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present? + end end # def cache_dir @@ -62,6 +62,6 @@ class CommissionerImageUploader < CarrierWave::Uploader::Base # Avoid using model.id or version_name here, see uploader/store.rb for details. # def filename # "something.jpg" if original_filename - # end + # end -end \ No newline at end of file +end diff --git a/app/uploaders/customer_image_uploader.rb b/app/uploaders/customer_image_uploader.rb index be1326d6..77a133af 100644 --- a/app/uploaders/customer_image_uploader.rb +++ b/app/uploaders/customer_image_uploader.rb @@ -20,11 +20,11 @@ class CustomerImageUploader < CarrierWave::Uploader::Base end def filename - if Shop.first.shop_code.nil? - "#{original_filename}" if original_filename.present? + if Shop.current_shop.shop_code.nil? + "#{original_filename}" if original_filename.present? else - "#{Shop.first.shop_code}_#{original_filename}" if original_filename.present? - end + "#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present? + end end # def cache_dir @@ -62,6 +62,6 @@ class CustomerImageUploader < CarrierWave::Uploader::Base # Avoid using model.id or version_name here, see uploader/store.rb for details. # def filename # "something.jpg" if original_filename - # end + # end -end \ No newline at end of file +end diff --git a/app/uploaders/employee_image_uploader.rb b/app/uploaders/employee_image_uploader.rb index 17c9d120..eed8c04f 100644 --- a/app/uploaders/employee_image_uploader.rb +++ b/app/uploaders/employee_image_uploader.rb @@ -20,11 +20,11 @@ class EmployeeImageUploader < CarrierWave::Uploader::Base end def filename - if Shop.first.shop_code.nil? - "#{original_filename}" if original_filename.present? - else - "#{Shop.first.shop_code}_#{original_filename}" if original_filename.present? - end + # if Shop.current_shop.shop_code.nil? + "#{original_filename}" if original_filename.present? + # else + "#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present? + # end end # def cache_dir @@ -62,6 +62,6 @@ class EmployeeImageUploader < CarrierWave::Uploader::Base # Avoid using model.id or version_name here, see uploader/store.rb for details. # def filename # "something.jpg" if original_filename - # end + # end -end \ No newline at end of file +end diff --git a/app/uploaders/menu_item_image_uploader.rb b/app/uploaders/menu_item_image_uploader.rb index 7a4b2039..5f23cafc 100755 --- a/app/uploaders/menu_item_image_uploader.rb +++ b/app/uploaders/menu_item_image_uploader.rb @@ -15,16 +15,16 @@ class MenuItemImageUploader < CarrierWave::Uploader::Base # Override the directory where uploaded files will be stored. # This is a sensible default for uploaders that are meant to be mounted: def store_dir - "image/menu_images/#{Shop.first.shop_code}" + "image/menu_images/#{Shop.current_shop.shop_code}" # "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end def filename - if Shop.first.shop_code.nil? - "#{original_filename}" if original_filename.present? + if Shop.current_shop.shop_code.nil? + "#{original_filename}" if original_filename.present? else - "#{Shop.first.shop_code}_#{original_filename}" if original_filename.present? - end + "#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present? + end end # def cache_dir @@ -42,7 +42,7 @@ class MenuItemImageUploader < CarrierWave::Uploader::Base # Process files as they are uploaded: # process scale: [200, 300] process :resize_to_fit => [400, 250]#[200, 150] - + # # def scale(width, height) # # do something diff --git a/app/uploaders/product_image_uploader.rb b/app/uploaders/product_image_uploader.rb index c39d867d..35fde675 100755 --- a/app/uploaders/product_image_uploader.rb +++ b/app/uploaders/product_image_uploader.rb @@ -20,11 +20,11 @@ class ProductImageUploader < CarrierWave::Uploader::Base end def filename - if Shop.first.shop_code.nil? - "#{original_filename}" if original_filename.present? + if Shop.current_shop.shop_code.nil? + "#{original_filename}" if original_filename.present? else - "#{Shop.first.shop_code}_#{original_filename}" if original_filename.present? - end + "#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present? + end end # def cache_dir diff --git a/app/uploaders/shop_image_uploader.rb b/app/uploaders/shop_image_uploader.rb index 394704c3..c27fb65c 100644 --- a/app/uploaders/shop_image_uploader.rb +++ b/app/uploaders/shop_image_uploader.rb @@ -20,11 +20,11 @@ class ShopImageUploader < CarrierWave::Uploader::Base end def filename - if Shop.first.shop_code.nil? - "#{original_filename}" if original_filename.present? + if Shop.current_shop.shop_code.nil? + "#{original_filename}" if original_filename.present? else - "#{Shop.first.shop_code}_#{original_filename}" if original_filename.present? - end + "#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present? + end end # def cache_dir @@ -62,6 +62,6 @@ class ShopImageUploader < CarrierWave::Uploader::Base # Avoid using model.id or version_name here, see uploader/store.rb for details. # def filename # "something.jpg" if original_filename - # end + # end -end \ No newline at end of file +end diff --git a/app/views/api/orders/create.json.jbuilder b/app/views/api/orders/create.json.jbuilder index 6c5a6fe9..28a7f764 100755 --- a/app/views/api/orders/create.json.jbuilder +++ b/app/views/api/orders/create.json.jbuilder @@ -5,11 +5,12 @@ if @status == true json.order_items do json.array! @order.order_items, :item_code, :item_name, :qty, :options, :remark,:price end + json.sale_id @sale.sale_id else json.status :error if @error_messages json.error_messages @error_messages else - json.error_messages @order.errors + json.error_messages @message end end diff --git a/app/views/api/orders/view_orders.json.jbuilder b/app/views/api/orders/view_orders.json.jbuilder index ce8eac1d..4a396050 100755 --- a/app/views/api/orders/view_orders.json.jbuilder +++ b/app/views/api/orders/view_orders.json.jbuilder @@ -20,7 +20,7 @@ if (@booking) @total_tax = 0.00 # For YGN BBQ - adult_count = 0 + adult_count = 0 child_count = 0 adult_spent = 0 child_spent = 0 @@ -33,18 +33,18 @@ if (@booking) if (order.status == "new") order_items = order_items + order.order_items end - end + end json.order_items order_items do |item| total_set_menu = 0 # For YGN BBQ if item.item_code.include? ("PSA_") - adult_count += item.qty - adult_spent += (item.price * item.qty) + adult_count += item.qty + adult_spent += (item.price * item.qty) end if item.item_code.include? ("PSC_") child_count += item.qty - child_spent += (item.price * item.qty) + child_spent += (item.price * item.qty) end # End YGN BBQ @@ -115,7 +115,7 @@ if (@booking) end @total_tax_amount = @service_charges + @commercial_tax end - + #total tax calculation json.sub_total @total_amount if @service_rate.to_i > 0 diff --git a/app/views/api/payment/mobilepayment/cash.json.jbuilder b/app/views/api/payments/mobilepayment/cash.json.jbuilder similarity index 100% rename from app/views/api/payment/mobilepayment/cash.json.jbuilder rename to app/views/api/payments/mobilepayment/cash.json.jbuilder diff --git a/app/views/api/payments/paymal_payment.json.jbuilder b/app/views/api/payments/paymal_payment.json.jbuilder new file mode 100644 index 00000000..e69de29b diff --git a/app/views/api/verifications/new.json.jbuilder b/app/views/api/verifications/new.json.jbuilder index c187f79b..d642e169 100644 --- a/app/views/api/verifications/new.json.jbuilder +++ b/app/views/api/verifications/new.json.jbuilder @@ -1,7 +1,11 @@ -if @result && @cus +if @result json.status true json.sent_pin true + elsif @cus + json.status true + json.sent_pin false + json.customer_id @cus.id else json.status false - json.message "Customer Not Found" + json.message "Phone number invalid" end diff --git a/app/views/foodcourt/addorders/_menu_item.json.jbuilder b/app/views/foodcourt/addorders/_menu_item.json.jbuilder new file mode 100755 index 00000000..2768fa9c --- /dev/null +++ b/app/views/foodcourt/addorders/_menu_item.json.jbuilder @@ -0,0 +1,81 @@ +# Format for attributes json +attr_format = [] +# Format for attributes json +if item.item_attributes.count > 0 + item_attributes = MenuItemAttribute.where(id: item.item_attributes) + attr_format = item_attributes.group_by {|att| att.attribute_type }.map { |type, values| {type: type, values: values.map(&:name)} } +end + +# Format for option json +opt_format = [] +# Format for attributes json +if item.item_options.count > 0 + item_options = MenuItemOption.where(id: item.item_options) + opt_format = item_options.group_by {|opt| opt.option_type }.map { |type, values| {type: type, values: values.map(&:name)} } +end + + +#Menu Item Information +json.id item.id +json.code item.item_code +json.name item.name +json.alt_name item.alt_name +json.image item.image_path.url +json.description item.description +json.information item.information +json.type item.type +json.account_id item.account_id +json.min_qty item.min_qty +json.is_available item.is_available +json.is_sub_item item.is_sub_item +json.unit item.unit + +# Item Sets of Menu Item +json.item_sets item.item_sets.includes(:menu_item_instances) do |its| + json.id its.id + json.name its.name + json.alt_name its.alt_name + json.min_selectable_qty its.min_selectable_qty + json.max_selectable_qty its.max_selectable_qty + json.instances its.menu_item_instances do |i| + json.id i.id + end +end + +json.attributes attr_format +json.options opt_format +# json.min_selectable_item item.min_selectable_item +# json.max_selectable_item item.max_selectable_item + +#Item instance +# if item.menu_item_instances.count == 1 then +# item_instance = item.menu_item_instances[0] +# json.price = item_instance.price +# json.is_available = item_instance.is_available +# json.is_on_promotion = item_instance.is_on_promotion +# json.promotion_price = item_instance.promotion_price +# json.item_attributes = item_instance.item_attributes + +json.instances item.menu_item_instances do |is| + if is.is_available + # Convert id to name for attributes + instance_attr = MenuItemAttribute.where(id: item.item_attributes).pluck(:name) + + json.id is.id + json.code is.item_instance_code + json.name is.item_instance_name + json.price is.price + json.is_available is.is_available + json.is_default is.is_default + json.is_on_promotion is.is_on_promotion + json.promotion_price is.promotion_price + json.values instance_attr + end +end + +#Child Menu items +# if (item.children) then +# json.set_items item.children.each do |item| +# json.partial! 'api/restaurant/menu/menu_item', item: item +# end +# end diff --git a/app/views/foodcourt/addorders/create.json.jbuilder b/app/views/foodcourt/addorders/create.json.jbuilder new file mode 100755 index 00000000..175e6e94 --- /dev/null +++ b/app/views/foodcourt/addorders/create.json.jbuilder @@ -0,0 +1,15 @@ +if @status == true + json.status :success + json.id @order.id + json.booking_id @booking.id + json.order_items do + json.array! @order.order_items, :item_code, :item_name, :qty, :options, :remark + end +else + json.status :error + if @error_messages + json.error_messages @error_messages + else + json.error_messages @order.errors + end +end diff --git a/app/views/foodcourt/addorders/detail.html.erb b/app/views/foodcourt/addorders/detail.html.erb new file mode 100644 index 00000000..adeec6b4 --- /dev/null +++ b/app/views/foodcourt/addorders/detail.html.erb @@ -0,0 +1,804 @@ +<%= stylesheet_link_tag 'addorder', media: 'all', 'data-turbolinks-track': 'reload' %> +<%= javascript_include_tag 'addorder', 'data-turbolinks-track': 'reload' %> +<% type = request.path_info.include?('quick_service') || request.path_info.include?('food_court')%> +<% modify_order = request.path_info.include?('modify_order')%> +
+ + + + + +
+ + + + + + +
+
+
+
+ +
+
+
+
+
+ +
+
+ <% if type %> +
+
+ ORDER DETAILS +
+ + <% if modify_order %> + <% if @table.nil? %> + +
Table :
+ + + + <% else%> + +
Table : <%=@table.name%>
+ + + + <% end%> + + + + + +
+ +
+ <% else%> + +
+ +
+
+ +
+ <% end%> +
+ <% else %> +
+
+ ORDER DETAILS | Table-<%=@table.name%> + + + + + + + +
+
+ +
+ <% end%> + +
+
+
+ + + + + + + + + + + + +
#ItemsQTYPrice
+
+ +
+
+ + + + + + + + + + + + <% if type && !modify_order%> + + <% end %> + " id="server_mode"> +
+ + + diff --git a/app/views/foodcourt/addorders/get_all_product.json.jbuilder b/app/views/foodcourt/addorders/get_all_product.json.jbuilder new file mode 100755 index 00000000..01921c59 --- /dev/null +++ b/app/views/foodcourt/addorders/get_all_product.json.jbuilder @@ -0,0 +1,4 @@ + +json.array! @product, :id, :item_code, :name, :alt_name,:image_path, + :description,:information,:taxable,:unit_price, :created_at, + :updated_at, :created_by \ No newline at end of file diff --git a/app/views/foodcourt/addorders/get_item_instance.json.jbuilder b/app/views/foodcourt/addorders/get_item_instance.json.jbuilder new file mode 100644 index 00000000..c95f782d --- /dev/null +++ b/app/views/foodcourt/addorders/get_item_instance.json.jbuilder @@ -0,0 +1,39 @@ +if(@instance) + menu_item = MenuItem.find(@instance.menu_item_id) + # Format for option json + opt_format = [] + # Format for attributes json + menu_item.item_options.each do|opt| + menu_opt = MenuItemOption.find(opt) + if opt_format.count == 0 + opt_format.push({ type: menu_opt.option_type, values: [menu_opt.name] }) + next + end + + opt_format.each do |of| + if menu_opt.option_type.in? opt_format.map {|k| k[:type]} + if menu_opt.option_type == of[:type] + of[:values].push(menu_opt.name) + end + else + new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] } + opt_format.push(new_opt) + break + end + end + end + + json.success true + json.id @instance.id + json.name @instance.item_instance_name + json.code @instance.item_instance_code + + json.item_id @instance.menu_item_id + json.attributes @instance.item_attributes + json.price @instance.price + json.is_default @instance.is_default + + json.options opt_format +else + json.success false +end diff --git a/app/views/foodcourt/addorders/get_menu.json.jbuilder b/app/views/foodcourt/addorders/get_menu.json.jbuilder new file mode 100644 index 00000000..bbe18fff --- /dev/null +++ b/app/views/foodcourt/addorders/get_menu.json.jbuilder @@ -0,0 +1 @@ +json.array! @menu_category \ No newline at end of file diff --git a/app/views/foodcourt/addorders/get_menu_category.json.jbuilder b/app/views/foodcourt/addorders/get_menu_category.json.jbuilder new file mode 100755 index 00000000..d5822d3d --- /dev/null +++ b/app/views/foodcourt/addorders/get_menu_category.json.jbuilder @@ -0,0 +1,8 @@ +if @menu.menu_items + json.menu_items @menu.menu_items do |item| + if item.is_available + json.partial! 'foodcourt/addorders/menu_item', item: item + end + + end +end diff --git a/app/views/foodcourt/addorders/get_menu_sub_category.json.jbuilder b/app/views/foodcourt/addorders/get_menu_sub_category.json.jbuilder new file mode 100644 index 00000000..d391e4c5 --- /dev/null +++ b/app/views/foodcourt/addorders/get_menu_sub_category.json.jbuilder @@ -0,0 +1,9 @@ +if @sub_menu + json.sub_category @sub_menu.each do |sub_cat| + json.id sub_cat.id + json.code sub_cat.code + json.name sub_cat.name + json.menu_id sub_cat.menu_id + json.menu_category_id sub_cat.menu_category_id + end +end diff --git a/app/views/foodcourt/cash_ins/new.html.erb b/app/views/foodcourt/cash_ins/new.html.erb new file mode 100755 index 00000000..7bc17066 --- /dev/null +++ b/app/views/foodcourt/cash_ins/new.html.erb @@ -0,0 +1,101 @@ +
+
+
+

<%= t :cash_in %>

+
+ + + + + + + + + + + + + + + + + + + + + +
<%= t :payment_reference %> + + +
<%= t("views.right_panel.detail.remark") %> + + +
<%= t :payment_method %> + + + + + +
<%= t :reference_number %> + + +
<%= t("views.right_panel.detail.amount") %> + + +
+
+
+
+
+ + +
+ +
+
+
+ + diff --git a/app/views/foodcourt/cash_mgmt/create.html.erb b/app/views/foodcourt/cash_mgmt/create.html.erb new file mode 100755 index 00000000..1b4805a2 --- /dev/null +++ b/app/views/foodcourt/cash_mgmt/create.html.erb @@ -0,0 +1,2 @@ +

CashMgmt#create

+

Find me in app/views/cash_mgmt/create.html.erb

diff --git a/app/views/foodcourt/cash_mgmt/index.html.erb b/app/views/foodcourt/cash_mgmt/index.html.erb new file mode 100755 index 00000000..88195969 --- /dev/null +++ b/app/views/foodcourt/cash_mgmt/index.html.erb @@ -0,0 +1,2 @@ +

CashMgmt#index

+

Find me in app/views/cash_mgmt/index.html.erb

\ No newline at end of file diff --git a/app/views/foodcourt/cash_mgmt/new.html.erb b/app/views/foodcourt/cash_mgmt/new.html.erb new file mode 100755 index 00000000..b06a8d2d --- /dev/null +++ b/app/views/foodcourt/cash_mgmt/new.html.erb @@ -0,0 +1,3 @@ +

CashMgmt#new

+

Find me in app/views/cash_mgmt/new.html.erb

+ diff --git a/app/views/foodcourt/cash_outs/new.html.erb b/app/views/foodcourt/cash_outs/new.html.erb new file mode 100755 index 00000000..14a9ec97 --- /dev/null +++ b/app/views/foodcourt/cash_outs/new.html.erb @@ -0,0 +1,53 @@ +
+
+
+

<%= t :cash_out %>

+ + + + + + + + + + + + + +
<%= t :payment_reference %>
<%= t("views.right_panel.detail.remark") %>
<%= t("views.right_panel.detail.amount") %>
+
+
+

+ + +
+
+
+ diff --git a/app/views/foodcourt/customers/index.html.erb b/app/views/foodcourt/customers/index.html.erb new file mode 100644 index 00000000..82d72d07 --- /dev/null +++ b/app/views/foodcourt/customers/index.html.erb @@ -0,0 +1,715 @@ + +
+
+
+
+
+
+ <% path ="/foodcourt/#{@sale_id}/#{@cashier_type}/customers/#{@page}" %> + <%= form_tag path, :id => "filter_form", :method => :get do %> +
+
+ + + +
+ + + + + + + + +
+ <% end %> +
+
+ +
+
+
+
+ <%= paginate @crm_customers %> +
+
+ + + + + + + + + + + + + + + + + <% if @crm_customers.count > 0 %> + <% @i = 0 %> + <% @crm_customers.each do |crm_customer| %> + + + + + + + + + + + + + + <% end %> + <%else%> + + <% end %> + +
<%= t("views.right_panel.detail.sr_no") %><%= t :customer %> <%= t("views.right_panel.detail.type") %><%= t("views.right_panel.detail.name") %><%= t("views.right_panel.detail.card_no") %><%= t("views.right_panel.detail.membership_type") %><%= t("views.right_panel.detail.contact_no") %><%= t("views.right_panel.detail.email") %>
+ + <% if crm_customer.customer_id != "CUS-000000000001" && crm_customer.customer_id != "CUS-000000000002" %> + <%= @i += 1 %> + <%else%> + - + <% end %> + <%= crm_customer.customer_type rescue '-' %><%= crm_customer.name %><%= crm_customer.card_no rescue '-' %> + <% if !@membership_types.nil? %> + <% @membership_types.each do |member_type| %> + <% if member_type[1] == crm_customer.membership_type %> + <%= member_type[0] %> + <% end %> + <% end %> + <% end %> + <%= crm_customer.contact_no %><%= crm_customer.email %>

There are no record for your search

+
+
+
+
+ + + + <%if !@dining_facility.nil?%> + + + + <% elsif @cashier_type == 'quick_service' || @cashier_type == "food_court" %> + + + + <%else%> + + + + <%end%> + +
+
+
+
+ +
+ <%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %> + + <%= f.error_notification %> + <%= f.hidden_field :id, :class => "form-control col-md-6 " %> +
+
+
+
+ +
+ +
+
+
+
+
+
+   +   +   + +
+
+
"> +
+ <%= f.input :name, :class => "form-control name", :required => true %> + + <% flash.each do |name, msg| %> + <% str="[\"#{msg['name']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> + <% end -%> +
+
+
"> +
+ <%= f.input :contact_no, :class => "form-control contact_no" ,:required => true%> + + <% flash.each do |name, msg| %> + <% str="[\"#{msg['contact_no']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> + <% end %> +
+
+ +
"> +
+ <%= f.input :email, :class => "form-control email" ,:required => true%> + + <% flash.each do |name, msg| %> + <% str="[\"#{msg['email']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> + <% end %> +
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+ + <%= f.file_field :image_path, :class => "img-thumbnail" %> +
+
+
+
+
+
+ + +
+
+
+
+ <%= f.input :nrc_no,:label => "NRC No", :class => "form-control nrc_no" %> +
+
+
+
+ <%= f.input :company, :class => "form-control col-md-6 company"%> + + <% flash.each do |name, msg| %> + <% str="[\"#{msg['company']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> + <% end -%> +
+
+
+
+ + <%= f.text_field :date_of_birth, :value=>"01-01-1990",:class=>"datepicker form-control col-md-12"%> +
+
+
+
+ <%= f.input :address, :class => "form-control address" %> +
+
+
+
+ + +
+
+ +
+
+ <%= f.input :tax_profiles, :collection => @taxes, :input_html => { :multiple => true }, :class => "form-control tax_profiles" %> +
+
+ +
"> +
+ <%= f.input :card_no, :class => "form-control card_no"%> + <% flash.each do |name, msg| %> + <% str="[\"#{msg['card_no']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> + <% end %> +
+
+ +
+
+ +
+ +
+
+
+
+ +
+
+ + +
+
+
+
+ + <%= f.submit t("views.btn.submit"),:class => 'btn bg-blue btn-md waves-effect', :id => 'submit_customer' %> + +
+
+
+
+ <% end %> +
+
+
+
+
+
+
+
+ +
+

Card Tap

+
+ +
+
+
+ diff --git a/app/views/foodcourt/dashboard/_menu.json.jbuilder b/app/views/foodcourt/dashboard/_menu.json.jbuilder new file mode 100644 index 00000000..9c9f1963 --- /dev/null +++ b/app/views/foodcourt/dashboard/_menu.json.jbuilder @@ -0,0 +1,112 @@ +json.id menu.id +json.name menu.name +json.is_ordering menu.is_ordering +json.is_active menu.is_active +json.valid_time_from menu.valid_time_from.strftime("%H:%M") +json.valid_time_to menu.valid_time_to.strftime("%H:%M") + +if (menu.menu_categories) + order_by = Lookup.find_by_lookup_type("order_by") + # if !order_by.nil? && order_by.value == "name" + # categories = MenuCategory.unscoped.where("menu_id ='#{menu.id}'").order("name asc") + # else + # categories = menu.menu_categories + # end + categories = menu.menu_categories + json.categories categories do |category| + if category.is_available + parent_category = category.parent + if !parent_category.nil? + json.sub_category "true" + else + json.sub_category "false" + end + valid_time = category.valid_time + json.valid_time valid_time + + json.id category.id + json.code category.code + json.order_by category.order_by + json.name category.name + json.alt_name category.alt_name + json.order_by category.order_by + json.parent_id category.menu_category_id + json.is_available category.is_available + + if !order_by.nil? && order_by.value == "name" + menu_items = category.menu_items.sort_by(&:name) + else + menu_items = category.menu_items + end + + if category.menu_items + json.items menu_items do |item| + if item.is_available + # Format for attributes json + attr_format = [] + # Format for attributes json + if item.item_attributes.count > 0 + item_attributes = @item_attributes.select{ |x| item.item_attributes.include?(x.id.to_s) } + attr_format = item_attributes.group_by {|att| att.attribute_type }.map { |type, values| {type: type, values: values.map(&:name)} } + end + + # Format for option json + opt_format = [] + # Format for attributes json + if item.item_options.count > 0 + item_options = @item_options.select{ |x| item.item_options.include?(x.id.to_s) } + opt_format = item_options.group_by {|opt| opt.option_type }.map { |type, values| {type: type, values: values.map(&:name)} } + end + + #Menu Item Information + json.id item.id + json.code item.item_code + json.name item.name + json.alt_name item.alt_name + json.image item.image_path.url + json.description item.description + json.information item.information + json.type item.type + json.account_id item.account_id + json.min_qty item.min_qty + json.is_available item.is_available + json.is_sub_item item.is_sub_item + json.unit item.unit + + # Item Sets of Menu Item + json.item_sets item.item_sets.map { |its| + { id: its.id, + name: its.name, + alt_name: its.alt_name, + min_selectable_qty: its.min_selectable_qty, + max_selectable_qty: its.max_selectable_qty, + instances: its.menu_item_instances.pluck(:id).map { |id| {id: id}} + } + } + + json.attributes attr_format + json.options opt_format + + json.instances item.menu_item_instances do |is| + if is.is_available + # Convert id to name for attributes + instance_attr = @item_attributes.select{ |x| item.item_attributes.include?(x.id) }.pluck(:name) + + json.id is.id + json.code is.item_instance_code + json.name is.item_instance_name + json.price is.price + json.is_available is.is_available + json.is_default is.is_default + json.is_on_promotion is.is_on_promotion + json.promotion_price is.promotion_price + json.values instance_attr + end + end + + end + end + end + end + end +end diff --git a/app/views/foodcourt/dashboard/get_all_menu.json.jbuilder b/app/views/foodcourt/dashboard/get_all_menu.json.jbuilder new file mode 100644 index 00000000..cce593ff --- /dev/null +++ b/app/views/foodcourt/dashboard/get_all_menu.json.jbuilder @@ -0,0 +1,18 @@ +menu_json = json.array! @menus do |menu| + + if !menu.is_ordering + json.id menu.id + json.name menu.name + json.valid_days menu.valid_days + json.valid_time_from menu.valid_time_from.strftime("%H:%M") + json.valid_time_to menu.valid_time_to.strftime("%H:%M") + + json.partial! 'foodcourt/dashboard/menu', menu: menu + # if (@current_menu) + # json.current_menu do + # json.partial! 'api/restaurant/menu/menu', menu: @current_menu + # end + # end + end + +end diff --git a/app/views/foodcourt/dashboard/index.html.erb b/app/views/foodcourt/dashboard/index.html.erb new file mode 100644 index 00000000..1caab8e6 --- /dev/null +++ b/app/views/foodcourt/dashboard/index.html.erb @@ -0,0 +1,281 @@ +
+ +
+ +

<%= t :date_time %> : <%= Time.zone.now.utc.getlocal.strftime("%Y-%m-%d %I:%M %p") %>

+
+ <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end + %> + + +
+ <% if @quick_service == '1' %> +
+
+
+ arrow_forward +
+
<%= t :quick_service %>
+
+
+ <% end %> + <% if @food_court == '1' %> +
+
+
+ arrow_forward +
+
<%= @food_court_name %>
+
+
+ <% end %> + <% if @dinein_cashier == '1' %> +
+
+
+ arrow_forward +
+
<%= t :dine_in_cashier %>
+
+
+ <% end %> + <% if @reservation == '1' %> +
+
+
+ arrow_forward +
+
<%= t :reservation %>
+
+
+ <% end %> + <% if @order_reservation == '1' %> +
+
+
+ arrow_forward +
+
<%= t :order_reservation %>
+
+
+ <% end %> +
+ + <% if !@current_user.nil? && @current_user.role != 'waiter' && @setting_flag %> + +
+ + <% if !@summ_sale.nil? %> + +
+
+
+
<%= t :sale %>
+ + + + + + + <% revenue = @summ_sale.total_amount - @summ_sale.total_discount%> + + + + + + + + + + + + + + + +
<%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.receipt") %> : <%= @summ_sale.total_receipt %>
<%= t("views.right_panel.detail.sale") %> <%= t :revenue %> : <%= number_with_precision( revenue, precision: precision.to_i ,delimiter: delimiter) %>
<%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.discount") %> : <%= number_with_precision( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) %>
<%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> : <%= number_with_precision( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter)%>
<%= t("views.right_panel.detail.total") %> <%= t :sale %> : <%= number_with_precision( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter)%>
+ + <% if !(@total_payment_methods.nil?) %> + <% @total_payment_methods.each do |payment| %> + <% if !@sale_data[0].empty? %> + <% if payment.payment_method != 'mpu' && payment.payment_method != 'visa' && payment.payment_method != 'master' && payment.payment_method != 'jcb' %> + + <% if payment.payment_method == 'paypar' %> + + <% else %> + + <% end %> + + + <% end %> + <% end %> + <% end %> + + <% total_card = @sale_data.select { |hash| hash["card"]!=nil }.first %> + <% if !total_card.nil? %> + + + + + <% end %> + + <% end %> +
Redeem Sale : <%= payment.payment_method.to_s.capitalize %> Sale : + <% @sale_data.each do |data| %> + <% pay_mth = payment.payment_method %> + <%= data[""+pay_mth+""] %> + <% end %> +
<%= t("views.right_panel.detail.other_payment") %> : + <%= total_card["card"].to_f %> +
+
+
+
+ <% end %> +
+
+
+
<%= t :customer %>
+ + <% if !@total_customer.nil? %> + + + + + <% end %> + <% if !@total_dinein.nil? %> + + + + + <% end %> + <% if !@total_takeaway.nil? %> + + + + + <% end %> + + <% if !@total_membership.nil? %> + + + + + <% end %> +
<%= t("views.right_panel.detail.total") %> <%= t :customer %> : <%= @total_customer %>
<%= t("views.right_panel.detail.dine_in") %> : <%= @total_dinein %>
<%= t("views.right_panel.detail.takeaway") %> : <%= @total_takeaway %>
<%= t("views.right_panel.detail.membership") %> : <%= @total_membership %>
+
+
+
+
+
+
+
<%= t("views.right_panel.detail.order") %>
+ + <% if !@total_order.nil? %> + + + + + <% end %> + + <% if !@total_accounts.nil? %> + <% @total_accounts.each do |account| %> + + + + + <% end %> + <% end %> + <% if !@top_items.nil? %> + + + + + <% end %> + <% if !@total_foc_items.nil? %> + + + + + <% end %> +
<%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.order") %> : <%= @total_order.total_order %>
<%= account.title %> (Account) : + <% @account_data.each do |data| %> + <% acc = account.title %> + <%= data[""+acc+""] %> <% if !data[''+acc+''].nil? %> ( <%= data[''+acc+'_amount'] %> ) <% end %> + <% end %> +
<%= t :top %> <%= t("views.right_panel.detail.item") %> : <%= @top_items.item_name %> +
(<%= @top_items.item_total_price %>)
<%= t("views.right_panel.detail.total") %> <%= t("views.btn.foc") %> <%= t("views.right_panel.detail.item") %> : <%= @total_foc_items.to_int %>
+
+
+
+
+ <% end %> +
+ + " id="server_mode"> + diff --git a/app/views/foodcourt/discounts/index.html.erb b/app/views/foodcourt/discounts/index.html.erb new file mode 100755 index 00000000..5ca020a3 --- /dev/null +++ b/app/views/foodcourt/discounts/index.html.erb @@ -0,0 +1,919 @@ +
+ + <% if !@print_settings.nil? %> + <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end + %> + <% end %> +
+ +
+ +
+ +
+
+
+ <%if !@table.nil?%> + + + <%else%> + + + <%end%> + + +

Receipt No: <%=@sale_data.receipt_no rescue ' '%>

+ +
+
+

Date: <%=@sale_data.receipt_date.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>

+
+
+
+
+ + + + + + + + + + + <% sub_total = 0 %> + <% @sale_data.sale_items.each do |sale_item| %> + <% sub_total += sale_item.qty * sale_item.unit_price %> + <% if sale_item.price > 0 && sale_item.status.blank? %> + > + + + + + <% elsif sale_item.price < 0 && sale_item.status == "Discount" %> + > + + + + + <% end %> + <% end %> + +
ItemsQTYPrice
+ + + <%=sale_item.product_name%>@<%=sale_item.unit_price%> + + <%=sale_item.qty%> + + <%=(sale_item.qty*sale_item.unit_price)%> +
+ + + <%=sale_item.product_name%>@<%=sale_item.unit_price%> + + <%=sale_item.qty.abs%> + + <%=(sale_item.qty*sale_item.unit_price)%> +
+
+
+ +
+
+
+ + + +
+ +
+
+
Discount Control
+
+
+
+
+
+
+ + +
+
+
+ <% @accounts.each do |acc| %> + + <% end %> +
+
+
+
+ +
+
+
+
+
+
+
5%
+
+
+
+
1
+
2
+
3
+
+
+
+ +
+
+
10%
+
+
+
+
4
+
5
+
6
+
+
+
+ +
+
+
15%
+
+
+
+
7
+
8
+
9
+
+
+
+ +
+
+
20%
+
+
+
+
0
+
.
+
00
+
+
+
+ +
+
+
30%
+
+
+
+
+
DEL
+
CLR
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+ + +
+ +
+ +
+ + + + + <% if @member_discount%> + + <%end %> +
+
+
+
+ + diff --git a/app/views/foodcourt/orders/app_orders.html.erb b/app/views/foodcourt/orders/app_orders.html.erb new file mode 100644 index 00000000..98c1f989 --- /dev/null +++ b/app/views/foodcourt/orders/app_orders.html.erb @@ -0,0 +1,364 @@ + +<%= javascript_include_tag 'custom', 'data-turbolinks-track': 'reload' %> +<% if @booking.nil?%> + +<% end %> +
+ +
+ <% if !@booking.nil?%> +
+ <% else %> +
+ <% end %> +
+
+ <% bk_color ='' %> + <% @bookings.each do |bk| + bk_status ='completed' + if bk.booking_status =='assign' + bk_status ='new' + end + if !@booking.nil? + if bk.booking_id == @booking.booking_id + bk_color ='bg-red' + else + bk_color =bk.booking_status + end + else + bk_color =bk.booking_status + end %> + <%= link_to foodcourt_app_order_by_booking_path(booking_id:bk.booking_id) do %> +
+
+ Cus Ph :<%= bk.contact_no %>Order Time :<%= bk.checkin_at.utc.getlocal.strftime("%I:%M %p") %>
+ Order No :<%= bk.orders[0].order_id %><%= bk_status %>
+
+ <% end %> + <% end %> +
+
+
+ <% if !@booking.nil?%> + +
+
+
+
+ ORDER DETAILS | Table-<%=@booking.dining_facility.name%>
+ Booking - <%=@booking.booking_id%>
+ Order No- <%=@booking.order_id%> +
+
+
+
+ + + + + + + + + + + <% sub_total = 0 + count = 0 + %> + <% @sale_data.sale_items.each do |sale_item| + count += 1 + %> + <% sub_total += sale_item.price%> + + + + + + + <%end %> + +
#ItemsQtyPrice
<%= count %><%=sale_item.product_name%>@<%=number_with_precision( sale_item.unit_price, precision: precision.to_i )%><%=sale_item.qty%><%=(number_with_precision(sale_item.price, precision: precision.to_i ))%>
+
+ +
+
+
+
+ + Void +
+ <% end %> +
+ + + +
+ diff --git a/app/views/foodcourt/orders/show.html.erb b/app/views/foodcourt/orders/show.html.erb new file mode 100755 index 00000000..53fdb437 --- /dev/null +++ b/app/views/foodcourt/orders/show.html.erb @@ -0,0 +1,391 @@ + +
+ +
+ + + + +
+
+ +
+
+ <% @complete.each do |sale| %> +
+
+ <%= sale.receipt_no %><%= sale.sale_status %> +
+
+ <% end %> +
+
+ + +
+
+ <% @tables.each do |table| %> + <% if table.status == 'occupied' %> + <% if table.get_booking.nil? %> + <% if table.get_checkout_booking.nil? %> +
+ <% else %> +
+ <% end %> +
+ <%= table.name %>
+ <%= table.zone.name %> + billed +
+
+
+ <% else %> + <% if table.get_checkout_booking.nil? %> +
+ <% else %> +
+ <% end %> +
+ <%= table.name %>
+ <%= table.zone.name %> + new +
+
+ <% end %> + <% else %> +
+
+ <%= table.name %>
+ <%= table.zone.name %> + new +
+
+ <% end %> + <% end %> +
+
+ + +
+
+ <% @rooms.each do |room| %> + <% if room.status == 'occupied' %> + <% if room.get_booking.nil? %> +
+
+ <%= room.name %>
+ <%= room.zone.name %> + billed +
+
+ <% else %> +
+
+ <%= room.name %>
+ <%= room.zone.name %> + new +
+
+ <% end %> + <% else %> +
+
+ <%= room.name %>
+ <%= room.zone.name %> + +
+
+ <% end %> + <% end %> +
+
+ + +
+
+ <% @orders.each do |order| %> +
text-white" data-id = "<%= order.order_id %>"> +
+ <% + order_status = "" + sale_order = SaleOrder.find_by_order_id(order) + if sale_order + unless sale_order.sale_id.nil? + sale = Sale.find(sale_order.sale_id) + order_status = sale.sale_status + if order_status == 'new' + order_status = order.status + end + end + else + order_status = order.status + end + %> + <%= order.order_id %> <% if !order_status.empty? %>| <%= order_status %> <% end %> +
+
+ <% end %> +
+
+ + +
+
+
+
+ +
+
+ +
+
+
+ + + + + + + + + +
<%= t :credit %> <%= t :sale %> <%= t("views.right_panel.detail.date") %><%= t("views.right_panel.detail.receipt_no") %> <%= t :cashier %> <%= t("views.right_panel.detail.name") %> <%= t :customer %> <%= t("views.right_panel.detail.name") %> <%= t("views.right_panel.detail.credit_amount") %>
+
+
+
+ +
+
+ +
+ + +
+
+
+
ORDERS DETAILS
+
+
+
+
+ Order No: <%= @order.order_id %> + +
+
+ Date: <%= @order.created_at.utc.getlocal.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%> +
+
+
+
+ Customer : +
+ +
+
"> +
+ + + + + + + + + + <% + sub_total = 0 + @order.order_items.each do |sale_item| + sub_total = sub_total + sale_item.price + %> + <% unless sale_item.price <= 0 %> + + + + + + <% + end + end + %> + +
ItemsQTYPrice
+ <%= sale_item.item_name %> + <% if !sale_item.set_menu_items.nil? + sale_item.set_menu_items.each do |item_instance| %> +
<%= item_instance %> + <% end + end %> +
<%= sale_item.qty %><%= sale_item.price %>
+
+
+ +
+
+
+ + +
+ + <% if !@split_bill.nil? && @split_bill == '1' %> + + <% end %> + <% if @sale_status != 'completed' %> + + <% end %> + +
+
+
+ + + + + + diff --git a/app/views/foodcourt/other_charges/index.html.erb b/app/views/foodcourt/other_charges/index.html.erb new file mode 100755 index 00000000..0a446619 --- /dev/null +++ b/app/views/foodcourt/other_charges/index.html.erb @@ -0,0 +1,406 @@ +
+
+ +
+ +
+ +
+
+
+ +

Receipt No: <%=@sale_data.receipt_no rescue ' '%>

+ +
+
+

Date: <%=@sale_data.receipt_date.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>

+
+
+
+
+ + + + + + + + + + <% sub_total = 0 %> + <% @sale_data.sale_items.each do |sale_item| %> + <% + sub_total += sale_item.qty*sale_item.unit_price + unless sale_item.price == 0 + %> + > + + + + + <% + end + end + %> + +
ItemsQTYPrice
+ + <%=sale_item.product_name%>@<%=sale_item.unit_price%> + + <%=sale_item.qty%> + + <%=(sale_item.qty*sale_item.unit_price)%> +
+
+
+ +
+
+
+ + + +
+ +
+
+
Other Charges Control
+
+
+
+
+
+
+ +
+
+
+ +
+
+ + Is Taxable +
+
+
+
+ +
+ +
+
+
+
+
+
3000
+
+
+
+
1
+
2
+
3
+
+
+
+ +
+
+
5000
+
+
+
+
4
+
5
+
6
+
+
+
+ +
+
+
10000
+
+
+
+
7
+
8
+
9
+
+
+
+ +
+
+
15000
+
+
+
+
0
+
.
+
00
+
+
+
+ +
+
+
20000
+
+
+
+
+
DEL
+
CLR
+
+
+
+
+
+ +
+
+ + +
+
+
+
+
+
+ + +
+ +
+ <%if !@table.nil?%> + + <%else%> + + <%end%> + +
+
+
+
+ diff --git a/app/views/foodcourt/paymal/create.json.jbuilder b/app/views/foodcourt/paymal/create.json.jbuilder new file mode 100644 index 00000000..f352b148 --- /dev/null +++ b/app/views/foodcourt/paymal/create.json.jbuilder @@ -0,0 +1,2 @@ +json.set! :status, @out[0] +json.set! :message, @out[1] \ No newline at end of file diff --git a/app/views/foodcourt/paymal/index.html.erb b/app/views/foodcourt/paymal/index.html.erb new file mode 100644 index 00000000..17d99db0 --- /dev/null +++ b/app/views/foodcourt/paymal/index.html.erb @@ -0,0 +1,404 @@ +
+ +
+
+
+
+ + + +
+
+ + <%@payment_prices = @payment_prices +@rounding_adj%> + +
+
+
+ <% if @payparcount > 0 %> +
+
+ + +
+
+
+ <% end %> +
+
+ + +
+
+
+
+
+ +
0.0
+
+
+
+
+
+ +
+ +
+
+
+
+
+
1
+
2
+
3
+
+
+
4
+
5
+
6
+
+
+
7
+
8
+
9
+
+
+
0
+
.
+
00
+
+
+
Nett
+
Del
+
Clr
+
+
+
+
+
1000
+
3000
+
+
+
5000
+
10000
+
+
+
Pay
+
+
+ +
+
+ + +
+
+ +
+
+ +
+

Card Tap

+
+ +
+
+
+ + + + + diff --git a/app/views/foodcourt/payments/create.json.jbuilder b/app/views/foodcourt/payments/create.json.jbuilder new file mode 100755 index 00000000..f1dd8cad --- /dev/null +++ b/app/views/foodcourt/payments/create.json.jbuilder @@ -0,0 +1,2 @@ +json.status true + diff --git a/app/views/foodcourt/payments/show.html.erb b/app/views/foodcourt/payments/show.html.erb new file mode 100755 index 00000000..3790e518 --- /dev/null +++ b/app/views/foodcourt/payments/show.html.erb @@ -0,0 +1,1697 @@ +
+ + <% if !@print_settings.nil? %> + <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end + %> + <% 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 : <%=@table_no%>
+ +
Sale ID : <% if @sale_data %><%=@sale_data.sale_id %><% end %>
+
+ +
+
+ Customer : + <% if @cashier_type == 'quick_service' || @cashier_type == 'food_court' %> + + <% else %> + <%= @sale_data.customer.name%> + <% end %> + +
+
Checkin Time : <%if !@checkin_time.nil?%><%= @checkin_time.utc.getlocal.strftime("%I:%M %p") %> + <%end%>
+
+
+
+ +
+
+
+ + + + + + + + + +
#ItemsQTYPrice
+
+
+
+ +
+ + + <% sub_total = 0 + count = 0 + %> + <% @sale_data.sale_items.each do |sale_item| + count += 1 + %> + + <% sub_total += sale_item.price%> + + + + + + + <%end %> + +
<%= count %><%=sale_item.product_name%>@<%=number_with_precision( sale_item.unit_price, precision: precision.to_i )%><%=sale_item.qty%><%=(number_with_precision(sale_item.price, precision: precision.to_i ))%>
+
+
+
+ + + + +
+
+ +
+
+
+
+
Amount Due <% if !@sale_payment.nil? %>( Credit )<% end %>
+
+ + + + <% if @sale_payment.nil? %> + <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %> + <% else %> + <%= number_with_precision(@sale_payment[0].payment_amount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i)%> + <% end %> + + +
+
+ +
+
Cash
+
+ <%= number_with_precision(@cash, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %> +
+
+ <% if @sale_payment.nil? && @cashier_type != "food_court" %> +
+
Credit
+
<%= number_with_precision(@credit, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
+ <% else %> + + <% end %> +
+
Other Payments
+
+ <%= number_with_precision(@other_payment, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %> +
+
+
+
+
+ +
+
+
MPU
+ <% if @other != 0.0 %> +
<%= number_with_precision(@other, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+ <% else %> +
<%= number_with_precision(0, precision: precision.to_i ) %>
+ <% end %> +
+ + +
+
+
Redeem
+ <% if @ppamount != 0.0 %> +
<%= number_with_precision(@ppamount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+ <% else %> +
<%= number_with_precision(0, precision: precision.to_i ) %>
+ <% end %> +
+ + +
+
+
VISA
+ <% if @visacount != 0.0 %> +
<%= number_with_precision(@visacount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+ <% else %> +
<%= number_with_precision(0, precision: precision.to_i ) %>
+ <% end %> +
+ + +
+
+
JCB
+ <% if @jcbcount != 0.0 %> +
<%= number_with_precision(@jcbcount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+ <% else %> +
<%= number_with_precision(0, precision: precision.to_i ) %>
+ <% end %> +
+ + +
+
+
MASTER
+ <% if @mastercount != 0.0 %> +
<%= number_with_precision(@mastercount, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i ) %>
+ <% else %> +
<%= number_with_precision(0, precision: precision.to_i ) %>
+ <% end %> +
+ + + +
+
+
UNIONPAY
+ <% if @unionpaycount != 0.0 %> +
<%= number_with_precision(@unionpaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+ <% else %> +
<%= number_with_precision(0, precision: precision.to_i ) %>
+ <% end %> +
+ + +
+
+
Alipay
+ <% if @alipaycount != 0.0 %> +
<%= number_with_precision(@alipaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+ <% else %> +
<%= number_with_precision(0, precision: precision.to_i ) %>
+ <% end %> +
+ + +
+
+
PAYMAL
+ <% if @paymalcount != 0.0 %> +
<%= number_with_precision(@paymalcount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+ <% else %> +
<%= number_with_precision(0, precision: precision.to_i ) %>
+ <% end %> +
+ +
+
+
DINGA
+ <% if @dingacount != 0.0 %> +
<%= number_with_precision(@dingacount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+ <% else %> +
<%= number_with_precision(0, precision: precision.to_i ) %>
+ <% end %> +
+ + +
+
+
JUNCTION PAY
+ <% if @junctionpaycount != 0.0 %> +
<%= number_with_precision(@junctionpaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+ <% else %> +
<%= number_with_precision(0, precision: precision.to_i ) %>
+ <% end %> +
+ + +
+
+
GIFT VOUCHER
+ <% if @giftvouchercount != 0.0 %> +
<%= number_with_precision(@giftvouchercount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+ <% else %> +
<%= number_with_precision(0, precision: precision.to_i ) %>
+ <% end %> +
+ +
+
Balance
+
<%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
+ +
+
+ + +
+
+
+ + <% if @sale_payment.nil? %> + + + <% end %> + <% end %> + <% end %> + <% if @sale_payment.nil? %> +
+ +
+ <% end %> + <% end %> + <% end %> +
+
+
+ +
+ +
+ +
+
+
+
+
+ +
+ +
+ +
+
+
+ +
+
+
+ + + + + + +
+
+

Card Tap

+
+
+ +
+
+ + + + + diff --git a/app/views/foodcourt/paypar_payments/create.json.jbuilder b/app/views/foodcourt/paypar_payments/create.json.jbuilder new file mode 100755 index 00000000..f352b148 --- /dev/null +++ b/app/views/foodcourt/paypar_payments/create.json.jbuilder @@ -0,0 +1,2 @@ +json.set! :status, @out[0] +json.set! :message, @out[1] \ No newline at end of file diff --git a/app/views/foodcourt/paypar_payments/index.html.erb b/app/views/foodcourt/paypar_payments/index.html.erb new file mode 100755 index 00000000..4e74da85 --- /dev/null +++ b/app/views/foodcourt/paypar_payments/index.html.erb @@ -0,0 +1,21 @@ +
+ +
+
+ <% if @membership_id!=0 %> +
+
Redim Amount
+
+ <% end %> +
+
+
+ +
+ +
+ diff --git a/app/views/foodcourt/request_bills/print.json.jbuilder b/app/views/foodcourt/request_bills/print.json.jbuilder new file mode 100755 index 00000000..332a9cec --- /dev/null +++ b/app/views/foodcourt/request_bills/print.json.jbuilder @@ -0,0 +1,7 @@ +if @status == true + #show invoice number and stuff + json.status @status +else + json.status @status + json.error_message @error_message +end diff --git a/app/views/foodcourt/reservation/index.html.erb b/app/views/foodcourt/reservation/index.html.erb new file mode 100644 index 00000000..1575b1e5 --- /dev/null +++ b/app/views/foodcourt/reservation/index.html.erb @@ -0,0 +1,149 @@ +<%= stylesheet_link_tag 'reservation', media: 'all', 'data-turbolinks-track': 'reload' %> +<%= javascript_include_tag 'reservation', 'data-turbolinks-track': 'reload' %> +
+
+
+
+
+
<%= t :make_reservation %>
+
+
+
+
+
+ +
+
+
+
+
+   + +
+
+ +
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+ +
+
+
+ +
+
+ +
+
+
+
+ + +
+
+
+ +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+
+
diff --git a/app/views/foodcourt/sale_edit/apply_void.json.jbuilder b/app/views/foodcourt/sale_edit/apply_void.json.jbuilder new file mode 100755 index 00000000..08bf292c --- /dev/null +++ b/app/views/foodcourt/sale_edit/apply_void.json.jbuilder @@ -0,0 +1 @@ +json.status true diff --git a/app/views/foodcourt/sale_edit/cancel_all_void.json.jbuilder b/app/views/foodcourt/sale_edit/cancel_all_void.json.jbuilder new file mode 100755 index 00000000..08bf292c --- /dev/null +++ b/app/views/foodcourt/sale_edit/cancel_all_void.json.jbuilder @@ -0,0 +1 @@ +json.status true diff --git a/app/views/foodcourt/sale_edit/edit.html.erb b/app/views/foodcourt/sale_edit/edit.html.erb new file mode 100755 index 00000000..e1a8dd85 --- /dev/null +++ b/app/views/foodcourt/sale_edit/edit.html.erb @@ -0,0 +1,427 @@ +
+
+ +
+
+
+
INVOICE DETAILS
+
+
+
+
+

Receipt No: + <%= @saleobj.receipt_no rescue '' %> +

+
+
+

Date: + <%= @saleobj.created_at.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-' %> +

+
+
+
+
+

Customer :

+
+ +
+
+ + + + + + + + + + + + + <% + count = 0 + sub_total = 0 + @saleobj.sale_items.each do |sale_item| + count += 1 + sub_total = sub_total + sale_item.price + %> + + <% + # Can't check for discount + unless sale_item.price == 0 + %> + + + + <% if sale_item.status != 'void' && sale_item.status != 'edit' && sale_item.status != 'foc' %> + + + + + + <% elsif sale_item.qty.to_i < 0 || sale_item.status == 'edit' %> + + + + + <% else %> + + + + <% end %> + + <% + end + end + %> + +
#ItemsQTY + Price + Action
<%= count %> + <%= sale_item.product_name %> + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
+ + +
+ + + + +
+
+
+ + + + diff --git a/app/views/foodcourt/sale_edit/item_void.json.jbuilder b/app/views/foodcourt/sale_edit/item_void.json.jbuilder new file mode 100755 index 00000000..08bf292c --- /dev/null +++ b/app/views/foodcourt/sale_edit/item_void.json.jbuilder @@ -0,0 +1 @@ +json.status true diff --git a/app/views/foodcourt/sale_edit/item_void_cancel.json.jbuilder b/app/views/foodcourt/sale_edit/item_void_cancel.json.jbuilder new file mode 100755 index 00000000..08bf292c --- /dev/null +++ b/app/views/foodcourt/sale_edit/item_void_cancel.json.jbuilder @@ -0,0 +1 @@ +json.status true diff --git a/app/views/foodcourt/sales/add_to_existing_invoice.json.jbuilder b/app/views/foodcourt/sales/add_to_existing_invoice.json.jbuilder new file mode 100755 index 00000000..08bf292c --- /dev/null +++ b/app/views/foodcourt/sales/add_to_existing_invoice.json.jbuilder @@ -0,0 +1 @@ +json.status true diff --git a/app/views/foodcourt/sales/show.html.erb b/app/views/foodcourt/sales/show.html.erb new file mode 100755 index 00000000..fd74df43 --- /dev/null +++ b/app/views/foodcourt/sales/show.html.erb @@ -0,0 +1,565 @@ +
+
+ +
+ + + + "> + +
+
+ +
+
+ <% @complete.each do |sale| %> +
+
+ <%= sale.receipt_no %><%= sale.sale_status %> +
+
+ <% end %> +
+
+ + +
+
+ <% @tables.each do |table| %> + <% if table.status == 'occupied' %> + <% if table.get_booking.nil? %> + <% if table.get_checkout_booking.nil? %> +
+ <% else %> +
+ <% end %> +
+ <%= table.name %>
+ <%= table.zone.name %> + + billed +
+
+
+ <% else %> + <% if table.get_checkout_booking.nil? %> +
+ <% else %> +
+ <% end %> +
+ <%= table.name %>
+ <%= table.zone.name %> + + new +
+
+ <% end %> + <% else %> +
+
+ <%= table.name %>
+ <%= table.zone.name %> + new +
+
+ <% end %> + <% end %> +
+
+ + +
+
+ <% @rooms.each do |room| %> + <% if room.status == 'occupied' %> + <% if room.get_booking.nil? %> +
+
+ <%= room.name %>
+ <%= room.zone.name %> + + billed +
+
+ <% else %> +
+
+ <%= room.name %>
+ <%= room.zone.name %> + + new +
+
+ <% end %> + <% else %> +
+
+ <%= room.name %>
+ <%= room.zone.name %> + +
+
+ <% end %> + <% end %> +
+
+ + +
+
+ <% @orders.each do |order| %> +
text-white" data-id="<%= order.order_id %>"> +
+ <% + order_status = "" + sale_order = SaleOrder.find_by_order_id(order) + if sale_order + unless sale_order.sale_id.nil? + sale = Sale.find(sale_order.sale_id) + order_status = sale.sale_status + if order_status == 'new' + order_status = order.status + end + end + else + order_status = order.status + end + %> + <%= order.order_id %> <% if !order_status.empty? %>| <%= order_status %> <% end %> +
+
+ <% end %> +
+
+ + +
+
+
+
+ +
+
+ +
+
+
+ + + + + + + + + +
<%= t :credit %> <%= t :sale %> <%= t("views.right_panel.detail.date") %><%= t("views.right_panel.detail.receipt_no") %> <%= t :cashier %> <%= t("views.right_panel.detail.name") %> <%= t :customer %> <%= t("views.right_panel.detail.name") %> <%= t("views.right_panel.detail.credit_amount") %>
+
+
+
+ +
+
+ +
+ + + +
+
+
+
INVOICE DETAILS | Table <%= @dining.name rescue "" %>
+
+
+
+
+ Receipt No: + <%= @sale.receipt_no rescue '' %> + +
+
+ Date: <%= @sale.created_at.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%> +
+
+
+
+ Customer : <%= @sale.customer.name rescue "-" %> + +
+ +
+
+
+ + + + + + + + + + <% + sub_total = 0 + @sale.sale_items.each do |sale_item| + sub_total = sub_total + sale_item.price + %> + + <% #unless sale_item.price <= 0 %> + + + + + + <% + + #end + end + + %> + +
ItemsQTYPrice
<%= sale_item.product_name %><%= sale_item.qty %><%= sale_item.price %>
+
+
+ +
+
+
+ + +
+ + <% if @sale.sale_status != 'void' && @sale.sale_status != 'waste' && @sale.sale_status != 'spoile' %> + <% if current_login_employee.role == "cashier" %> + <% if @sale.payment_status != 'foc' %> + Void + <% end %> + Re.Print + <% else %> + <% if @sale.payment_status != 'foc' %> + + <% end %> + + <% end %> + <% end %> + +
+
+ + +
+ + + + + + + + + diff --git a/app/views/foodcourt/second_display/_second_display.html.erb b/app/views/foodcourt/second_display/_second_display.html.erb new file mode 100644 index 00000000..c09d6c4c --- /dev/null +++ b/app/views/foodcourt/second_display/_second_display.html.erb @@ -0,0 +1,67 @@ +
+
+ +
+
+
+
+ + + + + + + + + + + + + +
#ItemsQTYPrice
+
+
+
+ +
+ +
+
+
+
+ <% @display_images.each do |p| %> + <%= image_tag "#{p.image}", :alt => "rss feed"%> + <% break %> + <% end %> +
+
+
+
+ diff --git a/app/views/foodcourt/second_display/_slider.html.erb b/app/views/foodcourt/second_display/_slider.html.erb new file mode 100644 index 00000000..71f463b7 --- /dev/null +++ b/app/views/foodcourt/second_display/_slider.html.erb @@ -0,0 +1,20 @@ +<%= stylesheet_link_tag 'wow_style', media: 'all', 'data-turbolinks-track': 'reload' %> +<%= javascript_include_tag 'wowslider', 'data-turbolinks-track': 'reload' %> +<%= javascript_include_tag 'wow_script', 'data-turbolinks-track': 'reload' %> +
+
+
+
+
    + <% @display_images.each do |p| %> +
  • + <%= image_tag "#{p.image}", :alt => "rss feed"%> +
  • + <% end %> +
+
+
+
+
+
+ diff --git a/app/views/foodcourt/second_display/index.html.erb b/app/views/foodcourt/second_display/index.html.erb new file mode 100644 index 00000000..5b4ad7f0 --- /dev/null +++ b/app/views/foodcourt/second_display/index.html.erb @@ -0,0 +1,20 @@ +
+ +
+ <%= render 'slider' %> +
+ + +
+ diff --git a/app/views/foodcourt/shifts/create.json.jbuilder b/app/views/foodcourt/shifts/create.json.jbuilder new file mode 100755 index 00000000..08bf292c --- /dev/null +++ b/app/views/foodcourt/shifts/create.json.jbuilder @@ -0,0 +1 @@ +json.status true diff --git a/app/views/foodcourt/shifts/edit.html.erb b/app/views/foodcourt/shifts/edit.html.erb new file mode 100755 index 00000000..60d5c6d8 --- /dev/null +++ b/app/views/foodcourt/shifts/edit.html.erb @@ -0,0 +1 @@ +

Close Cashier

diff --git a/app/views/foodcourt/shifts/index.html.erb b/app/views/foodcourt/shifts/index.html.erb new file mode 100755 index 00000000..ebec0301 --- /dev/null +++ b/app/views/foodcourt/shifts/index.html.erb @@ -0,0 +1,2 @@ +

Origami::Shifts#index

+

Find me in app/views/origami/shifts/index.html.erb

diff --git a/app/views/foodcourt/shifts/new.html.erb b/app/views/foodcourt/shifts/new.html.erb new file mode 100755 index 00000000..eb02d644 --- /dev/null +++ b/app/views/foodcourt/shifts/new.html.erb @@ -0,0 +1,126 @@ +
+

Open Cashier

+
+
+
+ + + + + + <% @float.each do |float| %> + + + + + <% end %> + + + + +
Cashier Terminal + + +
<%= float.name %>
Total
+ +
+
+
+
+
+
1
+
2
+
3
+
+
+
4
+
5
+
6
+
+
+
7
+
8
+
9
+
+
+
0
+
.
+
00
+
+
+
Clr
+
Calculate
+
Open Cashier
+
+
+ +
+
+
+
+ diff --git a/app/views/foodcourt/shifts/sale_summary.html.erb b/app/views/foodcourt/shifts/sale_summary.html.erb new file mode 100755 index 00000000..321a3941 --- /dev/null +++ b/app/views/foodcourt/shifts/sale_summary.html.erb @@ -0,0 +1,201 @@ +
+ +
+

Sales Summary Quick View

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Cashier Cashier Terminal Opening Date Opening float Received Amount Cast In Cast Out Total Receipt Dining Count Takeaway Count Total Void
<%= @shift.employee.name%><%=@shift.cashier_terminal.name%><%= @shift.shift_started_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') %> + <%=@shift.opening_balance %><%=@shift.closing_balance %><%=@shift.cash_in %><%=@shift.cash_out %><%= @shift.total_receipt %><%= @shift.dining_count %><%= @shift.takeaway_count %>(<%= @shift.total_void.round(2) %>)
+ + <% @total_amount_by_account.each do |amount| %> + + + + + + <%end%> + + + + + + + <% @total_discount_by_account.each do |amount| %> + + + + + + <%end%> + + <% if !@total_member_discount[0].member_discount.nil? + @member_discount = @total_member_discount[0].member_discount rescue 0.0 + @overall = @shift.total_discounts - @member_discount + %> + + + + + + <%else @overall = @shift.total_discounts %> + + <%end%> + + + + + + + + + + + + <% @sale_taxes.each do |tax| %> + + + + + + <%end%> + + + + + + + + + + + + + + + +
Total <%= amount.account_name %> Amount<%= amount.total_price.round(2) %>
Net Sales<%=@shift.nett_sales %>
Total <%= amount.account_name %> Discount<%= amount.total_price.round(2) %>
Total Member Discount<%= @member_discount %>
Total Overall Discount<%= @overall %>
Total Discount<%= @shift.total_discounts %>
<%= tax.tax_name %> <%= tax.st_amount.round(2) %>
Total Tax <%=@shift.total_taxes %>
Rounding Adj <%= @shift.total_rounding.round(2) %>
Grand Total <%= @shift.grand_total.round(2) %>
+
+ + + + + + + + + + + + <% @total_amount = 0 + + @other_payment.each do |other| %> + + + + + + + + + + <% @total_amount = @total_amount+other.mpu_amount rescue 0.0 %> + + + + + + <% @total_amount = @total_amount+other.visa_amount rescue 0.0 %> + + + + + + <% @total_amount = @total_amount+other.master_amount rescue 0.0 %> + + + + + + <% @total_amount = @total_amount+other.jcb_amount rescue 0.0 %> + + + + + + <% @total_amount = @total_amount+other.paypar_amount rescue 0.0 %> + + + + + + <% @total_amount = @total_amount+other.foc_amount rescue 0.0 %> + + <%end%> + + + + + + + + + + + + +
Cash Payment <%=@shift.cash_sales %>
Credit Payment <%=@shift.credit_sales %>
Other Payment Detail
MPU Payment <%=other.mpu_amount.round(2) rescue 0.0 %>
VISA Payment <%=other.visa_amount.round(2) rescue 0.0 %>
JCB Payment <%=other.master_amount.round(2) rescue 0.0 %>
Master Payment <%=other.jcb_amount.round(2) rescue 0.0 %>
Reedem Payment <%=other.paypar_amount.round(2) rescue 0.0 %>
FOC <%=other.foc_amount.round(2) rescue 0.0 %>
Total Other Payment <%=@shift.other_sales %>
Total Payment <%= @total_amount+@shift.cash_sales+@shift.credit_sales %>
+
+
+ +
+


+ + +
+
+ + diff --git a/app/views/foodcourt/shifts/show.html.erb b/app/views/foodcourt/shifts/show.html.erb new file mode 100755 index 00000000..e2f2275c --- /dev/null +++ b/app/views/foodcourt/shifts/show.html.erb @@ -0,0 +1,282 @@ +
+ + +
+
+

<%= t :close_cashier %>

+
+ + + + + + + + + + +
<%= t :shift_started_at %><%= @shift.shift_started_at.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-' %>
<%= t :cashier_name %><%= @shift.employee.name rescue ''%>
+
+
+
+ <%= t :closing_balance %> +
+
+ +
+

+
+
+ + + <% if @bank_integration == '1' && @cashier_type!="ordering" %> + + <% end %> +
+
+ + +
+ diff --git a/app/views/foodcourt/shifts/update_shift.json.jbuilder b/app/views/foodcourt/shifts/update_shift.json.jbuilder new file mode 100755 index 00000000..08bf292c --- /dev/null +++ b/app/views/foodcourt/shifts/update_shift.json.jbuilder @@ -0,0 +1 @@ +json.status true diff --git a/app/views/foodcourt/surveys/_form.html.erb b/app/views/foodcourt/surveys/_form.html.erb new file mode 100755 index 00000000..c0ed9f59 --- /dev/null +++ b/app/views/foodcourt/surveys/_form.html.erb @@ -0,0 +1,534 @@ +
+
+
+
+ <%= simple_form_for(@survey, :url => foodcourt_create_surveys_path) do |f| %> + <%= f.error_notification %> +
+ <% if !@survey_data.nil? %> +
+
+
+ <%= f.input :child, input_html: { value: @survey_data.child, class: 'col-md-10', :onChange => "total_customer();", :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyChild(this.value);" }%> +
+
+
+
+ <%= f.input :adult, input_html: { value: @survey_data.adult, class: 'col-md-10', :onChange => "total_customer();", :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyAdult(this.value);" }%> +
+
+
+
+
+
+ <%= f.input :male , input_html: { value: @survey_data.male, class: 'col-md-10', :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyMale(this.value);" }%> +
+
+
+
+ <%= f.input :female , input_html: { value: @survey_data.female, class: 'col-md-10', :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyFemale(this.value);" }%> +
+
+
+ <%= f.input :total_customer, input_html: { value:@survey_data.total_customer , :readonly => true, class: 'col-md-11'} %> + <%= f.input :local , input_html: { value: @survey_data.local, class: 'col-md-11', :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyLocal(this.value);" }%> + + +
+ Foreigner +
+
+
+ + + +
+
+
+
+ + +
+
+
+
+ +
+
+ +
+ <% else %> +
+
+
+ <%= f.input :child , input_html: { class: 'col-md-10' ,min:'1', :onChange => "total_customer();", :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyChild(this.value);" }%> +
+
+
+
+ <%= f.input :adult , input_html: { class: 'col-md-10' ,min:'1', :onChange => "total_customer();", :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyAdult(this.value);" }%> +
+
+
+
+
+
+ <%= f.input :male , input_html: { min:'1',class: 'col-md-10' , :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyMale(this.value);" }%> +
+
+
+
+ <%= f.input :female , input_html: { min:'1',class: 'col-md-10' , :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyFemale(this.value);" }%> +
+
+
+ <%= f.input :total_customer, input_html: { :readonly => true,min:'1', class: 'col-md-11'} %> + <%= f.input :local , input_html: { min:'1',class: 'col-md-11', :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyLocal(this.value);" }%> + +
+ Foreigner +
+
+
+ + + +
+
+
+
+ + +
+
+
+
+ +
+
+ +
+ <% end %> + + <%if !@dining_facility.nil? %> + + + <%= f.input :dining_name, :as => :hidden, :input_html => { :value => @dining_facility.name } %> + <%else%> + + + <%= f.input :dining_name, :as => :hidden, :input_html => { :value => 0 } %> + <%end%> + + + + <% if !@survey_data.nil? %> + /> + <% else %> + + <% end %> + + + <%= f.input :created_by, :as => :hidden, :input_html => { :value => current_login_employee.name } %> + <%= f.input :receipt_no, :as => :hidden, :input_html => { :value => @receipt_no} %> + <%= f.input :total_amount, :as => :hidden, :input_html => { :value => @grand_total } %> +
+
+ <%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %> +
+ <% end %> +
+
+
+
+
+
+
+
+
+
+
1
+
2
+
3
+
+
+
+ +
+
+
+
4
+
5
+
6
+
+
+
+ +
+
+
+
7
+
8
+
9
+
+
+
+ +
+
+
+
0
+
.
+
00
+
+
+
+ +
+
+
+
+
DEL
+
CLR
+
+
+
+
+
+
+
+
+ +
+ +
+ +
+ +
+ + diff --git a/app/views/foodcourt/surveys/_survey.json.jbuilder b/app/views/foodcourt/surveys/_survey.json.jbuilder new file mode 100755 index 00000000..1a0e4aa8 --- /dev/null +++ b/app/views/foodcourt/surveys/_survey.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! settings_account, :id, :title, :account_type, :created_at, :updated_at +json.url settings_account_url(settings_account, format: :json) diff --git a/app/views/foodcourt/surveys/edit.html.erb b/app/views/foodcourt/surveys/edit.html.erb new file mode 100755 index 00000000..96fca006 --- /dev/null +++ b/app/views/foodcourt/surveys/edit.html.erb @@ -0,0 +1,12 @@ + + + <%= render 'form', settings_account: @settings_account %> diff --git a/app/views/foodcourt/surveys/index.html.erb b/app/views/foodcourt/surveys/index.html.erb new file mode 100755 index 00000000..c3d9cdfa --- /dev/null +++ b/app/views/foodcourt/surveys/index.html.erb @@ -0,0 +1,91 @@ + + +
+
+
+ + + + + + + + + + + + + + + <% @settings_accounts.each do |account| %> + + + + + + + + + + <% end %> + +
<%= t("views.right_panel.detail.title") %><%= t("views.right_panel.detail.account_type") %><%= t("views.right_panel.detail.discount") %><%= t("views.right_panel.detail.point") %><%= t("views.right_panel.detail.bonus") %><%= t("views.right_panel.detail.rebate") %><%= t("views.right_panel.detail.actions") %>
<%= account.title %><%= account.account_type == 1 ? "Expense" : "Income"%><%= account.discount %><%= account.point %><%= account.bonus %><%= account.rebate %> + <%= link_to t("views.btn.show"), settings_account_path(account),:class => 'btn btn-info btn-sm waves-effect' %> + <%= link_to t("views.btn.edit"), edit_settings_account_path(account),:class => 'btn btn-primary btn-sm waves-effect' %> +
+
+
+
+
+
+
view_headline <%= t("views.right_panel.header.page_detail") %>
+

+ 1) <%= t("views.right_panel.detail.title") %> - <%= t("views.right_panel.detail.title_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.account_txt") %>
+ 2) <%= t("views.right_panel.detail.account_type") %> - <%= t("views.right_panel.detail.account_type_txt") %>
+ 3) <%= t("views.right_panel.detail.discount") %> - <%= t("views.right_panel.detail.status_txt2") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.discount_txt") %>
+ 4) <%= t("views.right_panel.detail.point") %> - <%= t("views.right_panel.detail.status_txt2") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.point_txt") %>
+ 5) <%= t("views.right_panel.detail.bonus") %> - <%= t("views.right_panel.detail.status_txt2") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.bonus_txt") %>
+ 6) <%= t("views.right_panel.detail.rebate") %> - <%= t("views.right_panel.detail.status_txt2") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.rebate_txt") %>
+ 7) <%= t("views.right_panel.detail.actions") %> - <%= t("views.right_panel.detail.actions_txt") %> <%= t("views.right_panel.detail.account_txt") %>
+

+
list <%= t("views.right_panel.header.button_lists") %>
+

+ 1) <%= t("views.right_panel.button.new") %> - <%= t("views.right_panel.detail.new_btn_txt") %> <%= t("views.right_panel.detail.account_txt") %>
+ 2) <%= t("views.right_panel.button.show") %> - <%= t("views.right_panel.detail.show_btn_txt") %> <%= t("views.right_panel.detail.account_txt") %>
+ 2) <%= t("views.right_panel.button.edit") %> - <%= t("views.right_panel.detail.edit_btn_txt") %> <%= t("views.right_panel.detail.account_txt") %>
+

+
list <%= t("views.right_panel.header.link_lists") %>
+

+ 1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %>
+ 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.dashboard_txt") %>
+

+
+
+
+
+ +
+
+ + diff --git a/app/views/foodcourt/surveys/index.json.jbuilder b/app/views/foodcourt/surveys/index.json.jbuilder new file mode 100755 index 00000000..10158c29 --- /dev/null +++ b/app/views/foodcourt/surveys/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @settings_accounts, partial: 'settings_accounts/settings_account', as: :settings_account diff --git a/app/views/foodcourt/surveys/new.html.erb b/app/views/foodcourt/surveys/new.html.erb new file mode 100755 index 00000000..ee4d9a57 --- /dev/null +++ b/app/views/foodcourt/surveys/new.html.erb @@ -0,0 +1,3 @@ + + + <%= render 'form', survey: @survey %> diff --git a/app/views/foodcourt/surveys/show.html.erb b/app/views/foodcourt/surveys/show.html.erb new file mode 100755 index 00000000..4c28f27c --- /dev/null +++ b/app/views/foodcourt/surveys/show.html.erb @@ -0,0 +1,84 @@ + + + +
+ +
+
+
+
+

Account

+ + + + + + + + + + + + + + + + + + + + + + + + + +
<%= t("views.right_panel.detail.title") %><%= t("views.right_panel.detail.account_type") %><%= t("views.right_panel.detail.can_get_points") %><%= t("views.right_panel.detail.can_rebate") %><%= t("views.right_panel.detail.actions") %>
<%= @settings_account.title %><%= @settings_account.account_type %><%= @settings_account.point %><%= @settings_account.rebate %><%= link_to t("views.btn.edit"), edit_settings_account_path(@settings_account),:class => 'btn btn-primary btn-sm waves-effect' %> + + + +
+
+
+
+ +
+
+
+
view_headline <%= t("views.right_panel.header.page_detail") %>
+

+ 1) <%= t("views.right_panel.detail.title") %> - <%= t("views.right_panel.detail.title_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.account_txt") %>
+ 2) <%= t("views.right_panel.detail.account_type") %> - <%= t("views.right_panel.detail.account_type_txt") %>
+ 3) <%= t("views.right_panel.detail.can_get_points") %> - <%= t("views.right_panel.detail.status_txt2") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.point_txt") %>
+ 4) <%= t("views.right_panel.detail.can_rebate") %> - <%= t("views.right_panel.detail.status_txt2") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.rebate_txt") %>
+ 5) <%= t("views.right_panel.detail.actions") %> - <%= t("views.right_panel.detail.actions_txt2") %> <%= t("views.right_panel.detail.account_txt") %>
+

+
list <%= t("views.right_panel.header.button_lists") %>
+

+ 1) <%= t("views.right_panel.button.edit") %> - <%= t("views.right_panel.detail.edit_btn_txt") %> <%= t("views.right_panel.detail.account_txt") %>
+ 2) <%= t("views.right_panel.button.delete") %> - <%= t("views.right_panel.detail.delete_btn_txt") %> <%= t("views.right_panel.detail.account_txt") %>
+

+
list <%= t("views.right_panel.header.link_lists") %>
+

+ 1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %>
+ 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.account_txt") %>
+

+
+
+
+
+ diff --git a/app/views/foodcourt/surveys/show.json.jbuilder b/app/views/foodcourt/surveys/show.json.jbuilder new file mode 100755 index 00000000..e9673454 --- /dev/null +++ b/app/views/foodcourt/surveys/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "settings_accounts/settings_account", settings_account: @settings_account diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index d8a5a9c8..71f7398a 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -67,24 +67,16 @@
<% if !@from.nil? && @from != "" - from_date = DateTime.parse(@from).utc.getlocal.strftime("%d-%m-%Y") + from_date = @from.strftime("%d-%m-%Y") + from_time = @from.strftime("%H:%M") if @from.strftime("%H:%M") != "00:00" else - from_date = Time.now.utc.getlocal.strftime('%d-%m-%Y') + from_date = Time.now.strftime('%d-%m-%Y') end if !@to.nil? && @to != "" - to_date = DateTime.parse(@to).utc.getlocal.strftime("%d-%m-%Y") + to_date = @to.strftime("%d-%m-%Y") + to_time = @to.strftime("%H:%M") if @to.strftime("%H:%M") != "23:59" else - to_date = Time.now.utc.getlocal.strftime('%d-%m-%Y') - end - if !@from_time.nil? - from_time = @from_time - else - from_time = '' - end - if !@to_time.nil? - to_time = @to_time - else - to_time = '' + to_date = Time.now.strftime('%d-%m-%Y') end %>
@@ -199,49 +191,48 @@ <% revenue = @summ_sale.total_amount - @summ_sale.total_discount%> <%= t("views.right_panel.detail.sale") %> <%= t :revenue %> : - <%= number_with_precision( revenue, precision: @precision.to_i ,delimiter: @delimiter) %> + + <%= number_format( revenue, precision: precision.to_i ,delimiter: delimiter) %> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.discount") %> : - <%= number_with_precision( @summ_sale.total_discount, precision: @precision.to_i ,delimiter: @delimiter) rescue number_with_precision(0, precision: @precision.to_i ,delimiter: @delimiter) %> + <%= number_format( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) rescue number_format(0, precision: precision.to_i ,delimiter: delimiter) %> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> : - <%= number_with_precision( @summ_sale.total_tax , precision: @precision.to_i ,delimiter: @delimiter) rescue number_with_precision(0, precision: @precision.to_i ,delimiter: @delimiter) %> + <%= number_format( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter) rescue number_format(0, precision: precision.to_i ,delimiter: delimiter) %> <%= t("views.right_panel.detail.total_sale") %> : - <%= number_with_precision( @summ_sale.grand_total , precision: @precision.to_i ,delimiter: @delimiter)%> + <%= number_format( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter)%> <% if !(@total_payment_methods.nil?) %> <% @total_payment_methods.each do |payment| %> - <% if !@sale_data[0].empty? %> - <% if payment.payment_method != 'mpu' && payment.payment_method != 'visa' && payment.payment_method != 'master' && payment.payment_method != 'jcb' && payment.payment_method != 'unionpay' %> - - <% if payment.payment_method == 'paypar' %> - - <% else %> - - <% end %> - - - <% end %> + + <% if payment.payment_method != 'card' %> + + <% if payment.payment_method == 'paypar' %> + + <% else %> + + <% end %> + + <% end %> <% end %> - <% total_card = @sale_data.select { |hash| hash["card"]!=nil }.first %> + <% total_card = @sale_data.find {|x| x.key?("card") } %> <% if !total_card.nil? %> <% end %> diff --git a/app/views/layouts/CRM.html.erb b/app/views/layouts/CRM.html.erb index 955abc98..f41f96f3 100755 --- a/app/views/layouts/CRM.html.erb +++ b/app/views/layouts/CRM.html.erb @@ -36,32 +36,36 @@
<%= render 'layouts/header' %> -
- <%= render 'layouts/left_sidebar' %> - <%= render 'layouts/right_sidebar' %> +
+ <%if current_login_employee.role == "foodcourt_cashier" %> + <%= render 'layouts/foodcourt_left_sidebar' %> + <% else %> + <%= render 'layouts/left_sidebar' %> + <%end%> + <%= render 'layouts/right_sidebar' %>
-
+
<% flash.each do |type, message| %> <% if !flash["errors"]%> - <% + <% if type == "notice" color = "alert-success" end if type == "error" color = "alert-danger" - end + end %> <% if flash["error"] || flash["notice"]%> <% end %> - <% end %> - <% end %> - <%= yield %> + <% end %> + <% end %> + <%= yield %>
- \ No newline at end of file + diff --git a/app/views/layouts/_foodcourt_left_sidebar.html.erb b/app/views/layouts/_foodcourt_left_sidebar.html.erb new file mode 100644 index 00000000..520a3251 --- /dev/null +++ b/app/views/layouts/_foodcourt_left_sidebar.html.erb @@ -0,0 +1,54 @@ + + + - - + <% if current_login_employee.role !='foodcourt_cashier' %> + + <% end %> + + + + + + + +<%end%> + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d03889f7..cd405859 100755 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -4,7 +4,7 @@ - + SmartSales : Restaurant <%= csrf_meta_tags %> @@ -12,10 +12,10 @@ <%= stylesheet_link_tag 'application', media: 'all' %> - <%= javascript_include_tag 'application' %> + <%= javascript_include_tag 'application' %> - +
@@ -37,27 +37,32 @@
<%= render 'layouts/header' %> -
- <%= render 'layouts/left_sidebar' %> - <%= render 'layouts/right_sidebar' %> +
+ <%if current_login_employee.role == "foodcourt_cashier" %> + <%= render 'layouts/foodcourt_left_sidebar' %> + <% else %> + <%= render 'layouts/left_sidebar' %> + <%end%> + + <%= render 'layouts/right_sidebar' %>
-
+
<% flash.each do |type, message| %> - <% if type == "notice" + <% if type == "notice" color = "alert-success" elsif type == "error" color = "alert-danger" else color = "bg-black" end %> - + - <% end %> - <%= yield %> -
+ <% end %> + <%= yield %> +
- \ No newline at end of file + diff --git a/app/views/layouts/foodcourt.html.erb b/app/views/layouts/foodcourt.html.erb new file mode 100644 index 00000000..05b1542b --- /dev/null +++ b/app/views/layouts/foodcourt.html.erb @@ -0,0 +1,63 @@ + + + + + + + + SmartSales : Restaurant + <%= csrf_meta_tags %> + + + + + <%= stylesheet_link_tag 'origami', media: 'all' %> + <%= javascript_include_tag 'origami', 'data-turbolinks-track': 'reload' %> + + + + +
+
+
+
+
+
+
+
+
+
+
+
+

Please wait...

+
+
+ + +
+ + <%= render 'layouts/header' %> +
+ <%= render 'layouts/foodcourt_left_sidebar' %> + <%= render 'layouts/right_sidebar' %> +
+ + +
+ <% flash.each do |type, message| %> + <% if type == "notice" + color = "alert-success" + elsif type == "error" + color = "alert-danger" + else + color = "bg-black" + end %> + + + <% end %> + <%= yield %> +
+ + diff --git a/app/views/layouts/login_dashboard.html.erb b/app/views/layouts/login_dashboard.html.erb index 407b5952..9edc81bc 100755 --- a/app/views/layouts/login_dashboard.html.erb +++ b/app/views/layouts/login_dashboard.html.erb @@ -68,7 +68,7 @@
- <%= shop_detail.name %> + <%= Shop.current_shop.name rescue "" %>
diff --git a/app/views/origami/dashboard/_menu.json.jbuilder b/app/views/origami/dashboard/_menu.json.jbuilder index d0c32865..19b05aa5 100644 --- a/app/views/origami/dashboard/_menu.json.jbuilder +++ b/app/views/origami/dashboard/_menu.json.jbuilder @@ -8,22 +8,17 @@ json.valid_time_to menu.valid_time_to.strftime("%H:%M") if (menu.menu_categories) order_by = Lookup.find_by_lookup_type("order_by") # if !order_by.nil? && order_by.value == "name" - # categories = MenuCategory.unscoped.where("menu_id ='#{menu.id}'").order("name asc") + # categories = MenuCategory.unscope(:order).where("menu_id ='#{menu.id}'").order("name asc") # else # categories = menu.menu_categories # end categories = menu.menu_categories json.categories categories do |category| if category.is_available - parent_category = category.parent - if !parent_category.nil? - json.sub_category "true" - else - json.sub_category "false" - end + json.sub_category category.children.present? + valid_time = category.valid_time json.valid_time valid_time - json.id category.id json.code category.code json.order_by category.order_by @@ -80,7 +75,7 @@ if (menu.menu_categories) alt_name: its.alt_name, min_selectable_qty: its.min_selectable_qty, max_selectable_qty: its.max_selectable_qty, - instances: its.menu_item_instances.pluck(:id).map { |id| {id: id}} + instances: its.menu_item_instances.map { |i| {id: i.id} } } } diff --git a/app/views/origami/dashboard/index.html.erb b/app/views/origami/dashboard/index.html.erb index 204ac3d4..713ba6a5 100644 --- a/app/views/origami/dashboard/index.html.erb +++ b/app/views/origami/dashboard/index.html.erb @@ -6,18 +6,6 @@

<%= t :date_time %> : <%= Time.zone.now.utc.getlocal.strftime("%Y-%m-%d %I:%M %p") %>

- <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %>
@@ -91,19 +79,19 @@
<% revenue = @summ_sale.total_amount - @summ_sale.total_discount%> - + - + - + - +
Redeem Sale : <%= payment.payment_method.to_s.capitalize %> Sale : - <% @sale_data.each do |data| %> - <% pay_mth = payment.payment_method %> - <%= number_with_precision(data[""+pay_mth+""], precision: @precision.to_i ,delimiter: @delimiter) rescue number_with_precision(0, precision: @precision.to_i ,delimiter: @delimiter) %> - <% end %> -
Redeem Sale : <%= payment.payment_method.to_s.capitalize %> Sale : + <%= number_format(@sale_data.find {|x| x.key?(payment.payment_method) }[payment.payment_method], precision: precision.to_i ,delimiter: delimiter) rescue number_format(0, precision: precision.to_i ,delimiter: delimiter) %> +
<%= t("views.right_panel.detail.other_payment") %> : - <%= number_with_precision(total_card["card"], precision: @precision.to_i ,delimiter: @delimiter) rescue number_with_precision(0, precision: @precision.to_i ,delimiter: @delimiter) %> + + <%= number_format(total_card["card"], precision: precision.to_i ,delimiter: delimiter) rescue number_format(0, precision: precision.to_i ,delimiter: delimiter) %> +
<%= t("views.right_panel.detail.sale") %> <%= t :revenue %> : <%= number_with_precision( revenue, precision: precision.to_i ,delimiter: delimiter) %><%= number_format( revenue, precision: precision.to_i ,delimiter: delimiter) %>
<%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.discount") %> : <%= number_with_precision( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) %><%= number_format( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) %>
<%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> : <%= number_with_precision( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter)%><%= number_format( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter)%>
<%= t("views.right_panel.detail.total") %> <%= t :sale %> : <%= number_with_precision( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter)%><%= number_format( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter)%>
diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index abeeb442..5d24c9d1 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -2,20 +2,6 @@ - <% if !@print_settings.nil? %> - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> - <% end %>
@@ -96,7 +82,7 @@
- +
@@ -364,7 +350,7 @@
Sub Total:<%= number_with_precision(sub_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %><%= number_format(sub_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- + <%if @obj_sale != nil && @obj_sale.discount_type == 'member_discount'%> @@ -373,7 +359,7 @@ <%end%> - + <% if @status_sale == "sale" %> @@ -396,15 +382,15 @@ <% end %> - + - + - + <% end %> diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index a40f7f58..a7737724 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -2,20 +2,6 @@ - <% if !@print_settings.nil? %> - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> - <% end %>
@@ -78,9 +64,9 @@ <% sub_total += sale_item.price%>
- + - + <%end %> @@ -93,7 +79,7 @@ - + <%if @sale_data.discount_type == 'member_discount'%> @@ -101,7 +87,7 @@ <%else%> <%end%> - + - + - + - + <%if @balance > 0%> - + <% end %> <% if !@individual_total[0].nil? %> @@ -149,7 +135,7 @@ - + <% end %> @@ -171,16 +157,16 @@ <% if @sale_payment.nil? %> - <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %> + <%= number_format(@sale_data.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %> <% else %> - <%= number_with_precision(@sale_payment[0].payment_amount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i)%> + <%= number_format(@sale_payment[0].payment_amount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i)%> <% end %> @@ -190,13 +176,13 @@
Cash
- <%= number_with_precision(@cash, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %> + <%= number_format(@cash, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% if @sale_payment.nil? && @cashier_type != "food_court" %>
Credit
-
<%= number_with_precision(@credit, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@credit, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> @@ -205,21 +191,21 @@
Other Payments (KBZ Pay)
- <%= number_with_precision(@kbz_pay_amount, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %> + <%= number_format(@kbz_pay_amount, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %>
<% elsif @other == 0.0 && @ppamount == 0.0 && @visacount == 0.0 && @jcbcount == 0.0 && @mastercount == 0.0 && @unionpaycount == 0.0 && @alipaycount == 0.0 && @paymalcount == 0.0 && @junctionpaycount == 0.0 && @dingacount == 0.0 && @giftvouchercount == 0.0 %>
Other Payments
- <%= number_with_precision(@other, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %> + <%= number_format(@other, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %>
<% else %>
Other Payments
- <%= number_with_precision(@other_payment, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %> + <%= number_format(@other_payment, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %>
<% end %> @@ -231,9 +217,9 @@
MPU
<% if @other != 0.0 %> -
<%= number_with_precision(@other, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@other, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -242,9 +228,9 @@
Redeem
<% if @ppamount != 0.0 %> -
<%= number_with_precision(@ppamount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@ppamount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -253,9 +239,9 @@
VISA
<% if @visacount != 0.0 %> -
<%= number_with_precision(@visacount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@visacount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -264,9 +250,9 @@
JCB
<% if @jcbcount != 0.0 %> -
<%= number_with_precision(@jcbcount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@jcbcount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -275,9 +261,9 @@
MASTER
<% if @mastercount != 0.0 %> -
<%= number_with_precision(@mastercount, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@mastercount, precision: precision.to_i) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -287,9 +273,9 @@
UNIONPAY
<% if @unionpaycount != 0.0 %> -
<%= number_with_precision(@unionpaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@unionpaycount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -298,9 +284,9 @@
Alipay
<% if @alipaycount != 0.0 %> -
<%= number_with_precision(@alipaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@alipaycount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -309,9 +295,9 @@
PAYMAL
<% if @paymalcount != 0.0 %> -
<%= number_with_precision(@paymalcount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@paymalcount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -319,9 +305,9 @@
DINGA
<% if @dingacount != 0.0 %> -
<%= number_with_precision(@dingacount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@dingacount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -330,9 +316,9 @@
JUNCTION PAY
<% if @junctionpaycount != 0.0 %> -
<%= number_with_precision(@junctionpaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@junctionpaycount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -341,15 +327,15 @@
GIFT VOUCHER
<% if @giftvouchercount != 0.0 %> -
<%= number_with_precision(@giftvouchercount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@giftvouchercount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %>
Balance
-
<%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@sale_data.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
diff --git a/app/views/origami/surveys/_form.html.erb b/app/views/origami/surveys/_form.html.erb index a4d8a666..b7ec4ca1 100755 --- a/app/views/origami/surveys/_form.html.erb +++ b/app/views/origami/surveys/_form.html.erb @@ -99,7 +99,7 @@ ' - +'<% Lookup.where("lookup_type = ? and shop_code='#{@shop.shop_code}'", "country" ).each do |ct| %>' + +'<% Lookup.where("lookup_type = ?", "country" ).each do |ct| %>' +'' +'<%end %>' @@ -321,7 +321,7 @@ var cashier_type = "<%= @cashier_type %>"; +'
' +' ' - +'<% Lookup.where("lookup_type = ? and shop_code='#{@shop.shop_code}'", "country" ).each do |ct| %>' + +'<% Lookup.where("lookup_type = ?", "country" ).each do |ct| %>' // if (key.toString() == '<%= ct.value.to_s %>') // var selected = "selected"; // else diff --git a/app/views/origami/table_invoices/show.html.erb b/app/views/origami/table_invoices/show.html.erb index 84efbc66..76c65057 100644 --- a/app/views/origami/table_invoices/show.html.erb +++ b/app/views/origami/table_invoices/show.html.erb @@ -1,19 +1,5 @@
-<% if !@print_settings.nil? %> - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> -<% end %>
@@ -89,7 +75,7 @@
- + <% # end @@ -108,7 +94,7 @@ - + <% end @@ -124,7 +110,7 @@
Sub Total:<%= number_with_precision(sub_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %><%= number_format(sub_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
Discount:(<%= number_with_precision(@obj_sale.total_discount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>)(<%= number_format(@obj_sale.total_discount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>)
<%= number_with_precision(@obj_sale.total_tax, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%><%= number_format(@obj_sale.total_tax, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%>
Rounding Adj:<%= number_with_precision(@obj_sale.rounding_adjustment, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%><%= number_format(@obj_sale.rounding_adjustment, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%>
Grand Total:<%= number_with_precision(@obj_sale.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %><%= number_format(@obj_sale.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<%= count %><%=sale_item.product_name%>@<%=number_with_precision( sale_item.unit_price, precision: precision.to_i )%><%=sale_item.product_name%>@<%=number_format( sale_item.unit_price, precision: precision.to_i )%> <%=sale_item.qty%><%=(number_with_precision(sale_item.price, precision: precision.to_i ))%><%=(number_format(sale_item.price, precision: precision.to_i ))%>
Sub Total<%=number_with_precision(sub_total, precision: precision.to_i)%><%=number_format(sub_total, precision: precision.to_i)%>
(Discount)(<%= number_with_precision(@sale_data.total_discount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>)(<%= number_format(@sale_data.total_discount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>)
@@ -122,20 +108,20 @@ <% end %> <%= number_with_precision(@sale_data.total_tax, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%><%= number_format(@sale_data.total_tax, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%>
Rounding Adj:<%= number_with_precision(@sale_data.rounding_adjustment, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%><%= number_format(@sale_data.rounding_adjustment, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%>
Grand Total<%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%><%= number_format(@sale_data.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%>
<%= @accountable_type %><%=number_with_precision(@balance, precision: precision.to_i )%><%=number_format(@balance, precision: precision.to_i )%>
Amount Due (per person) <%= number_with_precision(@individual_total[0]['per_person_amount'], precision: precision.to_i )%><%= number_format(@individual_total[0]['per_person_amount'], precision: precision.to_i )%>
<%= count %> <%= sale_item.product_name %> <%= sale_item.qty %><%= number_with_precision(sale_item.price, precision: precision.to_i ) %><%= number_format(sale_item.price, precision: precision.to_i ) %>
<%= count %> <%= order_item.item_name %> <%= order_item.qty %><%= number_with_precision(order_item.qty*order_item.price, precision: precision.to_i ) %><%= number_format(order_item.qty*order_item.price, precision: precision.to_i ) %>
- + <%if @sale.discount_type == 'member_discount'%> @@ -132,19 +118,19 @@ <%else%> <%end%> - + - + - + - +
Sub Total:<%= number_with_precision(sub_total, precision: precision.to_i ) %><%= number_format(sub_total, precision: precision.to_i ) %>
Discount:(<%= number_with_precision(@sale.total_discount, precision: precision.to_i ) rescue 0%>)(<%= number_format(@sale.total_discount, precision: precision.to_i ) rescue 0%>)
Tax:<%= number_with_precision(@sale.total_tax, precision: precision.to_i ) rescue 0%><%= number_format(@sale.total_tax, precision: precision.to_i ) rescue 0%>
Rounding Adj:<%= number_with_precision(@sale.rounding_adjustment, precision: precision.to_i ) rescue 0%><%= number_format(@sale.rounding_adjustment, precision: precision.to_i ) rescue 0%>
Grand Total:<%= number_with_precision(@sale.grand_total, precision: precision.to_i ) rescue 0%><%= number_format(@sale.grand_total, precision: precision.to_i ) rescue 0%>
@@ -163,7 +149,7 @@ <%else%> - <%end%> + <%end%> <% end %> @@ -173,7 +159,7 @@ <% else %>