diff --git a/app/controllers/origami/credit_payments_controller.rb b/app/controllers/origami/credit_payments_controller.rb index 1aab35a5..88982a94 100755 --- a/app/controllers/origami/credit_payments_controller.rb +++ b/app/controllers/origami/credit_payments_controller.rb @@ -43,7 +43,7 @@ class Origami::CreditPaymentsController < BaseOrigamiController saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "creditnote") + @status, @sale = sale_payment.process_payment(saleObj, current_user.name, cash, "creditnote") end end diff --git a/app/controllers/origami/dinga_controller.rb b/app/controllers/origami/dinga_controller.rb index 87caddfa..c10b9630 100644 --- a/app/controllers/origami/dinga_controller.rb +++ b/app/controllers/origami/dinga_controller.rb @@ -86,7 +86,7 @@ def create # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - status, @sale,@membership_data = sale_payment.process_payment(saleObj, @user, cash, "dinga",account_no) + status, @sale,@membership_data = sale_payment.process_payment(saleObj, current_user.name, cash, "dinga",account_no) if status == true && @membership_data["status"] == true @out = true, "Success!" diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 380c2c47..23c026b3 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -70,24 +70,24 @@ class Origami::DiscountsController < BaseOrigamiController sale_item.price = di["price"] sale_item.save - action_by = current_user.id + 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_id, action_by,remark,"ITEMDISCOUNT" ) + 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.id + 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_id, action_by,remark,"OVERALLDISCOUNT" ) + sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_name, action_by,remark,"OVERALLDISCOUNT" ) end sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f, nil,order_source) if !table.nil? @@ -129,13 +129,13 @@ class Origami::DiscountsController < BaseOrigamiController sale_item = SaleItem.find(di["id"]) sale.total_amount = (sale.total_amount + sale_item.price.abs) - action_by = current_user.id + 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_id, action_by,remark,"REMOVEITEMDISCOUNT" ) + sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_name, action_by,remark,"REMOVEITEMDISCOUNT" ) sale_item.destroy end @@ -197,13 +197,13 @@ class Origami::DiscountsController < BaseOrigamiController #destroy in sale.sale_items sale.sale_items.destroy(discount_items) - action_by = current_user.id + 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_id, action_by,remark,"REMOVEALLDISCOUNT" ) + 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(sale_id, sale.sale_items, 0, nil, order_source) diff --git a/app/controllers/origami/gift_voucher_controller.rb b/app/controllers/origami/gift_voucher_controller.rb index e52ed339..25c6f988 100644 --- a/app/controllers/origami/gift_voucher_controller.rb +++ b/app/controllers/origami/gift_voucher_controller.rb @@ -59,7 +59,7 @@ class Origami::GiftVoucherController < BaseOrigamiController # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "GiftVoucher",ref_no) + @status, @sale = sale_payment.process_payment(saleObj, current_user.name, cash, "GiftVoucher",ref_no) end end diff --git a/app/controllers/origami/jcb_controller.rb b/app/controllers/origami/jcb_controller.rb index dece303a..607d1f2c 100644 --- a/app/controllers/origami/jcb_controller.rb +++ b/app/controllers/origami/jcb_controller.rb @@ -67,7 +67,7 @@ class Origami::JcbController < BaseOrigamiController # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "jcb",ref_no) + @status, @sale = sale_payment.process_payment(saleObj, current_user.name, cash, "jcb",ref_no) end end diff --git a/app/controllers/origami/junction_pay_controller.rb b/app/controllers/origami/junction_pay_controller.rb index aa0f0615..67695603 100644 --- a/app/controllers/origami/junction_pay_controller.rb +++ b/app/controllers/origami/junction_pay_controller.rb @@ -63,7 +63,7 @@ class Origami::JunctionPayController < BaseOrigamiController # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "JunctionPay", remarks) + @status, @sale = sale_payment.process_payment(saleObj, current_user.name, cash, "JunctionPay", remarks) end end diff --git a/app/controllers/origami/master_controller.rb b/app/controllers/origami/master_controller.rb index 1e4c972d..27821c2c 100644 --- a/app/controllers/origami/master_controller.rb +++ b/app/controllers/origami/master_controller.rb @@ -64,7 +64,7 @@ class Origami::MasterController < BaseOrigamiController # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "master",ref_no) + @status, @sale = sale_payment.process_payment(saleObj, current_user.name, cash, "master",ref_no) end end diff --git a/app/controllers/origami/mpu_controller.rb b/app/controllers/origami/mpu_controller.rb index 234cebaa..00411fc3 100644 --- a/app/controllers/origami/mpu_controller.rb +++ b/app/controllers/origami/mpu_controller.rb @@ -65,7 +65,7 @@ class Origami::MpuController < BaseOrigamiController # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "mpu",ref_no) + @status, @sale = sale_payment.process_payment(saleObj, current_user.name, cash, "mpu",ref_no) end end diff --git a/app/controllers/origami/other_charges_controller.rb b/app/controllers/origami/other_charges_controller.rb index 4b94990b..63ffa937 100755 --- a/app/controllers/origami/other_charges_controller.rb +++ b/app/controllers/origami/other_charges_controller.rb @@ -60,14 +60,14 @@ class Origami::OtherChargesController < BaseOrigamiController sale_item.price = di["price"] * 1 sale_item.save - action_by = current_user.id + 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_id, action_by,remark,"ADDOTHERCHARGES" ) + sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,sale.cashier_name, action_by,remark,"ADDOTHERCHARGES" ) end end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 7948941b..dce4664a 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -60,6 +60,12 @@ class Origami::PaymentsController < BaseOrigamiController end end #end rounding adjustment + #record for sale audit + action_by = current_user.name + type = "FIRST_BILL" + + remark = "#{action_by} print out first bill for Receipt No #{sale_data.receipt_no}" + sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type ) # get member information rebate = MembershipSetting.find_by_rebate(1) if customer.membership_id != nil && rebate diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 1932821d..961fc855 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -46,6 +46,12 @@ class Origami::RequestBillsController < ApplicationController # @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) diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index b59aeb78..b14ccc05 100755 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -57,7 +57,7 @@ class Origami::SaleEditController < BaseOrigamiController 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,saleObj.cashier_id, action_by,remark,"SALEITEMVOID" ) + sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMVOID" ) saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount,order_source) ProductCommission.create_product_commission(@newsaleitem, saleitemObj) @@ -94,7 +94,7 @@ class Origami::SaleEditController < BaseOrigamiController 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,saleObj.cashier_id, action_by,remark,"SALEITEMFOC" ) + sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMFOC" ) saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount,order_source) ProductCommission.create_product_commission(@newsaleitem, saleitemObj) @@ -127,6 +127,8 @@ class Origami::SaleEditController < BaseOrigamiController 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 @@ -138,8 +140,8 @@ class Origami::SaleEditController < BaseOrigamiController if access_code != "null" && current_user.role == "cashier" action_by = Employee.find_by_emp_id(access_code).name end - remark = "Update 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,sale.cashier_id, action_by,remark,"SALEITEMEDIT" ) + 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' @@ -193,7 +195,7 @@ class Origami::SaleEditController < BaseOrigamiController 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,saleObj.cashier_id, action_by,remark,"ITEMCANCELVOID" ) + sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"ITEMCANCELVOID" ) saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount, order_source) ProductCommission.remove_product_commission(saleitemObj) diff --git a/app/controllers/origami/sales_controller.rb b/app/controllers/origami/sales_controller.rb index 63a7a34b..169df039 100755 --- a/app/controllers/origami/sales_controller.rb +++ b/app/controllers/origami/sales_controller.rb @@ -26,6 +26,7 @@ class Origami::SalesController < BaseOrigamiController # existing_booking.update_attributes(checkout_at: checkout_at) # end if booking.sale_id.nil? + order_array = [] booking.booking_orders.each do |booking_order| booking.booking_status = 'moved' @@ -48,7 +49,17 @@ class Origami::SalesController < BaseOrigamiController 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| diff --git a/app/controllers/origami/unionpay_controller.rb b/app/controllers/origami/unionpay_controller.rb index 2bb5b0cf..e74ff307 100644 --- a/app/controllers/origami/unionpay_controller.rb +++ b/app/controllers/origami/unionpay_controller.rb @@ -63,7 +63,7 @@ class Origami::UnionpayController < BaseOrigamiController # saleObj = Sale.find(sale_id) #end rounding adjustment sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "unionpay",ref_no) + @status, @sale = sale_payment.process_payment(saleObj, current_user.name, cash, "unionpay",ref_no) end end diff --git a/app/controllers/origami/visa_controller.rb b/app/controllers/origami/visa_controller.rb index 4dc0912a..465c6901 100644 --- a/app/controllers/origami/visa_controller.rb +++ b/app/controllers/origami/visa_controller.rb @@ -63,7 +63,7 @@ class Origami::VisaController < BaseOrigamiController # saleObj = Sale.find(sale_id) #end rounding adjustment sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "visa",ref_no) + @status, @sale = sale_payment.process_payment(saleObj, current_user.name, cash, "visa",ref_no) end end diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 76533730..e9c17ca1 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -78,7 +78,7 @@ class Origami::VoidController < BaseOrigamiController 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,sale.cashier_id, action_by,remark,"SALEVOID" ) + sale_audit = SaleAudit.record_audit_for_edit(sale_id,current_user.name, action_by,remark,"SALEVOID" ) # For Print diff --git a/app/controllers/origami/waste_spoile_controller.rb b/app/controllers/origami/waste_spoile_controller.rb index e7ca1091..2aa1bb77 100755 --- a/app/controllers/origami/waste_spoile_controller.rb +++ b/app/controllers/origami/waste_spoile_controller.rb @@ -59,7 +59,7 @@ class Origami::WasteSpoileController < BaseOrigamiController action_by = Employee.find_by_emp_id(access_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,sale.cashier_id, action_by,remark,remark ) + sale_audit = SaleAudit.record_audit_for_edit(sale_id,current_user.name, action_by,remark,remark ) # For Print diff --git a/app/models/sale_audit.rb b/app/models/sale_audit.rb index 633db6fe..b28753c4 100755 --- a/app/models/sale_audit.rb +++ b/app/models/sale_audit.rb @@ -72,7 +72,7 @@ class SaleAudit < ApplicationRecord sale_audit.sale_id = sale_id sale_audit.action = "SALEPAYMENT" sale_audit.action_at = DateTime.now.utc - sale_audit.action_by = Sale.find(sale_id).cashier_id + sale_audit.action_by = action_by sale_audit.remark = remark sale_audit.approved_by = action_by sale_audit.save! @@ -89,6 +89,17 @@ class SaleAudit < ApplicationRecord sale_audit.save! end + def self.record_audit_sale(sale_id, remark, action_by,type) + sale_audit = SaleAudit.new() + sale_audit.sale_id = sale_id + sale_audit.action = type + sale_audit.action_at = DateTime.now.utc + sale_audit.action_by = action_by + sale_audit.remark = remark + sale_audit.approved_by = action_by + sale_audit.save! + end + def self.paymal_search(sale_id) paymal = SaleAudit.where("sale_id =? and action = 'PAYMAL'",sale_id) remark = paymal[0].remark.split("}")