Skip to content

Commit

Permalink
feat: Customer Details
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijitramesh authored and therajanmaurya committed Jun 12, 2019
1 parent d10098d commit b5d2115
Show file tree
Hide file tree
Showing 87 changed files with 4,065 additions and 11 deletions.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<activity android:name=".ui.mifos.login.LoginActivity" />
<activity android:name=".ui.mifos.passcode.PasscodeActivity"/>
<activity android:name=".ui.mifos.loanApplication.loanActivity.LoanApplicationActivity"/>
<activity android:name=".ui.mifos.customerDetails.CustomerDetailsActivity"/>
<activity android:name=".ui.mifos.customerActivities.CustomerActivitiesActivity"/>
<activity android:name=".ui.mifos.identificationlist.IdentificationsActivity"/>
<activity android:name=".ui.mifos.viewScanCard.ViewScanCardActivity"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.mifos.mobile.cn.data.datamanager

import io.reactivex.Completable
import io.reactivex.Observable
import okhttp3.MultipartBody
import org.mifos.mobile.cn.data.models.customer.Command
import org.mifos.mobile.cn.data.models.customer.Customer
import org.mifos.mobile.cn.data.models.customer.identification.Identification
import org.mifos.mobile.cn.data.models.customer.identification.ScanCard

import org.mifos.mobile.cn.data.datamanager.contracts.ManagerCustomer
import org.mifos.mobile.cn.data.local.DatabaseHelperCustomer
import javax.inject.Inject


