From 82de95ca22654c4b1369dd323a9a5eca3507ffe9 Mon Sep 17 00:00:00 2001 From: Nweni Date: Fri, 9 Jun 2017 13:52:36 +0630 Subject: [PATCH] update --- app/controllers/crm/customers_controller.rb | 32 ++++++++----------- .../origami/payments_controller.rb | 2 +- app/models/sale.rb | 1 - app/models/sale_order.rb | 3 -- app/models/sale_payment.rb | 12 ++++++- app/models/seed_generator.rb | 6 ---- app/views/origami/payments/show.html.erb | 2 +- 7 files changed, 27 insertions(+), 31 deletions(-) diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 325ac7dd..e1283bd6 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -38,10 +38,10 @@ class Crm::CustomersController < ApplicationController def create @crm_customers = Customer.new(customer_params) - + respond_to do |format| if @crm_customers.save - + name = customer_params[:name] phone = customer_params[:contact_no] @@ -63,12 +63,10 @@ class Crm::CustomersController < ApplicationController ) if response["status"] == true - puts "hhhhhhhhhhhhhhhhhh" - puts params[:sale_id] customer = Customer.find(@crm_customers.customer_id) status = customer.update_attributes(membership_id: response["customer_datas"]["id"]) - if params[:sale_id] != 0 - format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' } + if params[:sale_id] != 0 + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' } else format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: 'Customer was successfully created.' } end @@ -77,27 +75,27 @@ class Crm::CustomersController < ApplicationController @crm_customers.destroy - if params[:sale_id] != 0 + if params[:sale_id] != 0 format.html { redirect_to crm_customers_path, notice: response["message"] } - + else format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: response["message"] } end - + end - + # format.json { render :index, status: :created, location: @crm_customers } else if params[:sale_id] != 0 format.html { redirect_to crm_customers_path} format.json { render json: @crm_customers.errors, status: :unprocessable_entity } - + else format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: response["message"] } end - + end end end @@ -105,7 +103,7 @@ class Crm::CustomersController < ApplicationController # PATCH/PUT /crm/customers/1 # PATCH/PUT /crm/customers/1.json def update - + respond_to do |format| if @crm_customer.update(customer_params) @@ -118,7 +116,7 @@ class Crm::CustomersController < ApplicationController membership = MembershipSetting.find_by_membership_type("paypar_url") app_token = membership.auth_token.to_s url = membership.gateway_url.to_s + "/api/update_membership_customer".to_s - + response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, date_of_birth: date_of_birth, id: id}.to_json, @@ -127,7 +125,7 @@ class Crm::CustomersController < ApplicationController 'Accept' => 'application/json' } ) - + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated.' } format.json { render :show, status: :ok, location: @crm_customer } @@ -153,7 +151,7 @@ class Crm::CustomersController < ApplicationController # DELETE /crm/customers/1 # DELETE /crm/customers/1.json def get_sale_id - + @sale_id = params[:sale_id] @crm_customers = Customer.all @crm_customer = Customer.new @@ -179,5 +177,3 @@ class Crm::CustomersController < ApplicationController params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth, :membership_type, :membership_authentication_code) end end - - diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index fa8135fe..a3831439 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -18,7 +18,7 @@ class Origami::PaymentsController < BaseOrigamiController sale_id = params[:sale_id] if Sale.exists?(sale_id) @sale_data = Sale.find_by_sale_id(sale_id) - @sale_date.sale_payments.each do |spay| + @sale_data.sale_payments.each do |spay| if spay.payment_method == "cash" @cash = spay.payment_amount end diff --git a/app/models/sale.rb b/app/models/sale.rb index 93ed327c..47d271f1 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -16,7 +16,6 @@ class Sale < ApplicationRecord scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") } def generate_invoice_from_booking(booking_id, requested_by) - puts "get invoice from booking" booking = Booking.find(booking_id) status = false Rails.logger.debug "Booking -> " + booking.id.to_s diff --git a/app/models/sale_order.rb b/app/models/sale_order.rb index 5c8fea71..786054c9 100644 --- a/app/models/sale_order.rb +++ b/app/models/sale_order.rb @@ -16,11 +16,8 @@ class SaleOrder < ApplicationRecord private def generate_sale_order_id - puts "create slae order id" self.class.name saleOrderId = SeedGenerator.generate_id(self.class.name, "SOI") - puts saleOrderId self.sale_order_id = saleOrderId - puts "create sale order id" end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 573a2da3..bb829962 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -205,12 +205,22 @@ class SalePayment < ApplicationRecord end def sale_update_payment_status(paid_amount) + puts "sale update" #update amount_outstanding self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f self.sale.amount_changed = paid_amount.to_f - self.sale.amount_received.to_f - if (self.sale.grand_total <= self.sale.amount_received.to_f && self.sale.amount_changed.to_f > 0) + all_received_amount = 0.0 + sObj = self.sale + sObj.sale_payments.each do |spay| + puts spay + puts spay.payment_amount + all_received_amount += spay.payment_amount.to_f + end + puts all_received_amount + puts self.sale.grand_total + if (self.sale.grand_total <= all_received_amount) puts " sale update ......" self.sale.payment_status = "paid" self.sale.sale_status = "completed" diff --git a/app/models/seed_generator.rb b/app/models/seed_generator.rb index b333111f..fe896a4d 100644 --- a/app/models/seed_generator.rb +++ b/app/models/seed_generator.rb @@ -2,19 +2,15 @@ class SeedGenerator < ApplicationRecord def self.generate_id(model, prefix) seed = SeedGenerator.find_by_model(model) - puts "found seed" - puts seed new_receipt_no = 0 if (seed.nil?) - puts "seed is null" seed = SeedGenerator.new() seed.model = model new_receipt_no = seed.next seed.save else - puts "seed is not null" current_no = seed.next seed.next = seed.next + seed.increase_by seed.current = current_no @@ -22,8 +18,6 @@ class SeedGenerator < ApplicationRecord end padding_len = 15 - prefix.length - puts prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0') - puts "this is actural sale orde" saleOrderId = prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0') return saleOrderId diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 85505ef5..f16ef927 100644 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -78,7 +78,7 @@
CASH
-
0.0
+
<%= @cash %>