Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #20
Browse files Browse the repository at this point in the history
Add Collector Backend
  • Loading branch information
MichaelSafwatHanna authored Oct 31, 2019
2 parents 3a5a20a + 48e7361 commit 430dca1
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
22 changes: 14 additions & 8 deletions app/src/main/java/com/tazkrtak/staff/activities/ScannerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.app.AlertDialog
import android.app.Dialog
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.Gravity
import android.view.KeyEvent
import android.view.View
import android.widget.Toast
Expand All @@ -17,10 +18,7 @@ import com.journeyapps.barcodescanner.BarcodeCallback
import com.journeyapps.barcodescanner.BarcodeResult
import com.journeyapps.barcodescanner.DecoratedBarcodeView
import com.tazkrtak.staff.R
import com.tazkrtak.staff.models.Account
import com.tazkrtak.staff.models.Conductor
import com.tazkrtak.staff.models.TaskResult
import com.tazkrtak.staff.models.Ticket
import com.tazkrtak.staff.models.*
import com.tazkrtak.staff.util.Auth
import kotlinx.android.synthetic.main.activity_scanner.*
import kotlinx.android.synthetic.main.repeated_transaction_daialog_box.view.*
Expand Down Expand Up @@ -48,6 +46,10 @@ class ScannerActivity : Activity(), DecoratedBarcodeView.TorchListener, Coroutin
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
actionBar?.hide()

if (Auth.currentUser!!.type == Account.Type.COLLECTOR) {
qr_status_icon.isGone = true
}

dialog = Dialog(this)
repeatedTransactionDialogView =
layoutInflater.inflate(R.layout.repeated_transaction_daialog_box, null)
Expand Down Expand Up @@ -128,6 +130,8 @@ class ScannerActivity : Activity(), DecoratedBarcodeView.TorchListener, Coroutin
barcode_scanner.resume()
}

} else if (taskResult.messageId == Collector.MESSAGE_ID) {
barcode_scanner.setStatusText(taskResult.details)
} else {
barcode_scanner.setStatusText(taskResult.message)
qr_status_icon.setImageResource(
Expand All @@ -136,7 +140,7 @@ class ScannerActivity : Activity(), DecoratedBarcodeView.TorchListener, Coroutin
)
}
}

}

override fun possibleResultPoints(resultPoints: List<ResultPoint>) {}
Expand Down Expand Up @@ -171,9 +175,11 @@ class ScannerActivity : Activity(), DecoratedBarcodeView.TorchListener, Coroutin
}

private fun getSelectedTicketPrice(): Double {
val conductor = Auth.currentUser as Conductor
val prices = conductor.bus?.ticketsPrices!!
return prices[price_picker.value]
return if (Auth.currentUser!!.type == Account.Type.CONDUCTOR) {
val conductor = Auth.currentUser as Conductor
val prices = conductor.bus?.ticketsPrices!!
prices[price_picker.value]
} else 0.0
}


Expand Down
38 changes: 37 additions & 1 deletion app/src/main/java/com/tazkrtak/staff/models/Collector.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package com.tazkrtak.staff.models

import com.tazkrtak.staff.App
import com.tazkrtak.staff.R
import com.tazkrtak.staff.repositories.BusRepository
import com.tazkrtak.staff.repositories.ClientRepository
import com.tazkrtak.staff.repositories.TransactionRepository
import java.util.concurrent.TimeUnit

data class Collector(
override val id: String? = null,
override val name: String? = null,
Expand All @@ -9,11 +16,40 @@ data class Collector(
override val type: Account.Type = Account.Type.COLLECTOR

override suspend fun executeTask(ticket: Ticket, extra: Map<String, Any>): TaskResult {
TODO("not implemented")

val client = ClientRepository.get(ticket.userNationalId!!)
?: return TaskResult(R.string.id_error)

if (client.lastTransactionId != "") {
val lastTransaction = TransactionRepository.get(client.lastTransactionId!!)

val bus = BusRepository.get(lastTransaction!!.issuer!!)
if (bus != null) {
return TaskResult(
MESSAGE_ID,
"${getMessage(R.string.issuer)}: ${bus.number}\n" +
"${getMessage(R.string.amount)}: ${lastTransaction.amount}\n" +
"${getMessage(R.string.since)}: ${TimeUnit.SECONDS.toMinutes(
lastTransaction.timeSinceCreation
)} " +
getMessage(R.string.minute)
)
}
}

return TaskResult(MESSAGE_ID, getMessage(R.string.no_transaction), isSuccess = false)
}

override fun makeTransaction(clientNationalId: String, amount: Double) {
TODO("not implemented")
}

private fun getMessage(id: Int): String {
return App.appContext!!.getString(id)
}

companion object {
const val MESSAGE_ID = 101
}

}
5 changes: 5 additions & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@
<string name="help">المساعدة</string>
<string name="transaction_repeated_notation">لقد أجرى هذا العميل معاملة ناجحة في هذه الحافلة في:</string>
<string name="ticket_count">عدد التذاكر المباعة اليوم:</string>
<string name="issuer">جهة الإصدار</string>
<string name="amount">القيمة</string>
<string name="since">منذ</string>
<string name="minute">دقيقة</string>
<string name="no_transaction">لا يوجد عملية ناجحة...</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@
<string name="help">Help</string>
<string name="transaction_repeated_notation">This Client has made a successful transaction from this bus at:</string>
<string name="ticket_count">Today\'s ticket count:</string>
<string name="issuer">Issuer</string>
<string name="amount">Amount</string>
<string name="since">Since</string>
<string name="minute">min.</string>
<string name="no_transaction">No Transaction Found...</string>
</resources>

0 comments on commit 430dca1

Please sign in to comment.