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_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 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.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 end end