From ee7cdee9d55478e3f0980f447215bb39a89277fa Mon Sep 17 00:00:00 2001
From: Muhammad Tufail <64038226+CoderBee1@users.noreply.github.com>
Date: Mon, 22 Feb 2021 00:03:28 +0500
Subject: [PATCH] Add files via upload
---
MyHCM Book.ipynb | 2350 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 2350 insertions(+)
create mode 100644 MyHCM Book.ipynb
diff --git a/MyHCM Book.ipynb b/MyHCM Book.ipynb
new file mode 100644
index 0000000..3e94b92
--- /dev/null
+++ b/MyHCM Book.ipynb
@@ -0,0 +1,2350 @@
+{
+ "metadata": {
+ "kernelspec": {
+ "name": "SQL",
+ "display_name": "SQL",
+ "language": "sql"
+ },
+ "language_info": {
+ "name": "sql",
+ "version": ""
+ }
+ },
+ "nbformat_minor": 2,
+ "nbformat": 4,
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Employee which have more than 1 Leaves and more than 3 lates"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "9c372ce0-1feb-4101-969a-800231621698"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "select EmployeeCode from MI_ONTIME_Attendance where Late>0\r\n",
+ "and EmployeeCode in (select distinct EmployeeCode from MI_ONTIME_Leave where Year(StartDate)=2020 and month(StartDate)=12)\r\n",
+ "group by EmployeeCode\r\n",
+ "having count(EmployeeCode)>3\r\n",
+ "\r\n",
+ "select * from MI_ONTIME_Leave where Year(StartDate)=2020 and month(StartDate)=12 and EmployeeCode=10\r\n",
+ "select * from MI_ONTIME_Attendance where Late>0 and EmployeeCode=11"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "9c73c12c-2f90-4515-a20f-cb3d437391f3"
+ },
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Check Attendance by number"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "63bf1bc2-2edc-407a-b2c1-12f80227e692"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "SELECT *\r\n",
+ "FROM [dbo].[mi_ontime_attendance]\r\n",
+ "WHERE employeecode in (SELECT employeecode\r\n",
+ "from MI_Employer_Employee\r\n",
+ "where number in ('000328') ) and (intime !='1901-01-01 00:00:00.000' or outtime !='1901-01-01 00:00:00.000')\r\n",
+ "and date>'2021-01-01'\r\n",
+ "order by employeecode,date\r\n",
+ "\r\n",
+ "select * from MI_ONTIME_Attendance where date > '2021-02-01' and (InTime!='1901-01-01 00:00:00.000' or OutTime!='1901-01-01 00:00:00.000') and EmployeeCode=96\r\n",
+ "select * from MI_ONTIME_backLog where Location='' order by CreatedDate desc\r\n",
+ "select TextCardNumber, number, EmployeeCode from MI_Employer_Employee where TextCardNumber='10029'\r\n",
+ "\r\n",
+ "select getdate()"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "5e9f1f40-3294-4cd1-a0b4-f6791a283f9e"
+ },
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Attendance Count in a spacifc date"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "07630345-9ecd-4c70-a450-f62c43e72aca"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "select count(*) from MI_ONTIME_Attendance where (InTime !='1901-01-01 00:00:00.000' or OutLate!='1901-01-01 00:00:00.000') \r\n",
+ "and EmployeeCode in (select distinct EmployeeCode from MI_Employer_Employee where Level2Code=1 )\r\n",
+ "and date='2021-01-26'"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "9b9d5f54-4506-49ca-b880-6df7ac06bcab",
+ "tags": [
+ "hide_input"
+ ]
+ },
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Insert and update LeaveType"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "80de17c7-0c0d-433f-9b00-6194bfdfb256"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "select top 1 * from MI_ONTIME_LeaveType\r\n",
+ "-- update MI_ONTIME_LeaveType set SystemLeaveTypeCode='SPS' where LeaveTypeCode=7\r\n",
+ "-- insert into MI_ONTIME_LeaveType values ('Special Sick','SpS',1,0,0,0,0,0,0,0,0,1,1,getdate(),0,'1901-01-01 00:00:00.000',0,'1901-01-01 00:00:00.000')\r\n",
+ "MI_ONTIME_LeaveAllocation"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "90b03724-7f83-48ce-a3a3-b8f89e971fd4",
+ "tags": []
+ },
+ "outputs": [
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/html": "(1 row affected)"
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/html": "Total execution time: 00:00:00.415"
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "execute_result",
+ "execution_count": 1,
+ "data": {
+ "application/vnd.dataresource+json": {
+ "schema": {
+ "fields": [
+ {
+ "name": "LeaveTypeCode"
+ },
+ {
+ "name": "LeaveTypeName"
+ },
+ {
+ "name": "SystemLeaveTypeCode"
+ },
+ {
+ "name": "PaidLeaveType"
+ },
+ {
+ "name": "PayAllowance"
+ },
+ {
+ "name": "LeavePayment"
+ },
+ {
+ "name": "Unlimited"
+ },
+ {
+ "name": "PayCutEffect"
+ },
+ {
+ "name": "AttAllowEffect"
+ },
+ {
+ "name": "NeedCovering"
+ },
+ {
+ "name": "NeedAttachment"
+ },
+ {
+ "name": "Deleted"
+ },
+ {
+ "name": "Status"
+ },
+ {
+ "name": "CreatedBy"
+ },
+ {
+ "name": "CreatedDate"
+ },
+ {
+ "name": "UpdatedBy"
+ },
+ {
+ "name": "UpdatedDate"
+ },
+ {
+ "name": "DeletedBy"
+ },
+ {
+ "name": "DeletedDate"
+ }
+ ]
+ },
+ "data": [
+ {
+ "0": "1",
+ "1": "Annual Leave",
+ "2": "ANN",
+ "3": "1",
+ "4": "0",
+ "5": "0",
+ "6": "0",
+ "7": "0",
+ "8": "0",
+ "9": "0",
+ "10": "0",
+ "11": "0",
+ "12": "1",
+ "13": "1",
+ "14": "2020-06-10 08:45:02.923",
+ "15": "1",
+ "16": "2020-12-01 07:41:42.823",
+ "17": "0",
+ "18": "1901-01-01 00:00:00.000"
+ }
+ ]
+ },
+ "text/html": "
| LeaveTypeCode | LeaveTypeName | SystemLeaveTypeCode | PaidLeaveType | PayAllowance | LeavePayment | Unlimited | PayCutEffect | AttAllowEffect | NeedCovering | NeedAttachment | Deleted | Status | CreatedBy | CreatedDate | UpdatedBy | UpdatedDate | DeletedBy | DeletedDate |
|---|
| 1 | Annual Leave | ANN | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 2020-06-10 08:45:02.923 | 1 | 2020-12-01 07:41:42.823 | 0 | 1901-01-01 00:00:00.000 |
"
+ },
+ "metadata": {
+ "resultSet": {
+ "id": 0,
+ "batchId": 0,
+ "rowCount": 1,
+ "complete": false,
+ "columnInfo": [
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 8,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": false,
+ "allowDBNull": false,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "LeaveTypeCode",
+ "columnOrdinal": 0,
+ "columnSize": 4,
+ "isAliased": null,
+ "isAutoIncrement": true,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": true,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": true,
+ "isUnique": false,
+ "numericPrecision": 10,
+ "numericScale": 255,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "int"
+ },
+ {
+ "isBytes": false,
+ "isChars": true,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 12,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": true,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "LeaveTypeName",
+ "columnOrdinal": 1,
+ "columnSize": 50,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 255,
+ "numericScale": 255,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "nvarchar"
+ },
+ {
+ "isBytes": false,
+ "isChars": true,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 22,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": false,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "SystemLeaveTypeCode",
+ "columnOrdinal": 2,
+ "columnSize": 5,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 255,
+ "numericScale": 255,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "varchar"
+ },
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 2,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": false,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "PaidLeaveType",
+ "columnOrdinal": 3,
+ "columnSize": 1,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 255,
+ "numericScale": 255,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "bit"
+ },
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 2,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": false,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "PayAllowance",
+ "columnOrdinal": 4,
+ "columnSize": 1,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 255,
+ "numericScale": 255,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "bit"
+ },
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 13,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": false,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "LeavePayment",
+ "columnOrdinal": 5,
+ "columnSize": 4,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 7,
+ "numericScale": 255,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.Single, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "real"
+ },
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 2,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": false,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "Unlimited",
+ "columnOrdinal": 6,
+ "columnSize": 1,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 255,
+ "numericScale": 255,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "bit"
+ },
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 2,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": false,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "PayCutEffect",
+ "columnOrdinal": 7,
+ "columnSize": 1,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 255,
+ "numericScale": 255,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "bit"
+ },
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 2,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": false,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "AttAllowEffect",
+ "columnOrdinal": 8,
+ "columnSize": 1,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 255,
+ "numericScale": 255,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "bit"
+ },
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 2,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": false,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "NeedCovering",
+ "columnOrdinal": 9,
+ "columnSize": 1,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 255,
+ "numericScale": 255,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "bit"
+ },
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 2,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": false,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "NeedAttachment",
+ "columnOrdinal": 10,
+ "columnSize": 1,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 255,
+ "numericScale": 255,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "bit"
+ },
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 2,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": false,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "Deleted",
+ "columnOrdinal": 11,
+ "columnSize": 1,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 255,
+ "numericScale": 255,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "bit"
+ },
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 2,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": false,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "Status",
+ "columnOrdinal": 12,
+ "columnSize": 1,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 255,
+ "numericScale": 255,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "bit"
+ },
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 8,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": true,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "CreatedBy",
+ "columnOrdinal": 13,
+ "columnSize": 4,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 10,
+ "numericScale": 255,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "int"
+ },
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 4,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": true,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "CreatedDate",
+ "columnOrdinal": 14,
+ "columnSize": 8,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 23,
+ "numericScale": 3,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.DateTime, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "datetime"
+ },
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 8,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": true,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "UpdatedBy",
+ "columnOrdinal": 15,
+ "columnSize": 4,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 10,
+ "numericScale": 255,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "int"
+ },
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 4,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": true,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "UpdatedDate",
+ "columnOrdinal": 16,
+ "columnSize": 8,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 23,
+ "numericScale": 3,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.DateTime, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "datetime"
+ },
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 8,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": true,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "DeletedBy",
+ "columnOrdinal": 17,
+ "columnSize": 4,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 10,
+ "numericScale": 255,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "int"
+ },
+ {
+ "isBytes": false,
+ "isChars": false,
+ "isSqlVariant": false,
+ "isUdt": false,
+ "isXml": false,
+ "isJson": false,
+ "sqlDbType": 4,
+ "isHierarchyId": false,
+ "isSqlXmlType": false,
+ "isUnknownType": false,
+ "isUpdatable": true,
+ "allowDBNull": true,
+ "baseCatalogName": null,
+ "baseColumnName": null,
+ "baseSchemaName": null,
+ "baseServerName": null,
+ "baseTableName": null,
+ "columnName": "DeletedDate",
+ "columnOrdinal": 18,
+ "columnSize": 8,
+ "isAliased": null,
+ "isAutoIncrement": false,
+ "isExpression": null,
+ "isHidden": null,
+ "isIdentity": false,
+ "isKey": null,
+ "isLong": false,
+ "isReadOnly": false,
+ "isUnique": false,
+ "numericPrecision": 23,
+ "numericScale": 3,
+ "udtAssemblyQualifiedName": null,
+ "dataType": "System.DateTime, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
+ "dataTypeName": "datetime"
+ }
+ ],
+ "specialAction": null
+ },
+ "azdata_chartOptions": {
+ "type": "bar",
+ "dataDirection": "horizontal",
+ "columnsAsLabels": true,
+ "labelFirstColumn": false,
+ "legendPosition": "top"
+ }
+ }
+ }
+ ],
+ "execution_count": 1
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Create LeaveAllocation BackUp and Insert"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "2662c0ad-2272-44c0-98c0-0fbf52232d04"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "\r\n",
+ "CREATE TABLE [dbo].[MI_ONTIME_LeaveAllocation_bak](\r\n",
+ "\t[LeaveAllocationCode] [int] IDENTITY(1,1) NOT NULL,\r\n",
+ "\t[LeaveTypeCode] [int] NOT NULL,\r\n",
+ "\t[EmployeeCode] [int] NOT NULL,\r\n",
+ "\t[LeaveYear] [int] NOT NULL,\r\n",
+ "\t[Allocated] [real] NOT NULL,\r\n",
+ "\t[Used] [real] NOT NULL,\r\n",
+ "\t[Deleted] [bit] NOT NULL,\r\n",
+ "\t[Status] [bit] NOT NULL,\r\n",
+ "\t[CreatedBy] [int] NULL,\r\n",
+ "\t[CreatedDate] [datetime] NULL,\r\n",
+ "\t[UpdatedBy] [int] NULL,\r\n",
+ "\t[UpdatedDate] [datetime] NULL,\r\n",
+ "\t[DeletedBy] [int] NULL,\r\n",
+ "\t[DeletedDate] [datetime] NULL\r\n",
+ " )\r\n",
+ "\r\n",
+ "Go\r\n",
+ "\r\n",
+ "insert into [MI_ONTIME_LeaveAllocation_bak]\r\n",
+ "SELECT [LeaveTypeCode]\r\n",
+ " ,[EmployeeCode]\r\n",
+ " ,[LeaveYear]\r\n",
+ " ,[Allocated]\r\n",
+ " ,[Used]\r\n",
+ " ,[Deleted]\r\n",
+ " ,[Status]\r\n",
+ " ,[CreatedBy]\r\n",
+ " ,[CreatedDate]\r\n",
+ " ,[UpdatedBy]\r\n",
+ " ,[UpdatedDate]\r\n",
+ " ,[DeletedBy]\r\n",
+ " ,[DeletedDate]\r\n",
+ " FROM [dbo].[MI_ONTIME_LeaveAllocation]"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "7ddfaa5f-a458-44ef-b4ed-53ecadfb52f4"
+ },
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "update employement type by excel"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "f49b4177-98cb-4bf7-b4e0-e93bd2ff95aa"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "update MI_Employer_Employee set EmploymentTypeCode=1 where employeecode in (select employeecode from MI_Employer_Employee where Number='' and Deleted=0) and Deleted=0"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "5bc80fdc-2690-47e2-9614-b37f58993409"
+ },
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Cloud Payproll Proccess work"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "52baaf73-b34b-4407-9aef-bff67fe67ca7"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "select EmployeeCode from MI_ONTIME_Attendance where InLate>0\r\n",
+ "and EmployeeCode in \r\n",
+ "(select distinct EmployeeCode from MI_ONTIME_Leave where Year(StartDate)=2021 and month(StartDate)=01) \r\n",
+ " and Year(Date)=2021 and month(Date)=01 --and EmployeeCode=16\r\n",
+ "group by EmployeeCode\r\n",
+ "having count(EmployeeCode)>3\r\n",
+ "\r\n",
+ "select @SickBalance=Allocated-(@SickPending+Used) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\r\n",
+ "SELECT e.EmployeeCode\r\n",
+ "\t\tFROM [dbo].[MI_PROLL_ProcessEmployee] AS p\r\n",
+ "\t\t\t INNER JOIN\r\n",
+ "\t\t\t [dbo].[mi_employer_employee] AS e\r\n",
+ "\t\t\t ON p.employeecode = e.employeecode\r\n",
+ "\t\tWHERE e.Deleted = 0 AND e.EmployeeCode=10 and \r\n",
+ "\t\t\t e.schemecode IN( 12 ) AND \r\n",
+ "\t\t\t invokedby = 1 AND \r\n",
+ "\t\t p.Deleted = 0 \r\n",
+ "\r\n",
+ "select * from MI_ONTIME_Leave where Year(StartDate)=2020 and month(StartDate)=12 and EmployeeCode=10\r\n",
+ "select * from MI_ONTIME_Attendance where Late>0 and EmployeeCode=17\r\n",
+ "\r\n",
+ "select * from MI_Employer_Employee where EmployeeCode=11\r\n",
+ "select * from MI_EPRF_AutoLeaveDeduction where EmployeeCode=11\r\n",
+ "delete from MI_EPRF_AutoLeaveDeduction where EmployeeCode=11\r\n",
+ "select * from MI_ONTIME_LeaveAllocation where leaveallocationcode=6\r\n",
+ "update MI_ONTIME_LeaveAllocation set used=2 where leaveallocationcode=6\r\n",
+ "select * from my_log order by CreatedDate desc \r\n",
+ "\r\n",
+ "/****** Object: StoredProcedure [dbo].[PRC_PROLL_ProcessPayroll] Script Date: 1/29/2021 6:19:22 PM ******/\r\n",
+ "SET ANSI_NULLS ON\r\n",
+ "GO\r\n",
+ "SET QUOTED_IDENTIFIER ON\r\n",
+ "GO\r\n",
+ "--select * from MI_PROLL_PayPeriod\r\n",
+ "--[PRC_PROLL_ProcessPayroll] 2020,3,953,12,1,1\r\n",
+ "ALTER PROCEDURE [dbo].[PRC_PROLL_ProcessPayroll] --[PRC_PROLL_ProcessPayroll] 2020,3,950,12,1,1\r\n",
+ "(\r\n",
+ " @Year int,\r\n",
+ "\t @PayPeriodType int,\r\n",
+ "\t @PayPeriodCode int,\r\n",
+ "\t @SchemeCode int,\r\n",
+ "\t @TemplateCode int,\r\n",
+ "\t @InvokedBy int\r\n",
+ ")\r\n",
+ "AS\r\n",
+ "\r\n",
+ "DECLARE @Result int;\r\n",
+ "set dateformat ymd\r\n",
+ "Declare @SDate datetime\r\n",
+ "Declare @EDate datetime\r\n",
+ "Declare @LSDate datetime\r\n",
+ "Declare @LEDate datetime\r\n",
+ "Declare @cnt int\r\n",
+ "Declare @Days Decimal(19,4)\r\n",
+ "Declare @LCode int\r\n",
+ "Declare @EmpNo varchar(50)\r\n",
+ "Declare @OThrs Decimal(19,4)\r\n",
+ "Declare @ArrearsOThrs Decimal(19,4)\r\n",
+ "Declare @Othrscnt int\r\n",
+ "Declare @DOThrs Decimal(19,4)\r\n",
+ "Declare @ArrearsDOThrs Decimal(19,4)\r\n",
+ "Declare @DOthrscnt int\r\n",
+ "Declare @TOThrs Decimal(19,4)\r\n",
+ "Declare @TOthrscnt int\r\n",
+ "Declare @Latehrs Decimal(19,4)\r\n",
+ "Declare @Latehrscnt int\r\n",
+ "Declare @dayoffs Decimal(19,4)\r\n",
+ "Declare @dayoffscnt int\r\n",
+ "Declare @daysworked Decimal(19,4)\r\n",
+ "Declare @daysworkedcnt int\r\n",
+ "Declare @AppLeave Decimal(19,4)\r\n",
+ "Declare @AppLeavecnt int\r\n",
+ "Declare @NAppLeave Decimal(19,4)\r\n",
+ "Declare @NAppLeavecnt int\r\n",
+ "Declare @Poya Decimal(19,4)\r\n",
+ "Declare @Poyacnt int\r\n",
+ "Declare @Mercantile Decimal(19,4)\r\n",
+ "Declare @Mercantilecnt int\r\n",
+ "Declare @sunday Decimal(19,5)\r\n",
+ "Declare @sundaycnt int\r\n",
+ "Declare @AutoNopayDays int\r\n",
+ "declare @EmpNoPaydevider int\r\n",
+ "Declare @TotSundays int\r\n",
+ "Declare @Date date\r\n",
+ "Declare @Deducted decimal(18,2)\r\n",
+ "set @Days =0\r\n",
+ "set @cnt =0\r\n",
+ "Declare @auonopaycount int\r\n",
+ "--declare @Employeecode int\r\n",
+ "declare @x int\r\n",
+ "declare @StartDate int\r\n",
+ "declare @EndtDate int\r\n",
+ "--declare @SchemeCode int\r\n",
+ "declare @autonopay decimal(18,2)\r\n",
+ "declare @ThisMonth int\r\n",
+ "declare @ThisYear int\r\n",
+ "declare @LastMonth int\r\n",
+ "declare @LastYear int\r\n",
+ "declare @Location int\r\n",
+ "Declare @Inlate decimal(18,2)\r\n",
+ "Declare @OutLate decimal(18,2)\r\n",
+ "Declare @Balance decimal(18,2)\r\n",
+ "Declare @DayType int\r\n",
+ "Declare @DOA date\r\n",
+ "Declare @LeaveYearStartDate date\r\n",
+ "Declare @LeaveYearEndDate date\r\n",
+ "Declare @LeaveYear int\r\n",
+ "Declare @LeaveType int\r\n",
+ "Declare @Val decimal(18,2)\r\n",
+ "Declare @LastMonthStartDate date\r\n",
+ "Declare @LastMonthEndDate date\r\n",
+ "Declare @DOB date\r\n",
+ "Declare @DOR date\r\n",
+ "Declare @LastMonthGrossSalary decimal(18,2)\r\n",
+ "Declare @ArrearDays int\r\n",
+ "Declare @daysArrearscnt int\r\n",
+ "Declare @AnnualLeaveType int=1\r\n",
+ "Declare @CasualLeaveType int=2\r\n",
+ "Declare @SickLeaveType int=3\r\n",
+ "Declare @PensionScheme int\r\n",
+ "Declare @OTAmount Decimal(18,2)\r\n",
+ "DECLARE @Success bit\r\n",
+ "DECLARE @Message varchar(50)\r\n",
+ "Declare @transcount int\r\n",
+ "Declare @Count as decimal(18,10)\r\n",
+ "Declare @Empcode as int\r\n",
+ "Declare @Progress as decimal(18,2)\r\n",
+ "select @Count=COUNT([dbo].[MI_Employer_Employee].EmployeeCode) from [dbo].[MI_PROLL_ProcessEmployee] inner join [dbo].[MI_Employer_Employee] on\r\n",
+ "[dbo].[MI_PROLL_ProcessEmployee].employeecode=[dbo].[MI_Employer_Employee].employeecode where [dbo].[MI_Employer_Employee].deleted=0\r\n",
+ "and [dbo].[MI_Employer_Employee].schemecode not in (@SchemeCode) and invokedby=@InvokedBy and [dbo].[MI_PROLL_ProcessEmployee].deleted=0 --and [dbo].[MI_Employer_Employee].EmployeeCode=382\r\n",
+ "IF @Count=0 \r\n",
+ "BEGIN\r\n",
+ "\tSET @Count=1\r\n",
+ "END\r\n",
+ "SET @Count=(1/@Count)*100\r\n",
+ "--select @Count\r\n",
+ "update [dbo].[MI_PROLL_PayrollProcessing] set Progress=0,Updatedby=@InvokedBy,Updateddate=getDate() where TemplateCode=@TemplateCode AND InvokedBy=@InvokedBy AND Deleted=0;\r\n",
+ "DECLARE Input_all cursor for\r\n",
+ "--Select [dbo].[MI_Employer_Employee].EmployeeCode from [dbo].[MI_PROLL_ProcessEmployee] inner join [dbo].[MI_Employer_Employee] on\r\n",
+ "--[dbo].[MI_PROLL_ProcessEmployee].employeecode=[dbo].[MI_Employer_Employee].employeecode where [dbo].[MI_Employer_Employee].deleted=0\r\n",
+ "--and [dbo].[MI_Employer_Employee].schemecode not in (@) and invokedby=@InvokedBy \r\n",
+ "--and [dbo].[MI_PROLL_ProcessEmployee].deleted=0 --and [dbo].[MI_Employer_Employee].EmployeeCode=137\r\n",
+ "SELECT e.EmployeeCode\r\n",
+ "\t\tFROM [dbo].[MI_PROLL_ProcessEmployee] AS p\r\n",
+ "\t\t\t INNER JOIN\r\n",
+ "\t\t\t [dbo].[mi_employer_employee] AS e\r\n",
+ "\t\t\t ON p.employeecode = e.employeecode\r\n",
+ "\t\tWHERE e.Deleted = 0 AND \r\n",
+ "\t\t\t e.schemecode IN( @SchemeCode ) AND \r\n",
+ "\t\t\t invokedby = @InvokedBy AND \r\n",
+ "\t\t p.Deleted = 0 \r\n",
+ "--and e.EmployeeCode in (382)\r\n",
+ "--and e.Level4Code in (\r\n",
+ "--2\r\n",
+ "--,3\r\n",
+ "--,4\r\n",
+ "--,5\r\n",
+ "--,6\r\n",
+ "--,7\r\n",
+ "--,8\r\n",
+ "--,9\r\n",
+ "--,10\r\n",
+ "--,11\r\n",
+ "--,12\r\n",
+ "--,13\r\n",
+ "--,14\r\n",
+ "--,17\r\n",
+ "--,18\r\n",
+ "--,19\r\n",
+ "--,20\r\n",
+ "--,23\r\n",
+ "--,25\r\n",
+ "--,30\r\n",
+ "--,33\r\n",
+ "--,34\r\n",
+ "--,35\r\n",
+ "--,38\r\n",
+ "--,42\r\n",
+ "--,44\r\n",
+ "--,45\r\n",
+ "--,46\r\n",
+ "--,47\r\n",
+ "--,50\r\n",
+ "--,54\r\n",
+ "--,56\r\n",
+ "--,62\r\n",
+ "--,63\r\n",
+ "--,64\r\n",
+ "--,67\r\n",
+ "--,68\r\n",
+ "--,73\r\n",
+ "--,83\r\n",
+ "--,84\r\n",
+ "--,89\r\n",
+ "--,90\r\n",
+ "--,92\r\n",
+ "--,101\r\n",
+ "--) \r\n",
+ "and e.Deleted=0\r\n",
+ "--and e.Level3Code=10 and e.Level4Code=33 \r\n",
+ "order by e.EmployeeCode\r\n",
+ "OPEN Input_all\r\n",
+ "FETCH NEXT FROM Input_all into @Empcode\r\n",
+ "while @@FETCH_STATUS=0 \r\n",
+ "BEGIN\r\n",
+ "\r\n",
+ "insert into [my_log] values (concat('@Empcode',@Empcode), getdate())\r\n",
+ "--While(@Progress<100)\r\n",
+ "--BEGIN \r\n",
+ "\t\r\n",
+ "\tSET @Progress =(SELECT (Progress+@Count) FROM [dbo].[MI_PROLL_PayrollProcessing] where TemplateCode=@TemplateCode AND InvokedBy=@InvokedBy AND Deleted=0);\r\n",
+ "\tset @Progress=round(@Progress,2)\r\n",
+ "\tif @Progress>=100 begin\r\n",
+ "\t\tset @Progress=100\r\n",
+ "\tend\r\n",
+ "\tupdate [dbo].[MI_PROLL_PayrollProcessing] set Progress=@Progress,Updatedby=@InvokedBy,Updateddate=getDate() where TemplateCode=@TemplateCode AND InvokedBy=@InvokedBy AND Deleted=0;\r\n",
+ "\t--WAITFOR DELAY '00:00:01'\r\n",
+ "--END--Change\r\n",
+ "--select @Progress\r\n",
+ "\r\n",
+ "\r\n",
+ "select @DOA=DateOfAppointment from [dbo].MI_Employer_Employee where employeecode=@Empcode and Deleted=0\r\n",
+ "select @PensionScheme=PensionSchemeCode from [dbo].MI_Employer_Employee where employeecode=@Empcode\r\n",
+ "set @PensionScheme=isnull(@PensionScheme,0)\r\n",
+ "--SELECT @LastMonthGrossSalary=sum(ProcessValue) FROM [dbo].MI_pRoll_ProcessInfo where Description ='Gross Salary' and EmployeeCode=@Empcode and PayPeriodCode=@PayPeriodCode-1\r\n",
+ "--set @LastMonthGrossSalary= isnull(@LastMonthGrossSalary,0)\r\n",
+ "select @SchemeCode=SchemeCode, @Location=LocationCode, @DOA=DateOfAppointment, @DOR=ResignedDate from [dbo].MI_Employer_Employee where EmployeeCode=@Empcode and Deleted=0\r\n",
+ "--select cast(SchemeItemValue as int) from [dbo].MI_pRoll_SchemeDetails where SchemeItemCode=15 and SchemeCode=8\r\n",
+ "--select cast(SchemeItemValue as int) from [dbo].MI_pRoll_SchemeDetails where SchemeItemCode=16 and SchemeCode=8\r\n",
+ "select month(StartDate) from [dbo].MI_pRoll_PayPeriod where PayPeriodCode=@PayPeriodCode and PPeriodTypeCode=3\r\n",
+ "select @ThisYear=Year(StartDate) from [dbo].MI_pRoll_PayPeriod where PayPeriodCode=@PayPeriodCode and PPeriodTypeCode=3\r\n",
+ "select @ThisMonth=Month(StartDate) from [dbo].MI_pRoll_PayPeriod where PayPeriodCode=@PayPeriodCode and PPeriodTypeCode=3\r\n",
+ "select @StartDate=Day(StartDate) from [dbo].MI_pRoll_PayPeriod where PayPeriodCode=@PayPeriodCode and PPeriodTypeCode=3\r\n",
+ "select @EndtDate=Day(EndDate) from [dbo].MI_pRoll_PayPeriod where PayPeriodCode=@PayPeriodCode and PPeriodTypeCode=3\r\n",
+ "\r\n",
+ "--if @ThisMonth=1 begin\r\n",
+ "--\tset @LastYear=@ThisYear-1\r\n",
+ "--\tset @LastMonth=12\r\n",
+ "--end\r\n",
+ "--else begin\r\n",
+ "--\tset @LastMonth=@ThisMonth-1\r\n",
+ "--\tset @LastYear=@ThisYear\r\n",
+ "--end\r\n",
+ "\r\n",
+ "if @ThisMonth=1 begin\r\n",
+ "\tif @SchemeCode>1 begin\r\n",
+ "\t\tset @LastYear=@ThisYear\r\n",
+ "\t\tset @LastMonth=1\r\n",
+ "\tend\r\n",
+ "\telse begin\r\n",
+ "\t\tset @LastYear=@ThisYear\r\n",
+ "\t\tset @LastMonth=1\r\n",
+ "\tend\r\n",
+ "end\r\n",
+ "else begin\r\n",
+ "\tif @SchemeCode>1 begin\r\n",
+ "\t\tset @LastMonth=@ThisMonth\r\n",
+ "\t\tset @LastYear=@ThisYear\r\n",
+ "\tend\r\n",
+ "\telse begin\r\n",
+ "\t\tset @LastMonth=@ThisMonth-1\r\n",
+ "\t\tset @LastYear=@ThisYear\r\n",
+ "\tend\r\n",
+ "end\r\n",
+ "\r\n",
+ "set @SDate=cast(cast(@LastYear as varchar(max))+'-'+cast(@LastMonth as varchar(max))+'-'+cast(@StartDate as varchar(max)) as date)\r\n",
+ "set @EDate=cast(cast(@ThisYear as varchar(max))+'-'+cast(@ThisMonth as varchar(max))+'-'+cast(@EndtDate as varchar(max)) as date)\r\n",
+ "\r\n",
+ "select @LSDate=Cast(StartDate as Date) from [dbo].mi_proll_payperiod where payperiodCode=(select payperiodCode-1 from [dbo].mi_proll_payperiod where cast(StartDate as Date)=cast(@SDate as Date))\r\n",
+ "select @LEDate=Cast(EndDate as Date) from [dbo].mi_proll_payperiod where payperiodCode=(select payperiodCode-1 from [dbo].mi_proll_payperiod where cast(enddate as Date)=cast(@EDate as Date))\r\n",
+ "\r\n",
+ "--set @LSDate=DATEADD(M,-1,@SDate)\r\n",
+ "--set @LEDate=DATEADD(M,-1,@EDate)\r\n",
+ "/*set @LeaveYearStartDate=cast(cast(@ThisYear as varchar(10))+'-'+Cast(Month(@DOA)as varchar(10))+'-'+Cast(day(@DOA)as varchar(10)) as Date)\r\n",
+ "\r\n",
+ "if Month(@LeaveYearStartDate)=@LeaveYearStartDate begin\r\n",
+ "\tSet @LeaveYear=Year(@LeaveYearStartDate)\r\n",
+ "end\r\n",
+ "else if @EDate>@LeaveYearEndDate begin\r\n",
+ "\tSet @LeaveYear=Year(@LeaveYearStartDate)+1\r\n",
+ "end\r\n",
+ "*/\r\n",
+ "\r\n",
+ "Set @LeaveYear= (\r\n",
+ "\t\t\t\t\tSELECT LeaveYear\r\n",
+ "\t\t\t\t\tFROM [dbo].MI_ONTIME_LeavePeriod\r\n",
+ "\t\t\t\t\tWHERE IsDefault = 1\r\n",
+ "\t\t\t\t\t)\r\n",
+ "BEGIN TRY\t\r\n",
+ "\r\n",
+ "--========================Auto Nopay days================================================\r\n",
+ "\t\t\t--if @Empcode not in (Select employeecode from [dbo].mi_employer_employee where number in(Select number from [dbo].MI_Attendance_ExemptedEmployees)) begin\r\n",
+ "\t\t\t--\t--Late employees\r\n",
+ "\t\t\t--\tDeclare @Annual decimal(18,2)\r\n",
+ "\t\t\t--\tset @Val=0\r\n",
+ "\t\t\t--\tset @Cnt=0\r\n",
+ "\t\t\t--\tselect @Annual=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where EmployeeCode=@Empcode and Payperiod=@PayPeriodCode and LeaveType=@AnnualLeaveType\r\n",
+ "\t\t\t--\tset @Annual=isnull(@Annual,0)\r\n",
+ "\t\t\t--\tselect @Cnt=count(EmployeeCode) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@AnnualLeaveType\r\n",
+ "\t\t\t--\tif @Cnt>0 begin\r\n",
+ "\t\t\t--\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=Used-@Annual where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@AnnualLeaveType\r\n",
+ "\t\t\t--\t\tselect @Annual=used from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@AnnualLeaveType\r\n",
+ "\t\t\t--\t\tif @Annual<0 begin\r\n",
+ "\t\t\t--\t\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=0 where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@AnnualLeaveType\r\n",
+ "\t\t\t--\t\tend\r\n",
+ "\t\t\t--\tend\r\n",
+ "\r\n",
+ "\t\t\t--\tDeclare @Casual decimal(18,2)\r\n",
+ "\t\t\t--\tset @Cnt=0\r\n",
+ "\t\t\t--\tselect @Casual=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where EmployeeCode=@Empcode and Payperiod=@PayPeriodCode and LeaveType=@CasualLeaveType\r\n",
+ "\t\t\t--\tset @Casual=isnull(@Casual,0)\r\n",
+ "\t\t\t--\tselect @Cnt=count(EmployeeCode) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@CasualLeaveType\r\n",
+ "\t\t\t--\tif @Cnt>0 begin\r\n",
+ "\t\t\t--\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=Used-@Casual where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@CasualLeaveType\r\n",
+ "\t\t\t--\t\tselect @Casual=used from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@CasualLeaveType\r\n",
+ "\t\t\t--\t\tif @Casual<0 begin\r\n",
+ "\t\t\t--\t\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=0 where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@CasualLeaveType\r\n",
+ "\t\t\t--\t\tend\r\n",
+ "\t\t\t--\tend\r\n",
+ "\t\t\t\t\r\n",
+ "\t\t\t\t\r\n",
+ "\t\t\t--\tDeclare @Sick decimal(18,2)\r\n",
+ "\t\t\t--\tset @Cnt=0\r\n",
+ "\t\t\t--\tselect @Sick=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where EmployeeCode=@Empcode and Payperiod=@PayPeriodCode and LeaveType=@SickLeaveType\r\n",
+ "\t\t\t--\tset @Sick=isnull(@Sick,0)\r\n",
+ "\t\t\t--\tselect @Cnt=count(EmployeeCode) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\t\t\t--\tif @Cnt>0 begin\r\n",
+ "\t\t\t--\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=Used-@Sick where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\t\t\t--\t\tselect @Sick=used from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\t\t\t--\t\tif @Sick<0 begin\r\n",
+ "\t\t\t--\t\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=0 where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\t\t\t--\t\tend\r\n",
+ "\t\t\t--\tend\r\n",
+ "\t\t\t--\tinsert into my_log values(concat('@Sdate ',@Sdate, '@Edate ',@Edate, '@EmpCode ',@EmpCode), getdate())\r\n",
+ "\t\t\t\t\t\r\n",
+ "\t\t\t--\tDelete from [dbo].MI_EPRF_AutoLeaveDeduction where EmployeeCode=@Empcode and Payperiod=@PayPeriodCode \r\n",
+ "\t\t\t--\t--if @SchemeCode=12 or (@SchemeCode=21) begin\r\n",
+ "\t\t\t--\t\tif (@ThisMonth=month(@DOR) and @ThisYear=Year(@DOR)) and @LastMonthGrossSalary=0 begin\r\n",
+ "\t\t\t--\t\t\tdeclare EffectedEmployee cursor for select Date, Inlate,OutLate,DayTypeCode from [dbo].MI_ONTIME_Attendance where EmployeeCode =@EmpCode and date >= @LSdate and date <= @DOR and InLate>0\r\n",
+ "\t\t\t--\t\tend\r\n",
+ "\t\t\t--\t\telse if (@ThisMonth=month(@DOR) and @ThisYear=Year(@DOR)) and @LastMonthGrossSalary>0 begin\r\n",
+ "\t\t\t--\t\t\tdeclare EffectedEmployee cursor for select Date, Inlate,OutLate,DayTypeCode from [dbo].MI_ONTIME_Attendance where EmployeeCode =@EmpCode and date >= @Sdate and date <= @DOR and inlate>0\r\n",
+ "\t\t\t--\t\tend\r\n",
+ "\t\t\t--\t\telse if (@LastMonth=month(@DOA) and @LastYear=Year(@DOA)) and @LastMonthGrossSalary=0 begin\r\n",
+ "\t\t\t--\t\t\tdeclare EffectedEmployee cursor for select Date, Inlate,OutLate,DayTypeCode from [dbo].MI_ONTIME_Attendance where EmployeeCode =@EmpCode and date >= @LSdate and date <= @Edate and inlate>0\r\n",
+ "\t\t\t--\t\tend\r\n",
+ "\t\t\t--\t\telse begin\r\n",
+ "\t\t\t--\t\t\tdeclare EffectedEmployee cursor for select Date, Inlate,OutLate, DayTypeCode from [dbo].MI_ONTIME_Attendance where EmployeeCode =@EmpCode and date >= @Sdate and date <= @Edate and inlate>0\r\n",
+ "\t\t\t--\t\tend\r\n",
+ "\t\t\t\t\t\r\n",
+ "\t\t\t--\t\topen EffectedEmployee\r\n",
+ "\t\t\t--\t\tfetch next from EffectedEmployee into @Date,@Inlate,@OutLate,@DayType\r\n",
+ "\t\t\t--\t\twhile @@Fetch_status = 0\r\n",
+ "\t\t\t--\t\tbegin\r\n",
+ "\t\t\t\t\t\t\t\r\n",
+ "\t\t\t--\t\t\tif @Inlate>0 or @Inlate>0 begin \r\n",
+ "\t\t\t--\t\t\t\tset @Val=@Val+1\r\n",
+ "\t\t\t--\t\t\tend\r\n",
+ "\t\t\t\t\t\t\t\r\n",
+ "\t\t\t--\t\tfetch next from EffectedEmployee into @Date,@Inlate,@OutLate,@DayType\r\n",
+ "\t\t\t--\t\tEnd\r\n",
+ "\t\t\t--\t\tclose EffectedEmployee\r\n",
+ "\t\t\t--\t\tdeallocate EffectedEmployee\r\n",
+ "\t\t\t--\t\tDeclare @AnnualBalance decimal(18,2)\r\n",
+ "\t\t\t--\t\tDeclare @CasualBalance decimal(18,2)\r\n",
+ "\t\t\t--\t\tDeclare @SickBalance decimal(18,2)\r\n",
+ "\t\t\t--\t\tDeclare @AnnualPending decimal(18,2)\r\n",
+ "\t\t\t--\t\tDeclare @CasualPending decimal(18,2)\r\n",
+ "\t\t\t--\t\tDeclare @SickPending decimal(18,2)\r\n",
+ "\t\t\t--\t\tDeclare @Remain decimal(18,2)\r\n",
+ "\t\t\t--\t\t\t\t\t\tinsert into my_log values(concat('@@Val ',@Val), getdate())\r\n",
+ "\r\n",
+ "\t\t\t--\t\tset @Val=@Val/6\r\n",
+ "\t\t\t--\t\tif @Val>0 begin\r\n",
+ "\t\t\t--\t\t\tset @Deducted=0\r\n",
+ "\t\t\t--\t\t\tselect @Deducted=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where Payperiod=@PayPeriodCode and Employeecode=@Empcode and @LeaveType=@AnnualLeaveType\r\n",
+ "\t\t\t--\t\t\tset @Deducted=isnull(@Deducted,0)\r\n",
+ "\t\t\t--\t\t\tset @cnt=0\r\n",
+ "\t\t\t--\t\t\tselect @cnt=count(employeecode) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@AnnualLeaveType\r\n",
+ "\t\t\t--\t\t\tif @cnt>0 begin\r\n",
+ "\t\t\t--\t\t\t\t--select @AnnualPending=[Z1_Multinet].[Fn_GetPendingLeaveCount] (@Empcode, @LeaveYear, @AnnualLeaveType)\r\n",
+ "\t\t\t--\t\t\t\tSelect @AnnualPending= NoOfDays FROM [dbo].MI_ONTIME_Leave WHERE Deleted = 0 AND EmployeeCode = @EmpCode AND LeaveYear = @LeaveYear AND LeaveTypeCode = @LeaveType AND RequestStatus = 'P'\r\n",
+ "\t\t\t--\t\t\t\tset @AnnualPending=isnull(@AnnualPending,0)\r\n",
+ "\t\t\t--\t\t\t\tselect @AnnualBalance=Allocated-(@AnnualPending+Used) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@AnnualLeaveType\r\n",
+ "\t\t\t--\t\t\t\tset @AnnualBalance=isnull(@AnnualBalance,0)-@Deducted\r\n",
+ "\t\t\t--\t\t\tend\r\n",
+ "\t\t\t--\t\t\tset @cnt=0\r\n",
+ "\t\t\t--\t\t\tset @Deducted=0\r\n",
+ "\t\t\t--\t\t\tselect @Deducted=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where Payperiod=@PayPeriodCode and Employeecode=@Empcode and @LeaveType=@CasualLeaveType\r\n",
+ "\t\t\t--\t\t\tset @Deducted=isnull(@Deducted,0)\r\n",
+ "\t\t\t--\t\t\tset @cnt=0\r\n",
+ "\t\t\t--\t\t\tselect @cnt=count(employeecode) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@CasualLeaveType\r\n",
+ "\t\t\t--\t\t\tif @cnt>0 begin\r\n",
+ "\t\t\t--\t\t\t\tselect @CasualPending=NoOfDays FROM [dbo].MI_ONTIME_Leave WHERE Deleted = 0 AND EmployeeCode = @EmpCode AND LeaveYear = @LeaveYear AND LeaveTypeCode = @LeaveType AND RequestStatus = 'P'\r\n",
+ "\t\t\t--\t\t\t\tset @CasualPending=isnull(@CasualPending,0)\r\n",
+ "\t\t\t--\t\t\t\tselect @CasualBalance=Allocated-(@CasualPending+Used) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@CasualLeaveType\r\n",
+ "\t\t\t--\t\t\t\tset @CasualBalance=isnull(@CasualBalance,0)-@Deducted\r\n",
+ "\t\t\t--\t\t\tend\r\n",
+ "\t\t\t--\t\t\tset @cnt=0\r\n",
+ "\t\t\t--\t\t\tset @Deducted=0\r\n",
+ "\t\t\t--\t\t\tselect @Deducted=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where Payperiod=@PayPeriodCode and Employeecode=@Empcode and @LeaveType=@SickLeaveType\r\n",
+ "\t\t\t--\t\t\tset @Deducted=isnull(@Deducted,0)\r\n",
+ "\t\t\t--\t\t\tset @cnt=0\r\n",
+ "\t\t\t--\t\t\tselect @cnt=count(employeecode) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\t\t\t--\t\t\tif @cnt>0 begin\r\n",
+ "\t\t\t--\t\t\t\tselect @SickPending=NoOfDays FROM [dbo].MI_ONTIME_Leave WHERE Deleted = 0 AND EmployeeCode = @EmpCode AND LeaveYear = @LeaveYear AND LeaveTypeCode = @LeaveType AND RequestStatus = 'P'\r\n",
+ "\t\t\t--\t\t\t\tset @SickPending=isnull(@SickPending,0)\r\n",
+ "\t\t\t--\t\t\t\tselect @SickBalance=Allocated-(@SickPending+Used) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\t\t\t--\t\t\t\tset @SickBalance=isnull(@SickBalance,0)-@Deducted\r\n",
+ "\t\t\t--\t\t\tend\t\r\n",
+ "\r\n",
+ "\r\n",
+ "\r\n",
+ "\t\t\t--\t\tif @AnnualBalance>@Val begin\r\n",
+ "\t\t\t--\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'3 Days Late',@AnnualLeaveType,@Val)\r\n",
+ "\t\t\t--\t\t\t\t\tend\r\n",
+ "\t\t\t--\t\t\t\t\telse begin\r\n",
+ "\t\t\t--\t\t\t\t\t\tif @AnnualBalance>0 begin\r\n",
+ "\t\t\t--\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'3 Days Late',@AnnualLeaveType,@AnnualBalance)\r\n",
+ "\t\t\t--\t\t\t\t\t\t\tset @Remain=@Val-@AnnualBalance\r\n",
+ "\t\t\t--\t\t\t\t\t\t\tif @Remain>0 begin\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\tif @CasualBalance>@Remain begin\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'3 Days Late',@CasualLeaveType,@Remain)\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\tend\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\telse begin\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'3 Days Late',@CasualLeaveType,@CasualBalance)\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\t\tset @Remain=@Val-@CasualBalance\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\t\tif @Remain>0 begin\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\t\t\tif @SickBalance>@Remain begin\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'3 Days Late',@SickLeaveType,@Remain)\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\t\t\tend\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\t\t\telse begin\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'3 Days Late',@SickLeaveType,@SickBalance)\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\t\t\t\tset @Remain=@Val-@SickBalance\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\t\t\t\tif @Remain>0 begin\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'3 Days Late',0,@Remain)\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\t\t\t\tend\r\n",
+ "\r\n",
+ "\r\n",
+ "\r\n",
+ "\t\t\t--\t\t\t--if @CasualBalance>@Val begin\r\n",
+ "\t\t\t--\t\t\t--\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days,UpdatedOn) values (@Empcode,@PayPeriodCode,@SDate,0,'3 Days Late',@CasualLeaveType,@Val, getdate())\r\n",
+ "\t\t\t--\t\t\t--end\r\n",
+ "\t\t\t--\t\t\t--else begin\r\n",
+ "\t\t\t--\t\t\t--\tif @CasualBalance>0 begin\r\n",
+ "\t\t\t--\t\t\t--\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days,UpdatedOn) values (@Empcode,@PayPeriodCode,@SDate,0,'3 Days Late',@CasualLeaveType,@CasualBalance,getdate())\r\n",
+ "\t\t\t--\t\t\t--\t\tset @Remain=@Val-@CasualBalance\r\n",
+ "\t\t\t--\t\t\t--\t\tif @Remain>0 begin\r\n",
+ "\t\t\t--\t\t\t--\t\t\tif @SickBalance>@Remain begin\r\n",
+ "\t\t\t--\t\t\t--\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days,UpdatedOn) values (@Empcode,@PayPeriodCode,@SDate,0,'3 Days Late',@SickLeaveType,@Remain,getdate())\r\n",
+ "\t\t\t--\t\t\t--\t\t\tend\r\n",
+ "\t\t\t--\t\t\t--\t\t\telse begin\r\n",
+ "\t\t\t--\t\t\t--\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days,UpdatedOn) values (@Empcode,@PayPeriodCode,@SDate,0,'3 Days Late',@SickLeaveType,@SickBalance,getdate())\r\n",
+ "\t\t\t--\t\t\t--\t\t\t\tset @Remain=@Val-@SickBalance\r\n",
+ "\t\t\t--\t\t\t--\t\t\t\tif @Remain>0 begin\r\n",
+ "\t\t\t--\t\t\t--\t\t\t\t\tif @AnnualBalance>@Remain begin\r\n",
+ "\t\t\t--\t\t\t--\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days,UpdatedOn) values (@Empcode,@PayPeriodCode,@SDate,0,'3 Days Late',@AnnualLeaveType,@Remain,getdate())\r\n",
+ "\t\t\t--\t\t\t--\t\t\t\t\tend\r\n",
+ "\t\t\t--\t\t\t--\t\t\t\t\telse begin\r\n",
+ "\t\t\t--\t\t\t--\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days,UpdatedOn) values (@Empcode,@PayPeriodCode,@SDate,0,'3 Days Late',@AnnualLeaveType,@AnnualBalance,getdate())\r\n",
+ "\t\t\t--\t\t\t--\t\t\t\t\t\tset @Remain=@Val-@AnnualBalance\r\n",
+ "\t\t\t--\t\t\t--\t\t\t\t\t\tif @Remain>0 begin\r\n",
+ "\t\t\t--\t\t\t--\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days,UpdatedOn) values (@Empcode,@PayPeriodCode,@SDate,0,'3 Days Late',0,@Remain,getdate())\r\n",
+ "\t\t\t--\t\t\t--\t\t\t\t\t\tend\r\n",
+ "\t\t\t--\t\t\t\t\t\t\t\tend\r\n",
+ "\t\t\t--\t\t\t\t\t\t\tend\r\n",
+ "\t\t\t--\t\t\t\t\t\tend\r\n",
+ "\t\t\t--\t\t\t\t\tend\r\n",
+ "\t\t\t--\t\t\t\tend\r\n",
+ "\t\t\t--\t\t\tend\r\n",
+ "\r\n",
+ "\t\t\t\t\t\t\t\r\n",
+ "\t\t\t--\t\t\tdelete [dbo].MI_EPRF_AutoLeaveDeduction where Employeecode=@Empcode and Payperiod=@PayPeriodCode and Days=0\r\n",
+ "\t\t\t--\t\tend\r\n",
+ "\t\t\t--\t\tset @cnt=0\r\n",
+ "\t\t\t--\t\tDeclare @used decimal(18,2)\r\n",
+ "\t\t\t--\t\tselect @Annual=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where EmployeeCode=@Empcode and Payperiod=@PayPeriodCode and LeaveType=@AnnualLeaveType\r\n",
+ "\t\t\t--\t\tset @Annual=isnull(@Annual,0)\r\n",
+ "\t\t\t--\t\tif @Annual>0 begin\r\n",
+ "\t\t\t--\t\t\tselect @used=used from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@AnnualLeaveType\r\n",
+ "\t\t\t--\t\t\tset @used=isnull(@used,0)\r\n",
+ "\t\t\t--\t\t\tset @used=@used+@Annual\r\n",
+ "\t\t\t--\t\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=@Used where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@AnnualLeaveType\r\n",
+ "\t\t\t--\t\tend\r\n",
+ "\t\t\t--\t\tselect @Casual=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where EmployeeCode=@Empcode and Payperiod=@PayPeriodCode and LeaveType=@CasualLeaveType\r\n",
+ "\t\t\t--\t\tset @Casual=isnull(@Casual,0)\r\n",
+ "\t\t\t--\t\tif @Casual>0 begin\r\n",
+ "\t\t\t--\t\t\tselect @used=used from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@CasualLeaveType\r\n",
+ "\t\t\t--\t\t\tset @used=isnull(@used,0)\r\n",
+ "\t\t\t--\t\t\tset @used=@used+@Casual\r\n",
+ "\t\t\t--\t\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=@Used where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@CasualLeaveType\r\n",
+ "\t\t\t--\t\tend\r\n",
+ "\t\t\t--\t\tselect @Sick=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where EmployeeCode=@Empcode and Payperiod=@PayPeriodCode and LeaveType=@SickLeaveType\r\n",
+ "\t\t\t--\t\tset @Sick=isnull(@Sick,0)\r\n",
+ "\t\t\t--\t\tif @Sick>0 begin\r\n",
+ "\t\t\t--\t\t\tselect @used=used from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\t\t\t--\t\t\tset @used=isnull(@used,0)\r\n",
+ "\t\t\t--\t\t\tset @used=@used+@Sick\r\n",
+ "\t\t\t--\t\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=@Used where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\t\t\t--\t\tend\r\n",
+ "\t\t\t\t\t\t\r\n",
+ "\t\t\t--\t--end\r\n",
+ "\t\t\t--end\r\n",
+ "\t\t\t--if @Empcode not in (Select employeecode from [dbo].MI_Employer_Employee where number in(Select number from [dbo].MI_Attendance_ExemptedEmployees)) begin\r\n",
+ "\t\t\t\t\t\r\n",
+ "\t\t\t\t\t\r\n",
+ "\t\t\t--\tif (@ThisMonth=month(@DOR) and @ThisYear=Year(@DOR)) and @LastMonthGrossSalary=0 begin\r\n",
+ "\t\t\t--\t\tdeclare EffectedEmployee cursor for\r\n",
+ "\t\t\t--\t\tselect Date from [dbo].MI_ONTIME_Attendance where EmployeeCode =@EmpCode and date >= @LSdate and date <= @DOR and Present=0 and Expected=1 and LeaveAmount=0\r\n",
+ "\t\t\t--\tend\r\n",
+ "\t\t\t--\telse begin\r\n",
+ "\t\t\t--\t\tdeclare EffectedEmployee cursor for\r\n",
+ "\t\t\t--\t\tselect Date from [dbo].MI_ONTIME_Attendance where EmployeeCode =@EmpCode and date >= @Sdate and date <= @Edate and Present=0 and Expected=1 and LeaveAmount=0\r\n",
+ "\t\t\t--\tend\r\n",
+ "\t\t\t\t\t\r\n",
+ "\t\t\t--\topen EffectedEmployee\r\n",
+ "\t\t\t--\tfetch next from EffectedEmployee into @Date\r\n",
+ "\t\t\t--\twhile @@Fetch_status = 0\r\n",
+ "\t\t\t--\t\tbegin\t\t\r\n",
+ "\r\n",
+ "\t\t\t--\t\t\tDECLARE @annualBalanceTemp Decimal(18,2) = 0;\t--1\r\n",
+ "\t\t\t--\t\t\tDECLARE @casualBalanceTemp Decimal(18,2) = 0;\t--2\r\n",
+ "\t\t\t--\t\t\tDECLARE @sickBalanceTemp Decimal(18,2) = 0;\t\t--3\r\n",
+ "\r\n",
+ "\t\t\t--\t\t\tSELECT @annualBalanceTemp = (Allocated-Used) from MI_ONTIME_LeaveAllocation where EmployeeCode = @Empcode and LeaveTypeCode = 1 and LeaveYear = @LeaveYear\r\n",
+ "\t\t\t--\t\t\tSELECT @casualBalanceTemp = (Allocated-Used) from MI_ONTIME_LeaveAllocation where EmployeeCode = @Empcode and LeaveTypeCode = 2 and LeaveYear = @LeaveYear\r\n",
+ "\t\t\t--\t\t\tSELECT @sickBalanceTemp = (Allocated-Used) from MI_ONTIME_LeaveAllocation where EmployeeCode = @Empcode and LeaveTypeCode = 3 and LeaveYear = @LeaveYear\r\n",
+ "\r\n",
+ "\r\n",
+ "\t\t\t--\t\t\tIF @sickBalanceTemp > 1\r\n",
+ "\t\t\t--\t\t\t\tSET @LeaveType = 3;\r\n",
+ "\t\t\t--\t\t\tELSE IF @casualBalanceTemp > 1\r\n",
+ "\t\t\t--\t\t\t\tSET @LeaveType = 2;\r\n",
+ "\t\t\t--\t\t\tELSE IF @annualBalanceTemp > 1\r\n",
+ "\t\t\t--\t\t\t\tSET @LeaveType = 1;\r\n",
+ "\t\t\t--\t\t\tELSE\r\n",
+ "\t\t\t--\t\t\t\tSET @LeaveType = 0;\r\n",
+ "\t\t\t--\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@Date,0,'Absent',0,1)\t\t\r\n",
+ "\t\t\t--\tfetch next from EffectedEmployee into @Date\r\n",
+ "\t\t\t--\tEnd\r\n",
+ "\t\t\t--\tclose EffectedEmployee\r\n",
+ "\t\t\t--\tdeallocate EffectedEmployee\r\n",
+ "\t\t\t--\tset @Autonopay=isnull(@Autonopay,0)\r\n",
+ "\t\t\t--\tselect @Autonopay=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where Employeecode=@Empcode and Payperiod=@PayPeriodCode and LeaveType=0\r\n",
+ "\t\t\t--\tset @Autonopay=isnull(@Autonopay,0)\r\n",
+ "\t\t\t--end\r\n",
+ "\r\n",
+ "\t\t\tif @Empcode not in (Select employeecode from [dbo].mi_employer_employee where number in(Select number from [dbo].MI_Attendance_ExemptedEmployees)) begin\r\n",
+ "\t\t\t\t--Late employees\r\n",
+ "\t\t\t\tDeclare @Annual decimal(18,2)\r\n",
+ "\t\t\t\tset @Val=0\r\n",
+ "\t\t\t\tset @Cnt=0\r\n",
+ "\t\t\t\tselect @Annual=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where EmployeeCode=@Empcode and Payperiod=@PayPeriodCode and LeaveType=@AnnualLeaveType\r\n",
+ "\t\t\t\tset @Annual=isnull(@Annual,0)\r\n",
+ "\t\t\t\tselect @Cnt=count(EmployeeCode) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@AnnualLeaveType\r\n",
+ "\t\t\t\tif @Cnt>0 begin\r\n",
+ "\t\t\t\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=Used-@Annual where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@AnnualLeaveType\r\n",
+ "\t\t\t\t\tselect @Annual=used from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@AnnualLeaveType\r\n",
+ "\t\t\t\t\tif @Annual<0 begin\r\n",
+ "\t\t\t\t\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=0 where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@AnnualLeaveType\r\n",
+ "\t\t\t\t\tend\r\n",
+ "\t\t\t\tend\r\n",
+ "\r\n",
+ "\t\t\t\tDeclare @Casual decimal(18,2)\r\n",
+ "\t\t\t\tset @Cnt=0\r\n",
+ "\t\t\t\tselect @Casual=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where EmployeeCode=@Empcode and Payperiod=@PayPeriodCode and LeaveType=@CasualLeaveType\r\n",
+ "\t\t\t\tset @Casual=isnull(@Casual,0)\r\n",
+ "\t\t\t\tselect @Cnt=count(EmployeeCode) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@CasualLeaveType\r\n",
+ "\t\t\t\tif @Cnt>0 begin\r\n",
+ "\t\t\t\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=Used-@Casual where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@CasualLeaveType\r\n",
+ "\t\t\t\t\tselect @Casual=used from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@CasualLeaveType\r\n",
+ "\t\t\t\t\tif @Casual<0 begin\r\n",
+ "\t\t\t\t\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=0 where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@CasualLeaveType\r\n",
+ "\t\t\t\t\tend\r\n",
+ "\t\t\t\tend\r\n",
+ "\t\t\t\t\r\n",
+ "\t\t\t\t\r\n",
+ "\t\t\t\tDeclare @Sick decimal(18,2)\r\n",
+ "\t\t\t\tset @Cnt=0\r\n",
+ "\t\t\t\tselect @Sick=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where EmployeeCode=@Empcode and Payperiod=@PayPeriodCode and LeaveType=@SickLeaveType\r\n",
+ "\t\t\t\tset @Sick=isnull(@Sick,0)\r\n",
+ "\t\t\t\tselect @Cnt=count(EmployeeCode) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\t\t\t\tif @Cnt>0 begin\r\n",
+ "\t\t\t\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=Used-@Sick where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\t\t\t\t\tselect @Sick=used from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\t\t\t\t\tif @Sick<0 begin\r\n",
+ "\t\t\t\t\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=0 where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\t\t\t\t\tend\r\n",
+ "\t\t\t\tend\r\n",
+ "\r\n",
+ "\t\t\t\tinsert into [my_log] values (concat('@@Sick',@Sick,'@Casual',@Casual,'@Annual',@Annual), getdate())\r\n",
+ "\r\n",
+ "\t\t\t\tDelete from [dbo].MI_EPRF_AutoLeaveDeduction where EmployeeCode=@Empcode and Payperiod=@PayPeriodCode \r\n",
+ "\t\t\t\t--if @SchemeCode=12 or (@SchemeCode=21) begin\r\n",
+ "\t\t\t\t\tif (@ThisMonth=month(@DOR) and @ThisYear=Year(@DOR)) and @LastMonthGrossSalary=0 begin\r\n",
+ "\t\t\t\t\t\tdeclare EffectedEmployee cursor for select Date, Inlate,OutLate,DayTypeCode from [dbo].MI_ONTIME_Attendance where EmployeeCode =@EmpCode and date >= @LSdate and date <= @DOR and InLate>0\r\n",
+ "\t\t\t\t\tend\r\n",
+ "\t\t\t\t\telse if (@ThisMonth=month(@DOR) and @ThisYear=Year(@DOR)) and @LastMonthGrossSalary>0 begin\r\n",
+ "\t\t\t\t\t\tdeclare EffectedEmployee cursor for select Date, Inlate,OutLate,DayTypeCode from [dbo].MI_ONTIME_Attendance where EmployeeCode =@EmpCode and date >= @Sdate and date <= @DOR and inlate>0\r\n",
+ "\t\t\t\t\tend\r\n",
+ "\t\t\t\t\telse if (@LastMonth=month(@DOA) and @LastYear=Year(@DOA)) and @LastMonthGrossSalary=0 begin\r\n",
+ "\t\t\t\t\t\tdeclare EffectedEmployee cursor for select Date, Inlate,OutLate,DayTypeCode from [dbo].MI_ONTIME_Attendance where EmployeeCode =@EmpCode and date >= @LSdate and date <= @Edate and inlate>0\r\n",
+ "\t\t\t\t\tend\r\n",
+ "\t\t\t\t\telse begin\r\n",
+ "\t\t\t\t\t\tdeclare EffectedEmployee cursor for select Date, Inlate,OutLate, DayTypeCode from [dbo].MI_ONTIME_Attendance where EmployeeCode =@EmpCode and date >= @Sdate and date <= @Edate and inlate>0\r\n",
+ "\t\t\t\t\tend\r\n",
+ "\t\t\t\t\topen EffectedEmployee\r\n",
+ "\t\t\t\t\tfetch next from EffectedEmployee into @Date,@Inlate,@OutLate,@DayType\r\n",
+ "\t\t\t\t\twhile @@Fetch_status = 0\r\n",
+ "\t\t\t\t\tbegin\r\n",
+ "\t\t\t\t\t\t\t\r\n",
+ "\t\t\t\t\t\tif @Inlate>0 or @Inlate>0 begin \r\n",
+ "\t\t\t\t\t\t\tset @Val=@Val+1\r\n",
+ "\t\t\t\t\t\tend\r\n",
+ "\t\t\t\t\t\t\t\r\n",
+ "\t\t\t\t\tfetch next from EffectedEmployee into @Date,@Inlate,@OutLate,@DayType\r\n",
+ "\t\t\t\t\tEnd\r\n",
+ "\t\t\t\t\tclose EffectedEmployee\r\n",
+ "\t\t\t\t\tdeallocate EffectedEmployee\r\n",
+ "\t\t\t\t\tDeclare @AnnualBalance decimal(18,2)\r\n",
+ "\t\t\t\t\tDeclare @CasualBalance decimal(18,2)\r\n",
+ "\t\t\t\t\tDeclare @SickBalance decimal(18,2)\r\n",
+ "\t\t\t\t\tDeclare @AnnualPending decimal(18,2)\r\n",
+ "\t\t\t\t\tDeclare @CasualPending decimal(18,2)\r\n",
+ "\t\t\t\t\tDeclare @SickPending decimal(18,2)\r\n",
+ "\t\t\t\t\tDeclare @Remain decimal(18,2)\r\n",
+ "\t\t\t\t\tinsert into [my_log] values (concat('@Val',@Val), getdate())\r\n",
+ "\t\t\t\t\t\r\n",
+ "\t\t\t\t\tset @Val=@Val/3\r\n",
+ "\t\t\t\t\tset @Val=cast(@Val as int)\r\n",
+ "\t\t\t\t\tset @Val= @Val/2\r\n",
+ "\r\n",
+ "\t\t\t\t\tif @Val>0 begin\r\n",
+ "\t\t\t\t\tinsert into [my_log] values (concat('@@Val>0 ','=true'), getdate())\r\n",
+ "\r\n",
+ "\t\t\t\t\t\tset @Deducted=0\r\n",
+ "\t\t\t\t\t\tselect @Deducted=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where Payperiod=@PayPeriodCode and Employeecode=@Empcode and @LeaveType=@AnnualLeaveType\r\n",
+ "\t\t\t\t\t\tset @Deducted=isnull(@Deducted,0)\r\n",
+ "\t\t\t\t\t\tset @cnt=0\r\n",
+ "\t\t\t\t\t\tselect @cnt=count(employeecode) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@AnnualLeaveType\r\n",
+ "\t\t\t\t\t\tif @cnt>0 begin\r\n",
+ "\t\t\t\t\t\t\t--select @AnnualPending=[Z1_Multinet].[Fn_GetPendingLeaveCount] (@Empcode, @LeaveYear, @AnnualLeaveType)\r\n",
+ "\t\t\t\t\t\t\tSelect @AnnualPending= NoOfDays FROM [dbo].MI_ONTIME_Leave WHERE Deleted = 0 AND EmployeeCode = @EmpCode AND LeaveYear = @LeaveYear AND LeaveTypeCode = @LeaveType AND RequestStatus = 'P'\r\n",
+ "\t\t\t\t\t\t\tset @AnnualPending=isnull(@AnnualPending,0)\r\n",
+ "\t\t\t\t\t\t\tselect @AnnualBalance=Allocated-(@AnnualPending+Used) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@AnnualLeaveType\r\n",
+ "\t\t\t\t\t\t\tset @AnnualBalance=isnull(@AnnualBalance,0)-@Deducted\r\n",
+ "\t\t\t\t\t\tend\r\n",
+ "\t\t\t\t\t\tset @cnt=0\r\n",
+ "\t\t\t\t\t\tset @Deducted=0\r\n",
+ "\t\t\t\t\t\tselect @Deducted=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where Payperiod=@PayPeriodCode and Employeecode=@Empcode and @LeaveType=@CasualLeaveType\r\n",
+ "\t\t\t\t\t\tset @Deducted=isnull(@Deducted,0)\r\n",
+ "\t\t\t\t\t\tset @cnt=0\r\n",
+ "\t\t\t\t\t\tselect @cnt=count(employeecode) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@CasualLeaveType\r\n",
+ "\t\t\t\t\t\tif @cnt>0 begin\r\n",
+ "\t\t\t\t\t\t\tselect @CasualPending=NoOfDays FROM [dbo].MI_ONTIME_Leave WHERE Deleted = 0 AND EmployeeCode = @EmpCode AND LeaveYear = @LeaveYear AND LeaveTypeCode = @LeaveType AND RequestStatus = 'P'\r\n",
+ "\t\t\t\t\t\t\tset @CasualPending=isnull(@CasualPending,0)\r\n",
+ "\t\t\t\t\t\t\tselect @CasualBalance=Allocated-(@CasualPending+Used) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@CasualLeaveType\r\n",
+ "\t\t\t\t\t\t\tset @CasualBalance=isnull(@CasualBalance,0)-@Deducted\r\n",
+ "\t\t\t\t\t\tend\r\n",
+ "\t\t\t\t\t\tset @cnt=0\r\n",
+ "\t\t\t\t\t\tset @Deducted=0\r\n",
+ "\t\t\t\t\t\tselect @Deducted=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where Payperiod=@PayPeriodCode and Employeecode=@Empcode and @LeaveType=@SickLeaveType\r\n",
+ "\t\t\t\t\t\tset @Deducted=isnull(@Deducted,0)\r\n",
+ "\t\t\t\t\t\tset @cnt=0\r\n",
+ "\t\t\t\t\t\tselect @cnt=count(employeecode) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\t\t\t\t\t\tinsert into [my_log] values (concat('@@@cnt',@cnt, '@@@LeaveYear',@LeaveYear,'@SickLeaveType',@SickLeaveType), getdate())\r\n",
+ "\t\t\t\t\t\tif @cnt>0 begin\r\n",
+ "\t\t\t\t\t\t\tselect @SickPending=NoOfDays FROM [dbo].MI_ONTIME_Leave WHERE Deleted = 0 AND EmployeeCode = @EmpCode AND LeaveYear = @LeaveYear AND LeaveTypeCode = @LeaveType AND RequestStatus = 'P'\r\n",
+ "\t\t\t\t\t\t\tset @SickPending=isnull(@SickPending,0)\r\n",
+ "\t\t\t\t\t\t\tselect @SickBalance=Allocated-(@SickPending+Used) from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\t\t\t\t\t\t\tinsert into [my_log] values (concat('@@SickBalance',@SickBalance, '@@Deducted',@Deducted), getdate())\r\n",
+ "\r\n",
+ "\t\t\t\t\t\t\tset @SickBalance=isnull(@SickBalance,0)-@Deducted\r\n",
+ "\t\t\t\t\t\tend\t\r\n",
+ "\r\n",
+ "\r\n",
+ "\t\t\t\t\tinsert into [my_log] values (concat('@Val',@Val, '@SickBalance',@SickBalance), getdate())\r\n",
+ "\t\t\t\t\tif @SickBalance>@Val begin\r\n",
+ "\t\t\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late from Sick',@SickLeaveType,@Val)\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\t\t\t\tinsert into [my_log] values (concat('@Val',@Val,'@Empcode',@Empcode, '@PayPeriodCode',@PayPeriodCode), getdate())\r\n",
+ "\r\n",
+ "\t\t\t\t\t\t\t\tend\r\n",
+ "\t\t\t\t\t\t\t\telse begin\r\n",
+ "\t\t\t\t\t\t\t\t\tinsert into [my_log] values (concat('@Val',@Val, '@SickBalance',@SickBalance), getdate())\r\n",
+ "\t\t\t\t\t\t\t\t\tif @SickBalance>0 begin\r\n",
+ "\t\t\t\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late from Sick',@SickLeaveType,@SickBalance)\r\n",
+ "\t\t\t\t\t\t\t\t\t\tset @Remain=@Val-@SickBalance\r\n",
+ "\t\t\t\t\t\t\t\t\t\tif @Remain>0 begin\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\tif @CasualBalance>@Remain begin\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late from Casual',@CasualLeaveType,@Remain)\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\tend\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\telse begin\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late from Casual',@CasualLeaveType,@CasualBalance)\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\t\tset @Remain=@Val-@CasualBalance\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\t\tif @Remain>0 begin\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\t\t\tif @AnnualBalance>@Remain begin\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late from Annual',@AnnualLeaveType,@Remain)\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\t\t\tend\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\t\t\telse begin\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late from Annual',@AnnualLeaveType,@AnnualBalance)\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\t\t\t\tset @Remain=@Val-@AnnualBalance\r\n",
+ "\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\t\t\t\tif @Remain>0 begin\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'Leave Balance Exhausted',0,@Remain)\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\t\t\t\tend\r\n",
+ "\r\n",
+ "\t\t\t\t\t--if @AnnualBalance>@Val begin\r\n",
+ "\t\t\t\t\t--\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late',@AnnualLeaveType,@Val)\r\n",
+ "\t\t\t\t\t--\t\t\tend\r\n",
+ "\t\t\t\t\t--\t\t\telse begin\r\n",
+ "\t\t\t\t\t--\t\t\t\tif @AnnualBalance>0 begin\r\n",
+ "\t\t\t\t\t--\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late',@AnnualLeaveType,@AnnualBalance)\r\n",
+ "\t\t\t\t\t--\t\t\t\t\tset @Remain=@Val-@AnnualBalance\r\n",
+ "\t\t\t\t\t--\t\t\t\t\tif @Remain>0 begin\r\n",
+ "\t\t\t\t\t--\t\t\t\t\t\tif @CasualBalance>@Remain begin\r\n",
+ "\t\t\t\t\t--\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late',@CasualLeaveType,@Remain)\r\n",
+ "\t\t\t\t\t--\t\t\t\t\t\tend\r\n",
+ "\t\t\t\t\t--\t\t\t\t\t\telse begin\r\n",
+ "\t\t\t\t\t--\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late',@CasualLeaveType,@CasualBalance)\r\n",
+ "\t\t\t\t\t--\t\t\t\t\t\t\tset @Remain=@Val-@CasualBalance\r\n",
+ "\t\t\t\t\t--\t\t\t\t\t\t\tif @Remain>0 begin\r\n",
+ "\t\t\t\t\t--\t\t\t\t\t\t\t\tif @SickBalance>@Remain begin\r\n",
+ "\t\t\t\t\t--\t\t\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late',@SickLeaveType,@Remain)\r\n",
+ "\t\t\t\t\t--\t\t\t\t\t\t\t\tend\r\n",
+ "\t\t\t\t\t--\t\t\t\t\t\t\t\telse begin\r\n",
+ "\t\t\t\t\t--\t\t\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late',@SickLeaveType,@SickBalance)\r\n",
+ "\t\t\t\t\t--\t\t\t\t\t\t\t\t\tset @Remain=@Val-@SickBalance\r\n",
+ "\r\n",
+ "\t\t\t\t\t--\t\t\t\t\t\t\t\t\tif @Remain>0 begin\r\n",
+ "\t\t\t\t\t--\t\t\t\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late',0,@Remain)\r\n",
+ "\t\t\t\t\t--\t\t\t\t\t\t\t\t\tend\r\n",
+ "\r\n",
+ "\r\n",
+ "\r\n",
+ "\t\t\t\t\t\t--if @CasualBalance>@Val begin\r\n",
+ "\t\t\t\t\t\t--\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days,UpdatedOn) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late',@CasualLeaveType,@Val, getdate())\r\n",
+ "\t\t\t\t\t\t--end\r\n",
+ "\t\t\t\t\t\t--else begin\r\n",
+ "\t\t\t\t\t\t--\tif @CasualBalance>0 begin\r\n",
+ "\t\t\t\t\t\t--\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days,UpdatedOn) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late',@CasualLeaveType,@CasualBalance,getdate())\r\n",
+ "\t\t\t\t\t\t--\t\tset @Remain=@Val-@CasualBalance\r\n",
+ "\t\t\t\t\t\t--\t\tif @Remain>0 begin\r\n",
+ "\t\t\t\t\t\t--\t\t\tif @SickBalance>@Remain begin\r\n",
+ "\t\t\t\t\t\t--\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days,UpdatedOn) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late',@SickLeaveType,@Remain,getdate())\r\n",
+ "\t\t\t\t\t\t--\t\t\tend\r\n",
+ "\t\t\t\t\t\t--\t\t\telse begin\r\n",
+ "\t\t\t\t\t\t--\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days,UpdatedOn) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late',@SickLeaveType,@SickBalance,getdate())\r\n",
+ "\t\t\t\t\t\t--\t\t\t\tset @Remain=@Val-@SickBalance\r\n",
+ "\t\t\t\t\t\t--\t\t\t\tif @Remain>0 begin\r\n",
+ "\t\t\t\t\t\t--\t\t\t\t\tif @AnnualBalance>@Remain begin\r\n",
+ "\t\t\t\t\t\t--\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days,UpdatedOn) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late',@AnnualLeaveType,@Remain,getdate())\r\n",
+ "\t\t\t\t\t\t--\t\t\t\t\tend\r\n",
+ "\t\t\t\t\t\t--\t\t\t\t\telse begin\r\n",
+ "\t\t\t\t\t\t--\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days,UpdatedOn) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late',@AnnualLeaveType,@AnnualBalance,getdate())\r\n",
+ "\t\t\t\t\t\t--\t\t\t\t\t\tset @Remain=@Val-@AnnualBalance\r\n",
+ "\t\t\t\t\t\t--\t\t\t\t\t\tif @Remain>0 begin\r\n",
+ "\t\t\t\t\t\t--\t\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days,UpdatedOn) values (@Empcode,@PayPeriodCode,@SDate,0,'Half Day On 3 Days Late',0,@Remain,getdate())\r\n",
+ "\t\t\t\t\t\t--\t\t\t\t\t\tend\r\n",
+ "\t\t\t\t\t\t\t\t\t\t\tend\r\n",
+ "\t\t\t\t\t\t\t\t\t\tend\r\n",
+ "\t\t\t\t\t\t\t\t\tend\r\n",
+ "\t\t\t\t\t\t\t\tend\r\n",
+ "\t\t\t\t\t\t\tend\r\n",
+ "\t\t\t\t\t\tend\r\n",
+ "\r\n",
+ "\t\t\t\t\t\t\t\r\n",
+ "\t\t\t\t\t\tdelete [dbo].MI_EPRF_AutoLeaveDeduction where Employeecode=@Empcode and Payperiod=@PayPeriodCode and Days=0\r\n",
+ "\t\t\t\t\tend\r\n",
+ "\t\t\t\t\tset @cnt=0\r\n",
+ "\t\t\t\t\tDeclare @used decimal(18,2)\r\n",
+ "\t\t\t\t\tselect @Annual=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where EmployeeCode=@Empcode and Payperiod=@PayPeriodCode and LeaveType=@AnnualLeaveType\r\n",
+ "\t\t\t\t\tset @Annual=isnull(@Annual,0)\r\n",
+ "\t\t\t\t\tif @Annual>0 begin\r\n",
+ "\t\t\t\t\t\tselect @used=used from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@AnnualLeaveType\r\n",
+ "\t\t\t\t\t\tset @used=isnull(@used,0)\r\n",
+ "\t\t\t\t\t\tset @used=@used+@Annual\r\n",
+ "\t\t\t\t\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=@Used where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@AnnualLeaveType\r\n",
+ "\t\t\t\t\tend\r\n",
+ "\t\t\t\t\tselect @Casual=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where EmployeeCode=@Empcode and Payperiod=@PayPeriodCode and LeaveType=@CasualLeaveType\r\n",
+ "\t\t\t\t\tset @Casual=isnull(@Casual,0)\r\n",
+ "\t\t\t\t\tif @Casual>0 begin\r\n",
+ "\t\t\t\t\t\tselect @used=used from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@CasualLeaveType\r\n",
+ "\t\t\t\t\t\tset @used=isnull(@used,0)\r\n",
+ "\t\t\t\t\t\tset @used=@used+@Casual\r\n",
+ "\t\t\t\t\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=@Used where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@CasualLeaveType\r\n",
+ "\t\t\t\t\tend\r\n",
+ "\t\t\t\t\tselect @Sick=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where EmployeeCode=@Empcode and Payperiod=@PayPeriodCode and LeaveType=@SickLeaveType\r\n",
+ "\t\t\t\t\tset @Sick=isnull(@Sick,0)\r\n",
+ "\t\t\t\t\tif @Sick>0 begin\r\n",
+ "\t\t\t\t\t\tselect @used=used from [dbo].MI_ONTIME_LeaveAllocation where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\t\t\t\t\t\tset @used=isnull(@used,0)\r\n",
+ "\t\t\t\t\t\tset @used=@used+@Sick\r\n",
+ "\t\t\t\t\t\tupdate [dbo].MI_ONTIME_LeaveAllocation set Used=@Used where EmployeeCode=@Empcode and LeaveYear=@LeaveYear and LeaveTypeCode=@SickLeaveType\r\n",
+ "\t\t\t\t\tend\r\n",
+ "\t\t\t\t\t\t\r\n",
+ "\t\t\t\t--end\r\n",
+ "\t\t\tend\r\n",
+ "\t\t\tif @Empcode not in (Select employeecode from [dbo].MI_Employer_Employee where number in(Select number from [dbo].MI_Attendance_ExemptedEmployees)) begin\r\n",
+ "\t\t\t\t\t\r\n",
+ "\t\t\t\t\t\r\n",
+ "\t\t\t\tif (@ThisMonth=month(@DOR) and @ThisYear=Year(@DOR)) and @LastMonthGrossSalary=0 begin\r\n",
+ "\t\t\t\t\tdeclare EffectedEmployee cursor for\r\n",
+ "\t\t\t\t\tselect Date from [dbo].MI_ONTIME_Attendance where EmployeeCode =@EmpCode and date >= @LSdate and date <= @DOR and Present=0 and Expected=1 and LeaveAmount=0\r\n",
+ "\t\t\t\tend\r\n",
+ "\t\t\t\telse begin\r\n",
+ "\t\t\t\t\tdeclare EffectedEmployee cursor for\r\n",
+ "\t\t\t\t\tselect Date from [dbo].MI_ONTIME_Attendance where EmployeeCode =@EmpCode and date >= @Sdate and date <= @Edate and Present=0 and Expected=1 and LeaveAmount=0\r\n",
+ "\t\t\t\tend\r\n",
+ "\t\t\t\t\t\r\n",
+ "\t\t\t\topen EffectedEmployee\r\n",
+ "\t\t\t\tfetch next from EffectedEmployee into @Date\r\n",
+ "\t\t\t\twhile @@Fetch_status = 0\r\n",
+ "\t\t\t\t\tbegin\t\t\r\n",
+ "\r\n",
+ "\t\t\t\t\t\tDECLARE @annualBalanceTemp Decimal(18,2) = 0;\t--1\r\n",
+ "\t\t\t\t\t\tDECLARE @casualBalanceTemp Decimal(18,2) = 0;\t--2\r\n",
+ "\t\t\t\t\t\tDECLARE @sickBalanceTemp Decimal(18,2) = 0;\t\t--3\r\n",
+ "\r\n",
+ "\t\t\t\t\t\tSELECT @annualBalanceTemp = (Allocated-Used) from MI_ONTIME_LeaveAllocation where EmployeeCode = @Empcode and LeaveTypeCode = 1 and LeaveYear = @LeaveYear\r\n",
+ "\t\t\t\t\t\tSELECT @casualBalanceTemp = (Allocated-Used) from MI_ONTIME_LeaveAllocation where EmployeeCode = @Empcode and LeaveTypeCode = 2 and LeaveYear = @LeaveYear\r\n",
+ "\t\t\t\t\t\tSELECT @sickBalanceTemp = (Allocated-Used) from MI_ONTIME_LeaveAllocation where EmployeeCode = @Empcode and LeaveTypeCode = 3 and LeaveYear = @LeaveYear\r\n",
+ "\r\n",
+ "\r\n",
+ "\t\t\t\t\t\tIF @sickBalanceTemp > 1\r\n",
+ "\t\t\t\t\t\t\tSET @LeaveType = 3;\r\n",
+ "\t\t\t\t\t\tELSE IF @casualBalanceTemp > 1\r\n",
+ "\t\t\t\t\t\t\tSET @LeaveType = 2;\r\n",
+ "\t\t\t\t\t\tELSE IF @annualBalanceTemp > 1\r\n",
+ "\t\t\t\t\t\t\tSET @LeaveType = 1;\r\n",
+ "\t\t\t\t\t\tELSE\r\n",
+ "\t\t\t\t\t\t\tSET @LeaveType = 0;\r\n",
+ "\t\t\t\t\t\tInsert into [dbo].MI_EPRF_AutoLeaveDeduction (Employeecode, Payperiod, Date, LateHours, Reason,LeaveType,Days) values (@Empcode,@PayPeriodCode,@Date,0,'Absent',0,1)\t\t\r\n",
+ "\t\t\t\tfetch next from EffectedEmployee into @Date\r\n",
+ "\t\t\t\tEnd\r\n",
+ "\t\t\t\tclose EffectedEmployee\r\n",
+ "\t\t\t\tdeallocate EffectedEmployee\r\n",
+ "\t\t\t\tset @Autonopay=isnull(@Autonopay,0)\r\n",
+ "\t\t\t\tselect @Autonopay=sum(Days) from [dbo].MI_EPRF_AutoLeaveDeduction where Employeecode=@Empcode and Payperiod=@PayPeriodCode and LeaveType=0\r\n",
+ "\t\t\t\tset @Autonopay=isnull(@Autonopay,0)\r\n",
+ "\t\t\tend\r\n",
+ "\r\n",
+ "--========================End Auto Nopay days================================================\r\n",
+ "\t\t\t\r\n",
+ "\t\t\tEND TRY\r\n",
+ "\t\t\t\tBEGIN CATCH\r\n",
+ "\t\t\t\t\t\t\tSELECT ERROR_MESSAGE() as ErrorMessage\r\n",
+ "\t\t\t\t\t\t\tSELECT GETDATE()\r\n",
+ "\t\t\t\t\t\t\t--insert into [dbo].error values (ERROR_MESSAGE(),GETDATE(),@EmpCode)\r\n",
+ "\t\t\t\t\t\t\tset @Success = 0\r\n",
+ "\t\t\t\t\t\t\tset @Message = 'Error ocured while syncing'\r\n",
+ "\t\t\t\t\t\t\t\r\n",
+ "\t\t\t\tEND CATCH;\r\n",
+ "\tFETCH NEXT FROM Input_all into @Empcode\r\n",
+ "\t\r\n",
+ "END\r\n",
+ "close Input_all\r\n",
+ "Deallocate Input_all\r\n",
+ "--Update [dbo].[MI_PROLL_ProcessEmployee] SET Deleted=1\r\n",
+ "--update [dbo].[MI_PROLL_PayrollProcessing] set Deleted=1 where TemplateCode=@TemplateCode AND InvokedBy=@InvokedBy AND Deleted=0\r\n",
+ "--update [dbo].[MI_PROLL_PayrollProcessing] set ProcessingStatus=1 where TemplateCode=@TemplateCode AND InvokedBy=@InvokedBy AND Deleted=1\r\n",
+ "UPDATE [dbo].[MI_PROLL_ProcessEmployee]\r\n",
+ "\t SET Deleted = 1;\r\n",
+ "update [dbo].[MI_PROLL_PayrollProcessing] set Processingstatus=1 where TemplateCode=@TemplateCode AND InvokedBy=@InvokedBy AND Deleted=0\r\n",
+ "\t--update [dbo].[MI_PROLL_PayrollProcessing] set Deleted=1 where TemplateCode=@TemplateCode AND InvokedBy=@InvokedBy AND Deleted=0\r\n",
+ "\t--select @Message As Message, @Success As Success\r\n",
+ "\r\n",
+ "\t\t\t\t--select @Message As Message, @Success As Success\r\n",
+ "\r\n",
+ "\r\n",
+ "IF @@ERROR <> 0\r\n",
+ "\tBEGIN\r\n",
+ "\t\tSET @Success=0\r\n",
+ "\t\tSET @Result = 0\r\n",
+ "\t\tSET @Message = 'Unable to complete the action'\r\n",
+ "\tEND\r\n",
+ "ELSE BEGIN\r\n",
+ "\tBEGIN\r\n",
+ "\t\tSET @Success=1\r\n",
+ "\t\tSET @Result = 1\r\n",
+ "\t\tSET @Message = 'Action completed sucsessfully'\r\n",
+ "\tEND\r\n",
+ "END\r\n",
+ "\r\n",
+ "SELECT @Result AS [Result], @Message AS [Message], @Success AS [Success]\r\n",
+ ""
+ ],
+ "metadata": {
+ "azdata_cell_guid": "97e80a65-5746-439b-a2fe-e1641d0b2f61"
+ },
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Search Employee"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "81faffec-67b2-428c-9cec-9cc9eb404cf3"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "select * from MI_Employer_Employee where FullName like '%hubna%' and Deleted=0\n",
+ "select * from MI_Employer_Employee where Number like '612001'"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "896b9610-e0ab-441e-9405-9650d51b42bf"
+ },
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Check Attendance data by from client"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "a25014c5-bbc8-4c8e-aa7f-022114a7fde4"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "select count(*) from MI_ONTIME_Attendance where (InTime !='1901-01-01' OR OutTime!='1901-01-01' ) \n",
+ "and EmployeeCode in (\n",
+ "select distinct EmployeeCode from MI_Employer_Employee where Level2Code=1 AND DELETED=0\n",
+ "and textcardnumber in (\n",
+ "SELECT distinct TextCardNumber FROM MI_ONTIME_Log where TextCardNumber in (select distinct TextCardNumber from MI_Employer_Employee where Level2Code=1 AND DELETED=0) and date='2021-02-02'\n",
+ "union\n",
+ "SELECT distinct TextCardNumber FROM MI_ONTIME_BackLog where TextCardNumber in (select distinct TextCardNumber from MI_Employer_Employee where Level2Code=1 AND DELETED=0) and date='2021-02-02'\n",
+ ") )\n",
+ "and date='2021-02-01'"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "38d3a38c-b195-43e3-94ca-c9110438ef01",
+ "tags": [
+ "hide_input"
+ ]
+ },
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "**Excel Quries**\n",
+ "\n",
+ "For sql formate\n",
+ "\n",
+ "- \\=\",'\"&C2&\"'\" \n",
+ "\n",
+ "For update leaeves by number\n",
+ "\n",
+ "- \\=\"update MI\\_ONTIME\\_LeaveAllocation set Allocated=\"&H1712&\" where LeaveYear=2021 and Deleted=0 and LeaveTypeCode=1 and EmployeeCode=(select EmployeeCode from MI\\_Employer\\_Employee where number='\"&C1712&\"' and Deleted=0)\""
+ ],
+ "metadata": {
+ "azdata_cell_guid": "faaa19b6-20d8-45ab-a78c-e38f7d019a4b"
+ }
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "insert leaves into LeaveAllocation and Leave Balances excel"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "3dbad9e1-3085-4890-af44-0f65df382afe"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "\tinsert into MI_ONTIME_LeaveAllocation values ( 1,(select employeecode from MI_Employer_Employee where TextCardNumber=''), 2021,al,0,0,1,1,getdate(),0,'1901-01-01',0,'1901-01-01')\r\n",
+ "=\"insert into Leavebalances values (1,2021,0,getdate(),\"&K29&\",0,(select EmployeeCode from MI_Employer_Employee where Number='\"&B29&\"' and deleted=0))\""
+ ],
+ "metadata": {
+ "azdata_cell_guid": "00b6aa73-d397-4366-b548-bd52a42c1768"
+ },
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Leaves update from excel"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "f4c0247e-1407-481a-b995-47d18fe28b54"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "DECLARE @emp_id int \r\n",
+ "DECLARE @annual decimal(18,2) \r\n",
+ "\r\n",
+ "DECLARE emp_cursor CURSOR FOR \r\n",
+ "select MI_Employer_Employee.EmployeeCode, annual from Sheet1 \r\n",
+ "inner join MI_Employer_Employee on MI_Employer_Employee.Number = Sheet1.id and Deleted=0 \r\n",
+ "where Annual!=0 and id is not null \r\n",
+ " \r\n",
+ "OPEN emp_cursor \r\n",
+ " \r\n",
+ "FETCH NEXT FROM emp_cursor INTO @emp_id ,@annual \r\n",
+ " \r\n",
+ "WHILE @@FETCH_STATUS = 0 \r\n",
+ "BEGIN \r\n",
+ " if not exists (select * from mi_ontime_leaveallocation where EmployeeCode=@emp_id and LeaveTypeCode=1 and LeaveYear=2021) \r\n",
+ "\tand @annual>0 and @emp_id >0\r\n",
+ " begin \r\n",
+ "\tinsert into MI_ONTIME_LeaveAllocation values (1,@emp_id,2021,@annual,0,0,1,1,getdate(),1,'1901-01-01',1,'1901-01-01') \r\n",
+ "\tend\r\n",
+ " \r\n",
+ " FETCH NEXT FROM emp_cursor \r\n",
+ "INTO @emp_id ,@annual\r\n",
+ " \r\n",
+ "END \r\n",
+ "CLOSE emp_cursor; \r\n",
+ "DEALLOCATE emp_cursor;\r\n",
+ "--44593\r\n",
+ "select count(*) from MI_ONTIME_LeaveAllocation\r\n",
+ "select distinct id from Sheet1 \r\n",
+ "where Annual!=0 and id is not null\r\n",
+ "delete from MI_ONTIME_LeaveAllocation where LeaveAllocationCode>55707 --order by CreatedDate desc\r\n",
+ "select top 1000 * from MI_ONTIME_LeaveAllocation where LeaveAllocationCode>55707\r\n",
+ "select getdate()"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "491eb93e-b8f5-43be-b63e-7178ba19b8fd"
+ },
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "insert leaves by query using number and allocated amount"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "24453003-0999-46f2-8fd8-0f3007ca1830"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "Declare @emp_code int=0\r\n",
+ "set @emp_code =(select EmployeeCode,* from MI_Employer_Employee where Number='631403' and deleted=0) \r\n",
+ "\r\n",
+ "if not exists (select * from mi_ontime_leaveallocation where EmployeeCode=@emp_code and LeaveTypeCode=1 and LeaveYear=2021) \r\n",
+ "begin \r\n",
+ "insert into MI_ONTIME_LeaveAllocation values (1,@emp_code,2021,28,0,0,1,1,getdate(),1,'1901-01-01',1,'1901-01-01')\r\n",
+ "end"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "5858e8ea-b8cc-4f43-8acc-5b7f00212a21"
+ },
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Get Dublicates"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "61c2bc4c-de80-4eed-97c0-810e1e8e772b"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "select FullName,Number, TextCardNumber, NicNumber, EpfNo,\r\n",
+ "MI_EPRF_OrgLevel2.Name level2,\r\n",
+ "MI_EPRF_OrgLevel3.Name level3,\r\n",
+ "MI_EPRF_OrgLevel4.Name level4,\r\n",
+ "MI_EPRF_OrgLevel5.Name level5,\r\n",
+ "MI_EPRF_OrgLevel6.Name level6,\r\n",
+ "MI_EPRF_OrgLevel7.Name level7,\r\n",
+ "MI_EPRF_OrgLevel8.Name level8\r\n",
+ "from MI_Employer_Employee\r\n",
+ "left join MI_EPRF_OrgLevel2 on MI_EPRF_OrgLevel2.Level2Code = MI_Employer_Employee.Level2Code\r\n",
+ "left join MI_EPRF_OrgLevel3 on MI_EPRF_OrgLevel3.Level3Code = MI_Employer_Employee.Level3Code\r\n",
+ "left join MI_EPRF_OrgLevel4 on MI_EPRF_OrgLevel4.Level4Code = MI_Employer_Employee.Level4Code\r\n",
+ "left join MI_EPRF_OrgLevel5 on MI_EPRF_OrgLevel5.Level5Code = MI_Employer_Employee.Level5Code\r\n",
+ "left join MI_EPRF_OrgLevel6 on MI_EPRF_OrgLevel6.Level6Code = MI_Employer_Employee.Level6Code\r\n",
+ "left join MI_EPRF_OrgLevel7 on MI_EPRF_OrgLevel7.Level7Code = MI_Employer_Employee.Level7Code\r\n",
+ "left join MI_EPRF_OrgLevel8 on MI_EPRF_OrgLevel8.Level8Code = MI_Employer_Employee.Level8Code\r\n",
+ "where TextCardNumber !='' and TextCardNumber in (select TextCardNumber from MI_Employer_Employee \r\n",
+ "where Deleted=0 \r\n",
+ "group by TextCardNumber\r\n",
+ "having count(TextCardNumber)>1) \r\n",
+ "order by TextCardNumber"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "8f09ee39-9b25-4ff7-bdc8-25a259118721"
+ },
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Leaves work LTM"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "b6e680ea-0b45-499a-98dc-8ebd123b6f77"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "insert into MI_ONTIME_LeaveAllocation \r\n",
+ "SELECT 1,EmployeeCode, 2021,Allocated,0,0,1,0,getdate(),0,'1901-01-01',0,'1901-01-01' FROM Leavebalances WHERE Deleted=0 --AND EmployeeCode \r\n",
+ "--NOT IN (\r\n",
+ "--select distinct employeecode from\tMI_Employer_Employee where EmploymentTypecode=1 and deleted=0 and datediff(MONTH, DateOfAppointment,getdate()) >=12\r\n",
+ "--and cast(getdate() as date)>=concat(SELECT * FROM LeavesAllocatedHistory WHERE DELETED=0\r\n",
+ "insert LeavesAllocatedHistory year(getdate()),'-',concat(REPLICATE('0', 2-LEN(month(Dateofappointment))),month(Dateofappointment)),'-',concat(REPLICATE('0', 2-LEN(day(dateofappointment))),day(dateofappointment)))) \r\n",
+ "update LeavesAllocatedHistory set Deleted=1, UpdatedDate=getdate() where Deleted=0 and EmployeeCode in \r\n",
+ "(select EmployeeCode from\tMI_Employer_Employee where EmploymentTypecode=1 and deleted=0 and datediff(MONTH, DateOfAppointment,getdate()) >=12\r\n",
+ "and concat(year(getdate()),'-',concat(REPLICATE('0', 2-LEN(month(Dateofappointment))),month(Dateofappointment)),'-',concat(REPLICATE('0', 2-LEN(day(dateofappointment))),day(dateofappointment))) <= '2021-03-04'\r\n",
+ "and EmployeeCode not in (select EmployeeCode from MI_ONTIME_LeaveAllocation where LeaveTypeCode=1 and Deleted=0) and\r\n",
+ "EmployeeCode in (select EmployeeCode from LeavesAllocatedHistory where deleted=0 ))\r\n",
+ "select * from Leavebalances where EmployeeCode=2188\r\n",
+ "select * from Leavebalances where EmployeeCode=1901\r\n",
+ "\r\n",
+ "UPDATE LeavesAllocatedHistory SET Deleted=1, UpdatedDate=GETDATE() WHERE Deleted=0 \r\n",
+ "update MI_ONTIME_LeaveAllocation set Deleted=0 where DeletedDate > '2021-02-12 13:43:07.630' and Deleted=1 order by DeletedDate \r\n",
+ "UPDATE MI_ONTIME_LeaveAllocation set Deleted=1, DeletedDate=GETDATE() where LeaveTypeCode=1 and Deleted=0\r\n",
+ "SELECT * FROM MI_ONTIME_LeaveAllocation where LeaveTypeCode=1 and Deleted=0\r\n",
+ "select * from Leavebalances where deleted=0 AND EmployeeCode=\r\n",
+ "\r\n",
+ "select COUNT(*) from MI_ONTIME_LeaveAllocation where deleted=0 AND LeaveTypeCode=3\r\n",
+ "\r\n",
+ "select COUNT(*) from LeavesAllocatedHistory where deleted=0\r\n",
+ "\r\n",
+ "select * from mi_ontime_leaveallocation where employeecode=2495 AND Deleted=0\r\n",
+ "Select Allocated from dbo.MI_ONTIME_LeaveAllocation where EmployeeCode = 2495 and LeaveYear = 2021 and LeaveTypeCode = 1 AND Deleted=0\r\n",
+ "\r\n",
+ "select * from MI_ONTIME_LeaveAllocation where EmployeeCode in (\r\n",
+ "select employeecode from\tMI_Employer_Employee where DateOfAppointment!='1901-01-01 00:00:00.000' AND datediff(MONTH, DateOfAppointment,getdate()) >=12\r\n",
+ "and YEAR(DateOfAppointment) <2020 AND MONTH(DateOfAppointment) < 2 AND MI_Employer_Employee.EmploymentTypeCode=1\r\n",
+ ") and Deleted=0 and LeaveTypeCode=1\r\n",
+ "select dateofappointment from\tMI_Employer_Employee WHERE (dateofappointment IS NULL OR dateofappointment <'2000-01-01')\r\n",
+ "\r\n",
+ "\r\n",
+ "select Allocated, Used,EmployeeCode from MI_ONTIME_LeaveAllocation where LeaveTypeCode=1 and Deleted=0 and \r\n",
+ "EmployeeCode in (select EmployeeCode from Leavebalances where Deleted=0 and LeaveTypeCode=1 )\r\n",
+ "\r\n",
+ "insert into MI_ONTIME_LeaveAllocation \r\n",
+ "SELECT datediff(year,e.DateOfBirth,getdate()),e.DateOfAppointment,e.EmploymentTypeCode ,1,Leavebalances.EmployeeCode, 2021,Allocated,0,0,1,0,getdate(),0,'1901-01-01',0,'1901-01-01' FROM Leavebalances \r\n",
+ "inner join MI_Employer_Employee e on e.EmployeeCode = Leavebalances.EmployeeCode\r\n",
+ "where Leavebalances.Deleted=0 and LeaveTypeCode=1 and Leavebalances.EmployeeCode not in (\r\n",
+ "select EmployeeCode from MI_ONTIME_LeaveAllocation where LeaveTypeCode=1 and Deleted=0)\r\n",
+ "\r\n",
+ "\r\n",
+ "insert into MI_ONTIME_LeaveAllocation \r\n",
+ "SELECT 1,EmployeeCode, 2021,Allocated,0,0,1,0,getdate(),0,'1901-01-01',0,'1901-01-01' from Leavebalances where Deleted=0 and LeaveTypeCode=1 and EmployeeCode not in (\r\n",
+ "select EmployeeCode from MI_ONTIME_LeaveAllocation where LeaveTypeCode=1 and Deleted=0\r\n",
+ ")\r\n",
+ "select distinct employeecode from MI_ONTIME_LeaveAllocation where LeaveTypeCode=7 and UpdatedBy !=-1\r\n",
+ "update MI_ONTIME_LeaveAllocation set Deleted=0, UpdatedDate=GETDATE() where LeaveTypeCode=7 and deleted=1 \r\n",
+ "select * from MI_ONTIME_LeaveType\r\n",
+ "select EmployeeCode, FULLNAME, EPFNO from MI_Employer_Employee where EPFNO='' and Deleted=0\r\n",
+ "select EmployeeCode, FULLNAME from MI_Employer_Employee where Number='608932' and Deleted=0\r\n",
+ "select * from MI_ONTIME_LeaveAllocation where EmployeeCode=2029 and Deleted=0 and LeaveTypeCode=1\r\n",
+ "SELECT * FROM Leavebalances WHERE EmployeeCode=10927 AND Deleted=0 AND LeaveTypeCode=1\r\n",
+ "\r\n",
+ "\r\n",
+ "select * from mi_employer_employee where "
+ ],
+ "metadata": {
+ "azdata_cell_guid": "94b0cec6-cfdc-403e-8207-28631221d25f",
+ "tags": []
+ },
+ "outputs": [],
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Man Power budget update"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "947d4054-f7a9-4779-b12b-ec7b2878592e"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "select * from MI_OD_BudgetManPower\r\n",
+ "update MI_OD_BudgetManPower set Deleted=1, UpdatedBy=-1, UpdatedDate=getdate() where Deleted=0\r\n",
+ "DECLARE @emp_id\t\tint\r\n",
+ "DECLARE @level1code int\r\n",
+ "DECLARE @level2code int\r\n",
+ "DECLARE @level3code int\r\n",
+ "DECLARE @level4code int\r\n",
+ "DECLARE @level5code int\r\n",
+ "DECLARE @level6code int\r\n",
+ "DECLARE @level7code int\r\n",
+ "DECLARE @level8code int\r\n",
+ "DECLARE @level9code int\r\n",
+ "DECLARE @level10code int\r\n",
+ "DECLARE @designationcode int\r\n",
+ " \r\n",
+ "\r\n",
+ "DECLARE emp_cursor CURSOR FOR\r\n",
+ "select EmployeeCode,level1code,Level2Code,Level3Code,level4code,Level5Code,Level6Code,Level7Code,Level8Code,Level9Code\r\n",
+ ",Level10Code,DesignationCode\r\n",
+ "from MI_Employer_Employee where \t Deleted=0\r\n",
+ " \r\n",
+ "\t \r\n",
+ "\r\n",
+ "OPEN emp_cursor\r\n",
+ "\r\n",
+ "FETCH NEXT FROM emp_cursor INTO\r\n",
+ " @emp_id\t\t\r\n",
+ ",@level1code \r\n",
+ ",@level2code \r\n",
+ ",@level3code \r\n",
+ ",@level4code \r\n",
+ ",@level5code \r\n",
+ ",@level6code \r\n",
+ ",@level7code \r\n",
+ ",@level8code \r\n",
+ ",@level9code \r\n",
+ ",@level10code\r\n",
+ ",@designationcode\r\n",
+ "\r\n",
+ "WHILE @@FETCH_STATUS = 0\r\n",
+ "BEGIN\r\n",
+ "\tif not exists (select *\r\n",
+ "\t\tfrom MI_OD_BudgetManPower\r\n",
+ "\t\twhere\r\n",
+ " level1code = @level1code \r\n",
+ "and level2code = @level2code \r\n",
+ "and level3code = @level3code \r\n",
+ "and level4code = @level4code \r\n",
+ "and level5code = @level5code \r\n",
+ "and level6code = @level6code \r\n",
+ "and level7code = @level7code \r\n",
+ "and level8code = @level8code \r\n",
+ "and level9code = @level9code \r\n",
+ "and level10code = @level10code\r\n",
+ "and designationcode = @designationcode\r\n",
+ "and Deleted=0\r\n",
+ "\r\n",
+ "\t\t\t)\r\n",
+ "\t\t\r\n",
+ "\tbegin\r\n",
+ "\t\tinsert into MI_OD_BudgetManPower\r\n",
+ "\t\tvalues ( @level1code \r\n",
+ ",@level2code \r\n",
+ ",@level3code \r\n",
+ ",@level4code \r\n",
+ ",@level5code \r\n",
+ ",@level6code \r\n",
+ ",@level7code \r\n",
+ ",@level8code \r\n",
+ ",@level9code \r\n",
+ ",@level10code\r\n",
+ ",0\r\n",
+ ",@designationcode, 1,1,0, 0, 1, 1, getdate(), 0, '1901-01-01', 0, '1901-01-01' )\r\n",
+ "\tend\r\n",
+ "\telse\r\n",
+ "\tbegin\r\n",
+ "\t\tupdate MI_OD_BudgetManPower\r\n",
+ "\t\tset BudgetHeadCount = BudgetHeadCount+1--,RequestedBudget=RequestedBudget+1\r\n",
+ "\t\twhere \r\n",
+ "\t\t level1code = @level1code \r\n",
+ "and level2code = @level2code \r\n",
+ "and level3code = @level3code \r\n",
+ "and level4code = @level4code \r\n",
+ "and level5code = @level5code \r\n",
+ "and level6code = @level6code \r\n",
+ "and level7code = @level7code \r\n",
+ "and level8code = @level8code \r\n",
+ "and level9code = @level9code \r\n",
+ "and level10code = @level10code\r\n",
+ "and designationcode = @designationcode\r\n",
+ "and Deleted=0\r\n",
+ "\tend\r\n",
+ "\r\n",
+ "FETCH NEXT FROM emp_cursor INTO\r\n",
+ " @emp_id\t\t\r\n",
+ ",@level1code \r\n",
+ ",@level2code \r\n",
+ ",@level3code \r\n",
+ ",@level4code \r\n",
+ ",@level5code \r\n",
+ ",@level6code \r\n",
+ ",@level7code \r\n",
+ ",@level8code \r\n",
+ ",@level9code \r\n",
+ ",@level10code\r\n",
+ ",@designationcode\r\n",
+ "\r\n",
+ "END\r\n",
+ "CLOSE emp_cursor;\r\n",
+ "DEALLOCATE emp_cursor;"
+ ],
+ "metadata": {
+ "azdata_cell_guid": "3a67aba2-9735-431e-836d-ed97bebc4367"
+ },
+ "outputs": [],
+ "execution_count": null
+ }
+ ]
+}
\ No newline at end of file