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
7 changes: 5 additions & 2 deletions app/src/main/assets/pages/Policy.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
<script src="../JS/jquery-3.2.1.min.js"></script>
<script src="../JS/exact.js"></script>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" charset="utf-8"/>

<link href="../CSS/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="../JS/jquery-ui.js"></script>
<script type="text/javascript" src="Policy.js"></script>

</head>
<body>

<div id="dialog-confirm" title="Confirm" style="display:none;">
<p><span id="msgAlert" class="ui-icon-alert" style="float:left; margin:2px 2px 2px 0;"></span></p>
</div>
<div>
<ul class="ulEntry">
<li>
Expand Down
46 changes: 36 additions & 10 deletions app/src/main/assets/pages/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ $(document).ready(function () {
$('#ControlNumber').hide();
}

$("#dialog-confirm").attr("title", Android.getString('Confirm'));

var LocationId = parseInt(queryString("l"));
var FamilyId = parseInt(queryString("f"));
var strOfficerLocation = Android.getOfficerLocation();
Expand Down Expand Up @@ -45,9 +47,9 @@ $(document).ready(function () {

if(Android.IsBulkCNUsed()) {
if($Policy[0]["ControlNumber"]) {
$('#AssignedControlNumber').val($Policy[0]["ControlNumber"]).prop('readonly', true);
$('#AssignedControlNumber').val($Policy[0]["ControlNumber"]);
} else {
$('#AssignedControlNumber').val('').prop('readonly', false);
$('#AssignedControlNumber').val('');
}
}

Expand Down Expand Up @@ -92,33 +94,57 @@ $(document).ready(function () {
if(Android.IsBulkCNUsed()) {
var productId = $('#ddlProduct').val();
if(productId == '0') {
$('#AssignedControlNumber').val('').prop('readonly', false);
$('#AssignedControlNumber').val('');
return;
}
var controlNumber = Android.GetNextBulkCn(productId);
if(typeof controlNumber === 'undefined') {
Android.ShowDialog(Android.getString('noBulkCNAvailable'));
$('#AssignedControlNumber').val('').prop('readonly', false);
$('#AssignedControlNumber').val('');
} else {
$('#AssignedControlNumber').val(controlNumber).prop('readonly', true);
$('#AssignedControlNumber').val(controlNumber);
}
}
});

function savePolicy() {
var jsonPolicy = createJSONString();
var PPolicyId = Android.SavePolicy(jsonPolicy, parseInt(FamilyId), parseInt(policyId));
window.open('FamilyPolicies.html?f=' + FamilyId + '&l=' + LocationId + '&r=' + RegionId + '&d=' + DistrictId, "_self");
$('#btnSave').attr("disabled", "disabled")
}

$('#btnSave').click(function () {
var passed = isFormValidated();
var jsonPolicy = createJSONString();

if (passed == true) {
if(Android.IsBulkCNUsed() && !$('#AssignedControlNumber').val()) {
Android.ShowDialog(Android.getString('noBulkCNAssigned'));
$('#AssignedControlNumber').val('').prop('readonly', false);
$('#AssignedControlNumber').val('');
return;
}

var PPolicyId = Android.SavePolicy(jsonPolicy, parseInt(FamilyId), parseInt(policyId));
window.open('FamilyPolicies.html?f=' + FamilyId + '&l=' + LocationId + '&r=' + RegionId + '&d=' + DistrictId, "_self");
$('#btnSave').attr("disabled", "disabled")
if(Android.IsBulkCNUsed() && !Android.isFetchedControlNumber($('#AssignedControlNumber').val())) {
$("#msgAlert").text(Android.getStringWithArgument('ConfirmControlNumber', $('#AssignedControlNumber').val()));
$("#dialog-confirm").dialog({
resizable: false,
height: "auto",
width: 300,
modal: true,
buttons: {
Yes: function () {
savePolicy();
$(this).dialog("close");
},
No: function () {
$(this).dialog("close");
}
}
});
}
else {
savePolicy()
}
}
else {
Android.ShowDialog(Android.getString('FieldRequired'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,17 @@ public String getString(String str) {
return "";
}

@JavascriptInterface
public String getStringWithArgument(String str, String arg) {
try {
Resources resources = mContext.getResources();
return resources.getString(resources.getIdentifier(str, "string", mContext.getPackageName()), arg);
} catch (Resources.NotFoundException e) {
Log.e("RESOURCES", String.format("Resource \"%s\" not found", str), e);
}
return "";
}


@JavascriptInterface
public boolean isValidInsuranceNumber(String InsuranceNumber) {
Expand Down Expand Up @@ -1788,6 +1799,11 @@ public void deleteBulkCn(String controlNumber) {
sqlHandler.deleteData("tblBulkControlNumbers", "ControlNumber = ?", new String[]{controlNumber});
}

@JavascriptInterface
public boolean isFetchedControlNumber(String controlNumber) {
return sqlHandler.isFetchedControlNumber(controlNumber);
}

@JavascriptInterface
public int SavePolicy(String PolicyData, int FamilyId, int PolicyId) throws Exception {
inProgress = true;
Expand Down
45 changes: 18 additions & 27 deletions app/src/main/java/org/openimis/imispolicies/Renewal.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
Expand Down Expand Up @@ -172,8 +171,6 @@ protected void onCreate(Bundle savedInstanceState) {

btnSubmit.setOnClickListener(v -> {
if (!chkDiscontinue.isChecked()) {

pd = ProgressDialog.show(Renewal.this, "", getResources().getString(R.string.Uploading));
final String[] renewal = {null};

if (getIntent().getStringExtra("CHFID").equals(getResources().getString(R.string.UnlistedRenewalPolicies))) {
Expand All @@ -185,36 +182,24 @@ protected void onCreate(Bundle savedInstanceState) {
return;
}

new Thread(() -> {
Runnable saveRenewal = () -> new Thread(() -> {
renewal[0] = WriteJSON();
WriteXML();
result = 3;

runOnUiThread(() -> {
UpdateRow(RenewalId);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.SavedOnSDCard), Toast.LENGTH_LONG).show();

switch (result) {
case 1:
DeleteRow(RenewalId);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.UploadedSuccessfully), Toast.LENGTH_LONG).show();
break;
case 2:
DeleteRow(RenewalId);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.ServerRejected), Toast.LENGTH_LONG).show();
break;
case 3:
UpdateRow(RenewalId);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.SavedOnSDCard), Toast.LENGTH_LONG).show();
break;
case -1:
Toast.makeText(getApplicationContext(), getResources().getString(R.string.RenewalNotUploaded), Toast.LENGTH_LONG).show();
break;
}
//Go back to the previous activity.
finish();
});

pd.dismiss();
}).start();

if (ca.IsBulkCNUsed() && !ca.isFetchedControlNumber(etControlNumber.getText().toString())) {
ConfirmControlNumber(saveRenewal);
} else {
saveRenewal.run();
}
}
});

Expand Down Expand Up @@ -427,6 +412,15 @@ private void DiscontinuePolicy() {
.setNegativeButton(R.string.No, (dialog, which) -> chkDiscontinue.setChecked(false)).show();
}

private void ConfirmControlNumber(Runnable onConfirmed) {
String message = getResources().getString(R.string.ConfirmControlNumber, etControlNumber.getText().toString());
new AlertDialog.Builder(this)
.setMessage(message)
.setPositiveButton(R.string.Yes, (dialog, which) -> onConfirmed.run())
.setNegativeButton(R.string.No, (dialog, which) -> {
}).show();
}

private void UpdateRow(int RenewalId) {
if (RenewalId != 0) {
ca.UpdateRenewTable(RenewalId);
Expand Down Expand Up @@ -647,15 +641,12 @@ private void assignNextFreeCn(String productCode) {
String controlNumber = sqlHandler.getNextFreeCn(etOfficer.getText().toString(), productCode);
if (controlNumber != null) {
etControlNumber.setText(controlNumber);
setEditable(etControlNumber, false);
} else {
showInfoDialog(R.string.noBulkCNAvailable);
etControlNumber.setText("");
setEditable(etControlNumber, true);
}
} else {
etControlNumber.setText("");
setEditable(etControlNumber, true);
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,5 @@
<string name="ControlNumberError">Control number error</string>
<string name="UnexpectedException">Unexpected exception</string>
<string name="InvalidRenewalFile">Invalid renewal file</string>
<string name="ConfirmControlNumber">Control number \"%1$s\" is not present in phone memory. Please confirm that this control number is correct.</string>
</resources>