require_dependency "educode_sales/application_controller" module EducodeSales class RecyclesController < ApplicationController def destroy @recycle = Recycle.find(params[:id]) @recycle.destroy render_success end def restore_follow_up @recycle = Recycle.find(params[:id]) report_id = @recycle.source_id EducodeSales::FollowUp.unscoped.find(report_id).update(deleted_at: nil) @recycle.destroy render_success end def restore_reports @recycle = Recycle.find(params[:id]) report_id = @recycle.source_id EducodeSales::SaleReport.unscoped.find(report_id).update(deleted_at: nil) @recycle.destroy render_success end def restore_plans @recycle = Recycle.find(params[:id]) plan = EducodeSales::SalePlan.unscoped.find(@recycle.source_id) business = EducodeSales::Business.unscoped.find(plan.business_id) Recycle.find_by(source_id: business.id).destroy if Recycle.find_by(source_id: business.id).present? business.update(deleted_at: nil) follow_ups = EducodeSales::FollowUp.unscoped.where(business_id: business.id) follow_ups.update_all(deleted_at: nil) plan.update(deleted_at: nil) @recycle.destroy render_success end def restore_businesses @recycle = Recycle.find(params[:id]) business_id = @recycle.source_id EducodeSales::Business.unscoped.find(business_id).update(deleted_at: nil) follow_ups = EducodeSales::FollowUp.unscoped.where(business_id: business_id) follow_ups.update_all(deleted_at: nil) @recycle.destroy render_success end def business @businesses = Recycle.where(source_type:"EducodeSales::Business") if params[:sort].present? && params[:sort][:field] @businesses = @businesses.order("created_at #{params[:sort][:order]}") else @businesses = @businesses.order("educode_sales_recycles.created_at desc") end @businesses = @businesses.page(params[:page]).per(params[:limit]) end def follow_up @data = Recycle.where(source_type:"EducodeSales::FollowUp") if params[:sort].present? && params[:sort][:field] @data = @data.order("created_at #{params[:sort][:order]}") else @data = @data.order("educode_sales_recycles.created_at desc") end @data = @data.page(params[:page]).per(params[:limit]) end def weekly @weekly = Recycle.where(source_type:"EducodeSales::SaleReport").order(created_at: :desc).page(params[:page]).per(params[:limit]) if params[:sort].present? && params[:sort][:field] @weekly = @weekly.order("created_at #{params[:sort][:order]}") else @weekly = @weekly.order("educode_sales_recycles.created_at desc") end @weekly = @weekly.page(params[:page]).per(params[:limit]) end def monthly @monthly = Recycle.where(source_type:"EducodeSales::SaleReport") if params[:sort].present? && params[:sort][:field] @monthly = @monthly.order("created_at #{params[:sort][:order]}") else @monthly = @monthly.order("educode_sales_recycles.created_at desc") end @monthly = @monthly.page(params[:page]).per(params[:limit]) end def weekPlan @weekPlans = Recycle.where(source_type:"EducodeSales::SalePlan") if params[:sort].present? && params[:sort][:field] @weekPlans = @weekPlans.order("created_at #{params[:sort][:order]}") else @weekPlans = @weekPlans.order("educode_sales_recycles.created_at desc") end @weekPlans = @weekPlans.page(params[:page]).per(params[:limit]) end def monthPlan @monthPlans = Recycle.joins("JOIN educode_sales_sale_plans ON educode_sales_sale_plans.id = educode_sales_recycles.source_id AND educode_sales_sale_plans.month IS NOT NULL AND educode_sales_sale_plans.weekly IS NULL").where(source_type:"EducodeSales::SalePlan") if params[:sort].present? && params[:sort][:field] @monthPlans = @monthPlans.order("created_at #{params[:sort][:order]}") else @monthPlans = @monthPlans.order("educode_sales_recycles.created_at desc") end @monthPlans = @monthPlans.page(params[:page]).per(params[:limit]) end def yearPlan @plans = Recycle.joins("JOIN educode_sales_sale_plans ON educode_sales_sale_plans.id = educode_sales_recycles.source_id AND educode_sales_sale_plans.year IS NOT NULL").where(source_type:"EducodeSales::SalePlan") if params[:sort].present? && params[:sort][:field] @plans = @plans.order("created_at #{params[:sort][:order]}") else @plans = @plans.order("educode_sales_recycles.created_at desc") end @plans = @plans.page(params[:page]).per(params[:limit]) end end end