
<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" controllerName="qrcode.qrcode.controller.View1"
xmlns:html="http://www.w3.org/1999/xhtml">
<App id="app">
<pages>
<Page id="page" title="Employee Attendance">
<content>
<Button text="Scan" press="onBarcodeScan" icon="sap-icon://bar-code"/>
<Panel backgroundDesign="Transparent">
<Table id="Employee" items="{/daf_empattSet}">
<headerToolbar>
<Toolbar>
<Title text="{i18n>Employee Attendence Details}"/>
<ToolbarSpacer/>
<SearchField placeholder="Search By Name" width="50%" liveChange="onFilterInvoices1" search="onFilterInvoices"/>
</Toolbar>
</headerToolbar>
<items>
<ColumnListItem>
<cells>
<Text text="{Srno}"></Text>
<Text text="{Dinkid}"></Text>
<Text text="{path: 'Tdate', type:'sap.ui.model.type.Date', formatOptions : { pattern:'dd.MM.yyyy'}}"/>
<Text text="{path: 'Entrytime', type:'sap.ui.model.odata.type.Time', formatOptions: {pattern: 'HH:mm:ss'}}"/>
<Text text="{path: 'Exittime', type:'sap.ui.model.odata.type.Time', formatOptions: {pattern: 'HH:mm:ss'}}"/>
<Text text="{path: 'Totalhrs', type:'sap.ui.model.odata.type.Time', formatOptions: {pattern: 'HH:mm:ss'}}"/>
<Text text="{Latehrs}"></Text>
</cells>
</ColumnListItem>
</items>
<columns>
<Column>
<Text text="Srno"></Text>
</Column>
<Column>
<Text id="Dinkid" text="Dinkid"></Text>
</Column>
<Column>
<Text text="Date"></Text>
</Column>
<Column>
<Text id="Entrytime1" text="In Time"></Text>
</Column>
<Column>
<Text id="Exittime2" text="Out Time"></Text>
</Column>
<Column>
<Text text="Total Hours"></Text>
</Column>
<Column>
<Text id="Latehrs3" text="Latehrs"></Text>
</Column>
</columns>
</Table>
</Panel>
</content>
</Page>
</pages>
</App>
</core:View>
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ndc/BarcodeScanner",
"sap/ui/model/Filter",
"sap/ui/model/FilterOperator"
], function (Controller, BarcodeScanner, Filter, FilterOperator) {
"use strict";
var ServiceUrl = "";
var oModel = new sap.ui.model.odata.ODataModel(ServiceUrl);
return Controller.extend("qrcode.qrcode.controller.View1", {
onInit: function () {
},
onBarcodeScan: function () {
var dinkid;
var that = this;
var code = "";
if (!cordova.plugins.barcodeScanner) {
alert("Barcode scanning not supported");
return;
}
cordova.plugins.barcodeScanner.scan(
function (result) {
if (result.format == "QR_CODE") {
code = result.text;
dinkid = result.text.split(" ")[2];
oModel.read("/daf_empmasterSet", null, null, true, function (oData, response) {
for (var i = 0; i < response.data.results.length; i++) {
var mdinkid = response.data.results[i].Dinkid;
if (dinkid === mdinkid) {
var Srno1 = response.data.results[i].Srno;
var Dinkid1 = response.data.results[i].Dinkid;
that.updateModel(Srno1, Dinkid1);
}
}
});
that.getView().byId("searchField").setValue(code);
that.onSearch();
}
},
function (error) {
alert("Scan failed: " + error);
},
{
preferFrontCamera: true, // iOS and Android
showFlipCameraButton: true, // iOS and Android
showTorchButton: true, // iOS and Android
torchOn: true, // Android, launch with the torch switched on (if available)
saveHistory: true, // Android, save scan history (default false)
prompt: "Place a barcode inside the scan area", // Android
resultDisplayDuration: 500, // Android, display scanned text for X ms. 0 suppresses it entirely, default 1500
formats: "QR_CODE,PDF_417", // default: all but PDF_417 and RSS_EXPANDED
orientation: "landscape", // Android only (portrait|landscape), default unset so it rotates with the device
disableAnimations: true, // iOS
disableSuccessBeep: false // iOS and Android
}
);
},
updateModel: function (Srno1, Dinkid1) {
var oTable = this.byId("Employee");
var Tdate = new Date();
var dateFormat = sap.ui.core.format.DateFormat.getInstance({
pattern: "yyyy-MM-ddThh:mm:ss"
});
var Tdate1 = dateFormat.format(new Date(Tdate));
/* var EntryTime1 = Tdate.toTimeString().split(" ")[0];
var tdateFormat = sap.ui.model.odata.type.Time({
pattern: "HH:mm:ss"
});
var EntryTime = tdateFormat.format(Tdate);*/
var timeFormat = sap.ui.core.format.DateFormat.getTimeInstance({
pattern: "'PT'HH'H'mm'M'ss'S'"
});
var EntryTime = timeFormat.format(Tdate);
var oEntry = {
"Srno": Srno1,
"Dinkid": Dinkid1,
"Tdate": Tdate1,
"Entrytime": EntryTime,
"Exittime": EntryTime,
// "Totalhrs": EntryTime,
"Latehrs": "X"
};
oModel.update("/daf_empattSet(Srno='" + Srno1 + "')",
oEntry, {
method: "PUT",
success: function (oData, oResponse) {
oTable.getModel().refresh();
oTable.getBinding("items").refresh(true);
sap.m.MessageToast.show("Successfully Scanned");
},
error: function (err, oResponse) {
sap.m.MessageToast.show("Somthing is Wrong.");
}
});
},
onFilterInvoices: function (oEvent) {
// build filter array
var aFilter = [];
var sQuery = oEvent.getParameter("query").toUpperCase();
if (sQuery) {
aFilter.push(new Filter("Dinkid", FilterOperator.Contains, sQuery));
}
// filter binding
var oList = this.getView().byId("Employee");
var oBinding = oList.getBinding("items");
oBinding.filter(aFilter);
},
onFilterInvoices1: function (oEvent) {
// build filter array
var aFilter = [];
var sQuery = oEvent.getParameters().newValue.toUpperCase();
if (sQuery) {
aFilter.push(new Filter("Dinkid", FilterOperator.Contains, sQuery));
}
// filter binding
var oList = this.getView().byId("Employee");
var oBinding = oList.getBinding("items");
oBinding.filter(aFilter);
}
});
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
9 | |
8 | |
6 | |
6 | |
5 | |
5 | |
5 | |
5 |