Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,199 changes: 2,199 additions & 0 deletions app/schemas/org.fossasia.openevent.general.OpenEventDatabase/9.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import org.fossasia.openevent.general.event.Event
import org.fossasia.openevent.general.event.EventDao
import org.fossasia.openevent.general.event.EventIdConverter
import org.fossasia.openevent.general.event.subtopic.EventSubTopicConverter
import org.fossasia.openevent.general.event.tax.Tax
import org.fossasia.openevent.general.event.tax.TaxDao
import org.fossasia.openevent.general.event.topic.EventTopic
import org.fossasia.openevent.general.event.topic.EventTopicConverter
import org.fossasia.openevent.general.event.topic.EventTopicsDao
Expand Down Expand Up @@ -54,7 +56,7 @@ import org.fossasia.openevent.general.ticket.TicketIdConverter
@Database(entities = [Event::class, User::class, SocialLink::class, Ticket::class, Attendee::class,
EventTopic::class, Order::class, CustomForm::class, Speaker::class, SpeakerWithEvent::class, Sponsor::class,
SponsorWithEvent::class, Session::class, SpeakersCall::class, Feedback::class, Notification::class,
Settings::class, Proposal::class], version = 8)
Settings::class, Proposal::class, Tax::class], version = 9)
@TypeConverters(EventIdConverter::class, EventTopicConverter::class, EventTypeConverter::class,
EventSubTopicConverter::class, TicketIdConverter::class, MicroLocationConverter::class, UserIdConverter::class,
AttendeeIdConverter::class, ListAttendeeIdConverter::class, SessionTypeConverter::class, TrackConverter::class,
Expand Down Expand Up @@ -92,4 +94,6 @@ abstract class OpenEventDatabase : RoomDatabase() {
abstract fun notificationDao(): NotificationDao

abstract fun settingsDao(): SettingsDao

abstract fun taxDao(): TaxDao
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ import kotlinx.android.synthetic.main.fragment_attendee.view.signInTextLayout
import kotlinx.android.synthetic.main.fragment_attendee.view.signInLayout
import kotlinx.android.synthetic.main.fragment_attendee.view.signOutLayout
import kotlinx.android.synthetic.main.fragment_attendee.view.paymentTitle
import kotlinx.android.synthetic.main.fragment_attendee.view.taxLayout
import kotlinx.android.synthetic.main.fragment_attendee.view.taxPrice
import kotlinx.android.synthetic.main.fragment_attendee.view.totalAmountLayout
import kotlinx.android.synthetic.main.fragment_attendee.view.totalPrice
import org.fossasia.openevent.general.BuildConfig
import org.fossasia.openevent.general.R
import org.fossasia.openevent.general.auth.User
Expand Down Expand Up @@ -313,6 +317,11 @@ class AttendeeFragment : Fragment(), ComplexBackPressFragment {
rootView.ticketsRecycler.adapter = ticketsRecyclerAdapter
rootView.ticketsRecycler.isNestedScrollingEnabled = false

rootView.taxLayout.isVisible = safeArgs.taxAmount > 0f
rootView.taxPrice.text = "${safeArgs.currency}${"%.2f".format(safeArgs.taxAmount)}"
rootView.totalAmountLayout.isVisible = safeArgs.amount > 0f
rootView.totalPrice.text = "${safeArgs.currency}${"%.2f".format(safeArgs.amount)}"

rootView.ticketTableDetails.setOnClickListener {
attendeeViewModel.ticketDetailsVisible = !attendeeViewModel.ticketDetailsVisible
loadTicketDetailsTableUI(attendeeViewModel.ticketDetailsVisible)
Expand Down
17 changes: 15 additions & 2 deletions app/src/main/java/org/fossasia/openevent/general/di/Modules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ import org.fossasia.openevent.general.sessions.Session
import org.fossasia.openevent.general.sessions.SessionApi
import org.fossasia.openevent.general.sessions.SessionService
import org.fossasia.openevent.general.event.faq.EventFAQViewModel
import org.fossasia.openevent.general.event.tax.Tax
import org.fossasia.openevent.general.event.tax.TaxApi
import org.fossasia.openevent.general.event.tax.TaxService
import org.fossasia.openevent.general.favorite.FavoriteEvent
import org.fossasia.openevent.general.favorite.FavoriteEventApi
import org.fossasia.openevent.general.feedback.FeedbackViewModel
Expand Down Expand Up @@ -209,6 +212,10 @@ val apiModule = module {
val retrofit: Retrofit = get()
retrofit.create(SettingsApi::class.java)
}
single {
val retrofit: Retrofit = get()
retrofit.create(TaxApi::class.java)
}

factory { AuthHolder(get()) }
factory { AuthService(get(), get(), get(), get(), get(), get(), get()) }
Expand All @@ -224,6 +231,7 @@ val apiModule = module {
factory { NotificationService(get(), get()) }
factory { FeedbackService(get(), get()) }
factory { SettingsService(get(), get()) }
factory { TaxService(get(), get()) }
}

val viewModelModule = module {
Expand All @@ -241,7 +249,7 @@ val viewModelModule = module {
viewModel { SearchLocationViewModel(get(), get()) }
viewModel { SearchTimeViewModel(get()) }
viewModel { SearchTypeViewModel(get(), get(), get()) }
viewModel { TicketsViewModel(get(), get(), get(), get(), get()) }
viewModel { TicketsViewModel(get(), get(), get(), get(), get(), get()) }
viewModel { AboutEventViewModel(get(), get()) }
viewModel { EventFAQViewModel(get(), get()) }
viewModel { FavoriteEventsViewModel(get(), get(), get()) }
Expand Down Expand Up @@ -310,7 +318,7 @@ val networkModule = module {
EventSubTopic::class.java, Feedback::class.java, Speaker::class.java, FavoriteEvent::class.java,
Session::class.java, SessionType::class.java, MicroLocation::class.java, SpeakersCall::class.java,
Sponsor::class.java, EventFAQ::class.java, Notification::class.java, Track::class.java,
DiscountCode::class.java, Settings::class.java, Proposal::class.java)
DiscountCode::class.java, Settings::class.java, Proposal::class.java, Tax::class.java)

Retrofit.Builder()
.client(get())
Expand Down Expand Up @@ -408,4 +416,9 @@ val databaseModule = module {
val database: OpenEventDatabase = get()
database.settingsDao()
}

factory {
val database: OpenEventDatabase = get()
database.taxDao()
}
}
36 changes: 36 additions & 0 deletions app/src/main/java/org/fossasia/openevent/general/event/tax/Tax.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.fossasia.openevent.general.event.tax

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.fasterxml.jackson.databind.PropertyNamingStrategy
import com.fasterxml.jackson.databind.annotation.JsonNaming
import com.github.jasminb.jsonapi.IntegerIdHandler
import com.github.jasminb.jsonapi.annotations.Id
import com.github.jasminb.jsonapi.annotations.Relationship
import com.github.jasminb.jsonapi.annotations.Type
import org.fossasia.openevent.general.event.EventId

@Type("tax")
@JsonNaming(PropertyNamingStrategy.KebabCaseStrategy::class)
@Entity
class Tax(
@Id(IntegerIdHandler::class)
@PrimaryKey
val id: Int? = null,
val name: String? = null,
val rate: Float? = null,
val taxId: String? = null,
val registeredCompany: String? = null,
val address: String? = null,
val city: String? = null,
val stare: String? = null,
val zip: String? = null,
val invoiceFooter: String? = null,
val isInvoiceSend: Boolean = false,
val isTaxIncludedInPrice: Boolean = false,
val shouldSendInvoice: Boolean = false,
@ColumnInfo(index = true)
@Relationship("event")
val eventId: EventId? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.fossasia.openevent.general.event.tax

import io.reactivex.Single
import retrofit2.http.GET
import retrofit2.http.Path

interface TaxApi {

@GET("events/{event_identifier}/tax?include=event")
fun getTaxDetails(@Path("event_identifier") identifier: String): Single<Tax>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.fossasia.openevent.general.event.tax

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import io.reactivex.Single

@Dao
interface TaxDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertTax(tax: Tax)

@Query("SELECT * from Tax WHERE eventId = :eventId")
fun getTaxDetails(eventId: Long): Single<Tax>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.fossasia.openevent.general.event.tax

import io.reactivex.Single
import timber.log.Timber

class TaxService(
private val taxApi: TaxApi,
private val taxDao: TaxDao
) {

fun getTax(eventId: Long): Single<Tax> {
return taxApi.getTaxDetails(eventId.toString())
.onErrorResumeNext {
Timber.e(it, "Error fetching tax")
taxDao.getTaxDetails(eventId)
}.map {
taxDao.insertTax(it)
it
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import kotlinx.android.synthetic.main.item_ticket.view.discountPrice
import kotlinx.android.synthetic.main.item_ticket.view.donationInput
import kotlinx.android.synthetic.main.item_ticket.view.orderQtySection
import kotlinx.android.synthetic.main.item_ticket.view.priceSection
import kotlinx.android.synthetic.main.item_ticket.view.taxInfo
import org.fossasia.openevent.general.R
import org.fossasia.openevent.general.data.Resource
import kotlinx.android.synthetic.main.item_ticket.view.priceInfo
Expand All @@ -28,6 +29,7 @@ import kotlinx.android.synthetic.main.item_ticket.view.description
import org.fossasia.openevent.general.discount.DiscountCode
import org.fossasia.openevent.general.event.EventUtils
import org.fossasia.openevent.general.event.EventUtils.getFormattedDate
import org.fossasia.openevent.general.event.tax.Tax
import org.threeten.bp.DateTimeUtils
import java.util.Date
import kotlin.collections.ArrayList
Expand All @@ -47,7 +49,8 @@ class TicketViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
eventTimeZone: String?,
ticketQuantity: Int,
donationAmount: Float,
discountCode: DiscountCode? = null
discountCode: DiscountCode? = null,
tax: Tax?
) {
itemView.ticketName.text = ticket.name
setupTicketSaleDate(ticket, eventTimeZone)
Expand Down Expand Up @@ -76,6 +79,13 @@ class TicketViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
itemView.orderRange.performClick()
}

var ticketPrice = ticket.price
if (tax?.rate != null) {
val taxPrice = (ticketPrice * tax.rate / 100)
ticketPrice += taxPrice
itemView.taxInfo.text = "(+ $eventCurrency$taxPrice ${tax.name})"
}

when (ticket.type) {
TICKET_TYPE_DONATION -> {
itemView.price.text = resource.getString(R.string.donation)
Expand All @@ -90,14 +100,14 @@ class TicketViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
itemView.donationInput.isVisible = false
}
TICKET_TYPE_PAID -> {
itemView.price.text = "$eventCurrency${"%.2f".format(ticket.price)}"
itemView.price.text = "$eventCurrency${"%.2f".format(ticketPrice)}"
itemView.priceSection.isVisible = true
itemView.donationInput.isVisible = false
}
}
setupQtyPicker(minQty, maxQty, selectedListener, ticket, ticketQuantity)

val priceInfo = "<b>${resource.getString(R.string.price)}:</b> ${itemView.price.text}"
val priceInfo = "<b>${resource.getString(R.string.price)}:</b> ${ticket.price}"
itemView.priceInfo.text = Html.fromHtml(priceInfo)

if (ticket.description.isNullOrEmpty()) {
Expand All @@ -111,8 +121,8 @@ class TicketViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
itemView.discountPrice.visibility = View.VISIBLE
itemView.price.paintFlags = Paint.STRIKE_THRU_TEXT_FLAG
itemView.discountPrice.text =
if (discountCode.type == AMOUNT) "$eventCurrency${ticket.price - discountCode.value}"
else "$eventCurrency${"%.2f".format(ticket.price - (ticket.price * discountCode.value / 100))}"
if (discountCode.type == AMOUNT) "$eventCurrency${ticketPrice - discountCode.value}"
else "$eventCurrency${"%.2f".format(ticketPrice - (ticketPrice * discountCode.value / 100))}"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class TicketsFragment : Fragment() {

rootView.retry.setOnClickListener {
loadTickets()
loadTaxDetails()
}

rootView.applyDiscountCode.setOnClickListener {
Expand Down Expand Up @@ -177,7 +178,10 @@ class TicketsFragment : Fragment() {
ticketsViewModel.connection
.nonNull()
.observe(viewLifecycleOwner, Observer { isConnected ->
loadTickets()
if (isConnected) {
loadTickets()
loadTaxDetails()
}
showNoInternetScreen(!isConnected && ticketsViewModel.tickets.value == null)
})

Expand Down Expand Up @@ -220,6 +224,7 @@ class TicketsFragment : Fragment() {
ticketIdAndQty = wrappedTicketAndQty,
currency = safeArgs.currency,
amount = totalAmount,
taxAmount = ticketsViewModel.totalTaxAmount,
hasPaidTickets = ticketsViewModel.hasPaidTickets
))
ticketsViewModel.hasPaidTickets = false
Expand Down Expand Up @@ -295,6 +300,16 @@ class TicketsFragment : Fragment() {
}
}

private fun loadTaxDetails() {
ticketsViewModel.getTaxDetails(safeArgs.eventId)
ticketsViewModel.taxInfo
.nonNull()
.observe(viewLifecycleOwner, Observer {
ticketsRecyclerAdapter.applyTax(it)
ticketsRecyclerAdapter.notifyDataSetChanged()
})
}

private fun showNoInternetScreen(show: Boolean) {
rootView.noInternetCard.isVisible = show
rootView.ticketTableHeader.isVisible = !show
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import org.fossasia.openevent.general.R
import org.fossasia.openevent.general.discount.DiscountCode
import org.fossasia.openevent.general.event.tax.Tax

class TicketsRecyclerAdapter : RecyclerView.Adapter<TicketViewHolder>() {

private val tickets = ArrayList<Ticket>()
private var eventCurrency: String? = null
private var eventTimeZone: String? = null
private var discountCode: DiscountCode? = null
private var tax: Tax? = null
private var selectedListener: TicketSelectedListener? = null
private lateinit var ticketAndQuantity: List<Triple<Int, Int, Float>>

Expand All @@ -38,6 +40,10 @@ class TicketsRecyclerAdapter : RecyclerView.Adapter<TicketViewHolder>() {
this.discountCode = discountCode
}

fun applyTax(tax: Tax) {
this.tax = tax
}

fun cancelDiscountCode() {
this.discountCode = null
}
Expand All @@ -64,7 +70,7 @@ class TicketsRecyclerAdapter : RecyclerView.Adapter<TicketViewHolder>() {
}
}

holder.bind(ticket, selectedListener, eventCurrency, eventTimeZone, qty, donation, currentDiscountCode)
holder.bind(ticket, selectedListener, eventCurrency, eventTimeZone, qty, donation, currentDiscountCode, tax)
}

override fun getItemCount(): Int {
Expand Down
Loading