class DataManagerCustomer @Inject constructor(databaseHelperCustomer: DatabaseHelperCustomer) : ManagerCustomer {
var databaseHelperCustomer: DatabaseHelperCustomer = databaseHelperCustomer


override fun fetchCustomer(identifier: String): Observable<Customer> {
return databaseHelperCustomer.fetchCustomer(identifier)

}

override fun updateCustomer(customerIdentifier: String, customer: Customer?): Completable? {
return null
}



override fun customerCommand(identifier: String, command: Command): Completable? {
return null
}

override fun fetchCustomerCommands(customerIdentifier: String): Observable<MutableList<Command>>? {
return null
}

override fun fetchIdentifications(customerIdentifier: String): Observable<MutableList<Identification>>? {
return null
}

override fun createIdentificationCard(identifier: String, identification: Identification): Completable? {
return null
}

override fun updateIdentificationCard(customerIdentifier: String, identificationNumber: String, identification: Identification?): Completable? {
return null
}

override fun fetchIdentificationScanCards(customerIdentifier: String, identificationNumber: String): Observable<MutableList<ScanCard>>? {
return null
}

override fun uploadIdentificationCardScan(customerIdentifier: String, identificationNumber: String, scanIdentifier: String, description: String, file: MultipartBody.Part): Completable? {
return null
}

override fun deleteIdentificationCardScan(customerIdentifier: String, identificationNumber: String, scanIdentifier: String): Completable? {
return null
}

override fun deleteIdentificationCard(customerIdentifier: String, identificationnumber: String): Completable? {
return null
}

override fun uploadCustomerPortrait(customerIdentifier: String, file: MultipartBody.Part): Completable? {
return null
}

override fun deleteCustomerPortrait(customerIdentifier: String): Completable? {
return null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.mifos.mobile.cn.data.datamanager.contracts;

import org.mifos.mobile.cn.data.models.customer.Command;
import org.mifos.mobile.cn.data.models.customer.Customer;
import org.mifos.mobile.cn.data.models.customer.identification.Identification;
import org.mifos.mobile.cn.data.models.customer.identification.ScanCard;

import java.util.List;

import io.reactivex.Completable;
import io.reactivex.Observable;
import okhttp3.MultipartBody;

public interface ManagerCustomer {



Observable<Customer> fetchCustomer(String identifier);

Completable updateCustomer(String customerIdentifier, Customer customer);





Completable customerCommand(String identifier, Command command);

Observable<List<Command>> fetchCustomerCommands(String customerIdentifier);

Observable<List<Identification>> fetchIdentifications(String customerIdentifier);

Completable createIdentificationCard(String identifier, Identification identification);

Completable updateIdentificationCard(String customerIdentifier, String identificationNumber,
Identification identification);

Observable<List<ScanCard>> fetchIdentificationScanCards(String customerIdentifier,
String identificationNumber);

Completable uploadIdentificationCardScan(String customerIdentifier, String identificationNumber,
String scanIdentifier, String description,
MultipartBody.Part file);

Completable deleteIdentificationCardScan(String customerIdentifier, String identificationNumber,
String scanIdentifier);

Completable deleteIdentificationCard(String customerIdentifier, String identificationnumber);

Completable uploadCustomerPortrait(String customerIdentifier, MultipartBody.Part file);

Completable deleteCustomerPortrait(String customerIdentifier);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.mifos.mobile.cn.data.local

import com.raizlabs.android.dbflow.sql.language.SQLite.select
import org.mifos.mobile.cn.data.models.customer.Customer
import org.mifos.mobile.cn.data.models.customer.Customer_Table

import javax.inject.Inject


class DatabaseHelperCustomer @Inject constructor(){

fun fetchCustomer(identifier: String): io.reactivex.Observable<Customer> {
return io.reactivex.Observable.defer {
var customer = select()
.from(Customer::class.java)
.where(Customer_Table.identifier.eq(identifier))
.querySingle()
if (customer == null)
customer = Customer()
//else it will throw exception and will not go in the flatMap
io.reactivex.Observable.just(customer!!)
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.mifos.mobile.cn.data.models.customer

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import com.raizlabs.android.dbflow.annotation.ConflictAction
import com.raizlabs.android.dbflow.annotation.PrimaryKey
import com.raizlabs.android.dbflow.annotation.Table
import com.raizlabs.android.dbflow.structure.BaseModel
import kotlinx.android.parcel.Parcelize
import org.mifos.mobile.cn.local.MifosCnDatabase

@Parcelize
@Table(name = "Address", database = MifosCnDatabase::class, allFields = true, insertConflict =
ConflictAction.REPLACE)
data class Address(
@PrimaryKey
@SerializedName("street") var street: String? = null,
@PrimaryKey
@SerializedName("city") var city: String? = null,
@PrimaryKey
@SerializedName("region") var region: String? = null,
@SerializedName("postalCode") var postalCode: String? = null,
@SerializedName("countryCode") var countryCode: String? = null,
@SerializedName("country") var country: String? = null
) : BaseModel(), Parcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.mifos.mobile.cn.data.models.customer

import com.google.gson.annotations.SerializedName

data class Command(
@SerializedName("action") var action: Action? = null,
@SerializedName("comment") var comment: String? = null,
@SerializedName("createdOn") var createdOn: String? = null,
@SerializedName("createdBy") var createdBy: String? = null
) {
enum class Action {

@SerializedName("ACTIVATE")
ACTIVATE,

@SerializedName("LOCK")
LOCK,

@SerializedName("UNLOCK")
UNLOCK,

@SerializedName("CLOSE")
CLOSE,

@SerializedName("REOPEN")
REOPEN
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.mifos.mobile.cn.data.models.customer

import android.os.Parcelable

import com.google.gson.annotations.SerializedName
import com.raizlabs.android.dbflow.annotation.ConflictAction
import com.raizlabs.android.dbflow.annotation.ForeignKey
import com.raizlabs.android.dbflow.annotation.PrimaryKey
import com.raizlabs.android.dbflow.annotation.Table
import com.raizlabs.android.dbflow.structure.BaseModel
import kotlinx.android.parcel.Parcelize
import org.mifos.mobile.cn.local.MifosCnDatabase

@Parcelize
@Table(name = "ContactDetail", database = MifosCnDatabase::class, allFields = true, insertConflict =
ConflictAction.REPLACE, useBooleanGetterSetters = false)
data class ContactDetail(
@SerializedName("type") var type: Type? = null,
@SerializedName("value") var value: String? = null,
@SerializedName("preferenceLevel") var preferenceLevel: Int? = null,
@SerializedName("validated") var validated: Boolean? = null,
@SerializedName("group") var group: Group? = null
) : BaseModel(), Parcelable {

@PrimaryKey
@ForeignKey(stubbedRelationship = true) var customer: Customer? = null

enum class Type {
@SerializedName("EMAIL")
EMAIL,

@SerializedName("PHONE")
PHONE,

@SerializedName("MOBILE")
MOBILE
}

enum class Group {

@SerializedName("BUSINESS")
BUSINESS,

@SerializedName("PRIVATE")
PRIVATE
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.mifos.mobile.cn.data.models.customer

import com.google.gson.annotations.SerializedName

/**
* @author Rajan Maurya
* On 26/07/17.
*/

data class Country(
@SerializedName("translations") var translations: Translations,
@SerializedName("name") var name: String,
@SerializedName("alpha2Code") var alphaCode: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.mifos.mobile.cn.data.models.customer

import android.os.Parcelable

import com.google.gson.annotations.SerializedName
import com.raizlabs.android.dbflow.annotation.*
import com.raizlabs.android.dbflow.sql.language.SQLite.select
import com.raizlabs.android.dbflow.structure.BaseModel
import kotlinx.android.parcel.Parcelize
import org.mifos.mobile.cn.data.models.customer.ContactDetail_Table
import org.mifos.mobile.cn.local.MifosCnDatabase

@Parcelize
@Table(database = MifosCnDatabase::class, useBooleanGetterSetters = false)
data class Customer(
@PrimaryKey
@Column var identifier: String? = null,
@Column var type: String? = null,
@Column var givenName: String? = null,
@Column var middleName: String? = null,
@Column var surname: String? = null,
@ForeignKey(saveForeignKeyModel = true)
@Column var dateOfBirth: DateOfBirth? = null,
@Column var member: Boolean? = null,
@Column var accountBeneficiary: String? = null,
@Column var referenceCustomer: String? = null,
@Column var assignedOffice: String? = null,
@Column var assignedEmployee: String? = null,
@ForeignKey(saveForeignKeyModel = true)
@Column var address: Address? = null,
var contactDetails: List<ContactDetail>? = null,
@Column var currentState: State? = null,
@Column var createdBy: String? = null,
@Column var createdOn: String? = null,
@Column var lastModifiedBy: String? = null,
@Column var lastModifiedOn: String? = null
) : BaseModel(), Parcelable {

var isUpdate: Boolean? = null

@OneToMany(methods = arrayOf(OneToMany.Method.ALL), variableName = "contactDetails")
fun getContactDetail() : List<ContactDetail>? {
contactDetails = select()
.from(ContactDetail::class.java)
.where(ContactDetail_Table.customer_identifier.eq(identifier))
.queryList()
return contactDetails
}

enum class Type {

@SerializedName("PERSON")
PERSON,

@SerializedName("BUSINESS")
BUSINESS
}

enum class State {

@SerializedName("PENDING")
PENDING,

@SerializedName("ACTIVE")
ACTIVE,

@SerializedName("LOCKED")
LOCKED,

@SerializedName("CLOSED")
CLOSED
}

override fun save(): Boolean {
val res = super.save()
if (contactDetails != null) {
contactDetails!!.forEach {
it.customer = this
it.save()
}
}
return res
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.mifos.mobile.cn.data.models.customer

import com.google.gson.annotations.SerializedName

data class CustomerPage(
@SerializedName("customers") var customers: List<Customer>? = null,
@SerializedName("totalPages") var totalPages: Int? = null,
@SerializedName("totalElements") var totalElements: Long? = null
)
Loading

0 comments on commit b5d2115

Please sign in to comment.