Skip to content

Instantly share code, notes, and snippets.

@martink-io
martink-io / client.rb
Created February 21, 2019 10:54
Used Credit method
# Current Version
def used_credit_amount
used_credit = jobs.where(paid_on_credit: true)
.where.not(state: 'unpaid')
.where.not(state: 'complete')
.map(&:total_charge).sum
completed_jobs_on_credit = jobs.completed_paid_on_credit_by_client(self)
completed_jobs_on_credit.each do |job|
if job.client_invoice.status == 'unpaid'
def licences_query(users)
return users unless params[:licence_ids]
users_scope = users
licence_ids = params[:licence_ids]
if params[:licence_ids].is_a? String
licence_ids = params[:licence_ids].split(',').map{|chr| chr.to_i}
end
# 4 - Door Supervision
class JobItem < ApplicationRecord
VAT_RATE = 0.2
AMENDMENT_FORM_LABELS = ['Lateness', 'Full Refund'].freeze
AMENDMENT_TYPES = ['JobItems::Lateness', 'JobItems::Refund'].freeze
CHARGABLE_TYPES = ['JobItems::GuardBooking', 'JobItems::LateBookingPenalty'].freeze
REFUNDABLE_TYPES = ['JobItems::Lateness', 'JobItems::Refund'].freeze
PERCENTAGE_TYPES = ['JobItems::CancelationPenalty', 'JobItems::LateBookingPenalty'].freeze
HOURS_TYPES = ['JobItems::GuardBooking', 'JobItems::Lateness',].freeze
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware, compose} from 'redux';
import thunkMiddleware from 'redux-thunk';
import createLogger from 'redux-logger';
import reducer from './app/reducers';
import DashboardContainer from './app/containers/DashboardContainer';
@martink-io
martink-io / secretfile.rb
Last active October 3, 2018 10:17
I love refactoring!
# Before Refactoring
def max_refund_exceeded
return unless quantity.present?
job_hours = self.job.number_of_hours
amendment_hours = self.job.job_items.where(type: ['JobItems::Lateness', 'JobItems::Refund']).map(&:quantity).sum
errors[:base] << "You've exceeded maximum refund" unless amendment_hours + quantity <= job_hours
end
# After Refactoring #1
@martink-io
martink-io / cancel_filled.rb
Created October 3, 2018 09:50
client_command/jobs
module ClientCommand
module Jobs
class CancelFilled < BaseCommand
include Concerns::Common::WithUser
def call
job.cancel_client_filled! do
JobItemCommand::CreateCancellationPenaltyCharge::call(job: job)
if refund.save
AdminCommand::StripeRefund::Create::call(job: job)
import React from 'react';
import { FlatList, ActivityIndicator, Text, View } from 'react-native';
export default class FetchExample extends React.Component {
constructor(props){
super(props);
this.state ={ isLoading: true}
}
@martink-io
martink-io / cancel_filled.rb
Created September 25, 2018 14:37
Client Comamnd, Cancel Job Filled
module ClientCommand
module Jobs
class CancelFilled < BaseCommand
include Concerns::Common::WithUser
def call
job.cancel_client_filled! do
JobItemCommand::CreateCancellationPenaltyCharge::call(job: job)
if refund.save
AdminCommand::StripeRefund::Create::call(job: job)
module AdminCommand
module Jobs
class Assign < BaseCommand
include Concerns::Common::Collection
include Concerns::Common::WithUser
include Concerns::Jobs::GuardFilters
GUARD_ERROR = "Error: Job Is Already Filled"
LICENCE_ERROR ="Error: Guard Has Unmet Licence Requirements"
# TODO: Revisit guard_job creation and relations.
@martink-io
martink-io / cancel.rb
Last active September 10, 2018 19:56
Cancel assignment(guard_job) by guard/admin
module AdminCommand
module GuardJobs
class Cancel < BaseCommand
def call
if job.present? && job.filled?
if current_user.guard? && current_user.id != guard_job.guard_id
return false
end
guard_job.update(guard_id: nil)