Document
Document
• budget.component.html
<form [formGroup]="myForm">
<div class="newrow">
<div class="product-logo">
</div>
<ng-multiselect-dropdown
[settings]="dropdownSettingsYear"
class="yearDropdown"
[data]="numberOfYearsOptions"
(ngModelChange)="onNumberOfYearsChange($event)"
[singleSelection]="true"
formControlName="numberOfYears"
(onDeSelect)="onItemDeSelect($event)"
>
</ng-multiselect-dropdown>
</div>
<ng-multiselect-dropdown
[settings]="dropdownSettingsSelectYear"
[placeholder]="'Select Year'"
[data]="selectYearOptions"
[singleSelection]="true"
formControlName="selectYear"
(onSelect)="onYearSelect($event)"
>
</ng-multiselect-dropdown>
</div>
<ng-multiselect-dropdown
[settings]="dropdownSettingsPercentage"
[placeholder]="'Select Percentage'"
[data]="percentageOption"
[singleSelection]="true"
formControlName="percentage"
(onSelect)="onPercentageSelect($event)"
>
</ng-multiselect-dropdown>
</div>
<button class="buttonload"
style="position:absolute;margin-left: 690px;
border-radius: 5px;
background-color: #23527a;
color: #ffffff;"
type="submit"
[loading]="loading" (click)="onButtonClick()">
Go</button>
<button class="buttonload"
style="position:absolute;
border-radius: 5px;
background-color: #23527a;
margin-left: 760px;
color: #ffffff;"
type="submit"
[loading]="loading" (click)="convertToJson2()">
Save</button>
Welcome<br />
Yadnya
</div>
</div>
<span class="dot">Y</span>
</div>
</div>
</div>
</div>
<div *ngIf="loading" class="d-flex align-items-center">
<strong>Loading...</strong>
</div>
<br>
<div class="row">
<thead class="custom-table1">
<tr>
<th colspan="2">Description</th>
<th [attr.colspan]="selectedNumberOfYears+1">Years</th>
</tr>
<tr>
<td>acc_cat</td>
<td >acc_grp</td>
<td>2024</td>
</tr>
</thead>
<tbody>
<td></td>
{{ data.totalResultAcWise[year] || '0.00' }}
</td>
</tr>
<tr>
<td></td>
{{ data.dsAccGrpDesc }}
</td>
{{ data.totalResult[year] || '0.00' }}
</td>
</tr>
</ng-container>
</tbody>
</table>
</div>
</div>
</div>
</form>
<thead class="custom-table1">
<tr>
<th colspan="2">Description</th>
<th [attr.colspan]="selectedNumberOfYears+1">Years</th>
</tr>
<tr>
<td>acc_cat</td>
<td >acc_grp</td>
<td>2024</td>
</tr>
</thead>
<tbody>
<td></td>
{{ data.totalResultAcWise[year] || '0.00' }}
</td>
</tr>
<tr>
<td></td>
{{ data.dsAccGrpDesc }}
</td>
{{ data.totalResult[year] || '0.00' }}
</td>
</tr>
</ng-container>
</tbody>
</table> -->
• dropdown.services.ts
import { HttpClient, HttpHeaders, } from '@angular/common/http';
getApprover(idCustomer: string) {
return this.http.get<any>(`${environment.apiUrl}/api/usermaster/${idCustomer}`);
getCustomer() {
return this.http.get<any>(`${environment.apiUrl}/api/customermaster`);
getKPI1(idCustomer:string){
return this.http.get<any>(url);
getKPI(idCustomer:string){
return this.http.get<any>(`${environment.apiUrl}/api/customermaster/${idCustomer}`);
getKPICategoryMaster(idUser:string, idCustomer:string){
return this.http.get<any>(`${environment.apiUrl}/api/dropdown/kpicategorymaster/${idUser}/$
{idCustomer}`);
return this.http.get<any>(`${environment.apiUrl}/api/dropdown/kpimaster/${idUser}/${idCustomer}/$
{idCategory}`);
return this.http.get<any>(`${environment.apiUrl}/api/dropdown/kpimaster/${idCustomer}/${idCategory}/$
{idKPI}`);
return this.http.get<any>(`${environment.apiUrl}/api/dropdown/kpifiltermaster/${idUser}/${idCustomer}/$
{idKPI}`);
return this.http.get<any>(`${environment.apiUrl}/api/dropdown/authjobrole/${idUser}/${idCustomer}`);
return this.http.get<any>(`${environment.apiUrl}/api/dropdown/user/${idUser}/${idCustomer}`);
return this.http.get<any>(`${environment.apiUrl}/api/dropdown/role/${idUser}/${idCustomer}/$
{idRoleType}`);
return this.http.get<any>(`${environment.apiUrl}/api/BudgetHouse/AccDescByAccCat/${idUser}/$
{idCustomer}/${accountCat}/${accountGrp}`);
return this.http.get<any>(`${environment.apiUrl}/api/BudgetHouse/AllDesc/${idUser}/${idCustomer}`);
// return this.http.post<any>(`${environment.apiUrl}/api/BudgetHouse/AccTotalResult/${id}/${customer}`,
requestBody);
// }
`${environment.apiUrl}/api/BudgetHouse/AccTotalResult/${id}/${customer}`,
requestBody,
);
• budget.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-budget',
templateUrl: './budget.component.html',
styleUrl: './budget.component.css',
providers: [OdataService]
})
inputValue:new FormControl(),
inputValueTotalAc:new FormControl()
});
selectedNumberOfYears: any;
selectYearOptions:any[] = [];
dropdownSettingsYear:IDropdownSettings={};
dropdownSettingsPercentage:any;
dropdownSettingsSelectYear:any;
dataSet:any;
FormBuilder:any;
pnl_dataset: any[]=[];
selectedYear:any;
selectedPercentage:any;
modifiedValues: any[]=[];
modifiedValuesGrp: any[]=[];
table:any;
jsonString: any;
){}
ngOnInit() {
this.dropdownSettingsYear = {
singleSelection: true,
idField: 'item_id',
textField: 'item_text',
enableCheckAll: false,
closeDropDownOnSelection: true,
};
this.dropdownSettingsSelectYear = {
singleSelection: true,
idField: 'item_id',
textField: 'item_text',
};
this.dropdownSettingsPercentage = {
singleSelection: true,
idField: 'item_id',
textField: 'item_text',
};
this.numberOfYearsOptions = [
this.percentageOption = [
];
onYearSelect(item: any) {
this.selectedYear = item.item_text;
onPercentageSelect(item: any) {
this.selectedPercentage = item.item_id;
onButtonClick(){
this.updateTableDataAcc();
this.updateTableDataGrp();
onNumberOfYearsChange(selectedItems:any) {
// this.selectedNumberOfYears = this.myForm.get('numberOfYears')!.value;
this.selectedNumberOfYears = selectedItems[0].item_id;
var previousYear=this.getPreviousYears();
let ODataFilters = {
"PreviousYearsArr":previousYear
};
sessionStorage.setItem("ODataFilters", JSON.stringify(ODataFilters));
this.call_OData_ACC_BAL();
this.updateSelectYearDropdownData();
}
getPreviousYears(): number[] {
previousYears.push((this.currentYear-1) - i);
return previousYears.reverse();
updateSelectYearDropdownData() {
if (selectYearControl) {
selectYearControl.enable();
this.selectYearOptions = selectYearOptions;
updateTableDataAcc() {
this.modifiedValues = [];
this.pnl_dataset.forEach(data => {
if (!isNaN(yearValue)) {
this.modifiedValues.push(formatValueAcc);
//this.myForm.get('inputValueTotalAc')!.setValue(modifiedValue.toFixed(2));
} else {
});
updateTableDataGrp() {
this.modifiedValuesGrp = [];
this.pnl_dataset.forEach(data => {
if (!isNaN(yearValueGrp)) {
this.modifiedValuesGrp.push(formatValueGrp);
//this.myForm.get('inputValueTotalAc')!.setValue(modifiedValue.toFixed(2));
} else {
console.log('Invalid numeric value for selected year');
});
onSubmit(){
// var previousYear=this.getPreviousYears();
// let ODataFilters = {
// "PreviousYearsArr":previousYear
// };
// sessionStorage.setItem("ODataFilters", JSON.stringify(ODataFilters));
// this.call_OData_ACC_BAL();
call_OData_ACC_BAL(){
let q:any;
if (storedData) {
try {
q = JSON.parse(storedData);
} catch (error) {
q = {};
}
this.loading = true;
this.odataService.oData_ACC_BAL(oDataUrl).subscribe((x:any)=>{
this.loading = false;
this.dataSet = []
this.dataSet = x.d.results;
this.monthWisePNLDataset(this.dataSet,selectedYear);
})
this.pnl_dataset = [];
this.dspnl_dataset = [];
this.budget_house_dataset = [];
if (x["bal_sh_ind"] == false) {
let ac_cat = x["ac_cat"];
totalResultAcWise[gjahr] = formaClBal;
});
totalResult[gjahr] = formaClBal;
});
account_desc = data["description"];
account_grp_desc = data["groupDescription"];
} else {
this.pnl_dataset.push({
"dsAccoutCat": ac_cat,
"dsAccountgrp": ac_grp,
"dsAccountDesc": account_desc,
"dsAccGrpDesc": account_grp_desc,
"totalResultAcWise": totalResultAcWise,
"totalResult": totalResult,
"actual_amount": formatClBal
});
this.dspnl_dataset.push(this.common.sortData(this.pnl_dataset, "dsAccountgrp"));
});
});
convertToJson2() {
if (tablePNL) {
rows.forEach((row) => {
if(acc_catTemp == ""){
}else{
cells.forEach((cell, i) => {
if (i >= 2) {
if (inputElement) {
value = inputElement.value;
acc_cat: acc_cat,
year:curryear,
value: value
};
jsonData.push(rowData);
});
});
console.log(this.jsonString);
} else {
console.error('Table with ID "tableId" not found.');
console.log(data);
// // account_desc = data["description"];
// // account_grp_desc = data["groupDescription"];
// } else {
// }
});
this.budget_house_dataset = [];
this.pnl_dataset = [];
if (x["bal_sh_ind"] == true) {
totalResultAcWise[gjahr] = formaClBal;
});
totalResult[gjahr] = formaClBal;
});
let account_desc = "";
account_desc = data["description"];
account_grp_desc = data["groupDescription"];
} else {
this.budget_house_dataset.push({
"dsAccoutCat": ac_cat,
"dsAccountgrp": ac_grp,
"dsAccountDesc": account_desc,
"dsAccGrpDesc": account_grp_desc,
"totalResultAcWise": totalResultAcWise,
"totalResult": totalResult,
"cl_bal":formatClBal
});
this.dsbudget_house_dataset.push(this.common.sortData(this.budget_house_dataset, "dsAccountgrp"));
});
});
onItemDeSelect(item: any) {
}
}
3. Write method logic in BudgetHoueManager.cs public static Msg PostAccTotalResult(string id, string
customer,JsonElement jsonObject){}
4. Create Table in SQL server : Open SQL server -> Database->BudgetHouse-> Tables-> right click on it-> new-
>table-> give column names and data types.
AccountCategory NVARCHAR(255),
AccountGroup NVARCHAR(255),
Year NVARCHAR(4),
TotalResult DECIMAL(18, 2)
);
7. To open Table type go to programmability ->Types -> User-defined Table types -> check new table type is listed
or not.
Programmability -> Stored Procedure -> Right click-> new-> stored procedure.
@idUser NVARCHAR(255),
@idCustomer NVARCHAR(255),
AS
BEGIN
END;
• BudgetHouseController.cs
using BudgetHouseApi.Models;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Text;
using System.Text.Json;
using System.Data;
using Newtonsoft.Json;
namespace BudgetHouseApi.Controllers
[ApiController]
[Route("api/[controller]")]
[HttpGet("AllDesc/{id}/{customer}")]
return lst;
[HttpGet("AccDescByAccCat/{id}/{customer}/{accountCat}/{accountGroup}")]
public Models.BudgetHouse getAccDescByAccCat(string id, string customer, string accountCat, string
accountGroup)
[HttpPost("AccTotalResult/{id}/{customer}")]
• BudgetHouseManager.cs
public static Msg PostAccTotalResult(string id, string customer,JsonElement jsonObject)
try
dt.Columns.Add("AccountCategory", typeof(string));
dt.Columns.Add("AccountGroup", typeof(string));
dt.Columns.Add("Year", typeof(string));
dt.Columns.Add("TotalResult", typeof(string));
{
string accCat = element.GetProperty("acc_cat").GetString();
ParameterName = "@AccTotalResult",
SqlDbType = SqlDbType.Structured,
Value = dt,
TypeName = "dbo.AccTotalResultType"
};
if (!string.IsNullOrEmpty(objMsg.Text))
objMsg.Type = Msg.danger;
else
objMsg.Type = Msg.success;
objMsg.Data = "Bulk data inserted successfully.";
objMsg.Type = Msg.danger;
objMsg.Text = ex.Message;
return objMsg;
• Access Modifier: public static indicates that this method is accessible from outside the class and doesn't
require an instance of the class to be called.
• Parameters:-
• JsonElement jsonObject: Represents a JSON object that seems to contain accounting information.
Creates an instance of the Msg class, presumably for storing messages related to the success or failure of the
method.
• This line creates an instance of the DataAccess class and assigns it to the variable da. DataAccess seems to
be a class or object responsible for handling data access operations, likely interacting with a database.
• This line creates a new instance of the DataTable class and assigns it to the variable dt. A DataTable is an
in-memory representation of a table, and it can hold rows and columns of data, similar to a table in a
database.
#dt.Columns.Add("AccountCategory", typeof(string));
dt.Columns.Add("AccountGroup", typeof(string));
dt.Columns.Add("Year", typeof(string));
dt.Columns.Add("TotalResult", typeof(string));
• These lines add columns to the DataTable. Each Add method call adds a new column to the table. The
parameters for Add are the column name and the data type of the column. In this case, it adds four columns:
• This loop iterates over each element in the jsonObject, assuming it is an array. Let's go through each part in
detail:
This line starts a loop that iterates over each element in the jsonObject. EnumerateArray() is a method that returns an
enumerator for the elements in a JSON array.
For each iteration of the loop, a JsonElement named element represents the current element in the JSON array.
string accCat = element.GetProperty("acc_cat").GetString();:
This line extracts the value of the "acc_cat" property from the current JSON element and converts it to a string. It
assumes that the "acc_cat" property is present and has a string value.
Similarly, this line extracts the value of the "acc_grp" property from the current JSON element and converts it to a
string.
Extracts the value of the "value" property and converts it to a string. It assumes that the property is named "value."
Adds a new row to the DataTable (dt) with values from the current JSON element. The order of values corresponds
to the order of columns in the DataTable created earlier ("AccountCategory," "AccountGroup," "Year,"
"TotalResult"). Each property from the JSON element is mapped to a corresponding column in the DataTable.
ParameterName = "@AccTotalResult",
SqlDbType = SqlDbType.Structured,
Value = dt,
TypeName = "dbo.AccTotalResultType"
};
• The line SqlParameter[] sqlparam = new SqlParameter[3]; is used to create an array of SqlParameter
objects in C#. Each element in this array will represent a parameter that can be passed to a SQL query or
stored procedure.
sqlparam[0] = new SqlParameter("@idUser", id);
• This line creates a new SqlParameter and assigns it to the first slot (sqlparam[0]) in the array. It is used to
pass a parameter named @idUser with the value of the variable id. This is typically used in a SQL query or
stored procedure.Similar to the previous line, this sets up another SqlParameter in the second slot
(sqlparam[1]). It's used to pass a parameter named @idCustomer with the value of the variable customer.
ParameterName = "@AccTotalResult",
SqlDbType = SqlDbType.Structured,
Value = dt,
TypeName = "dbo.AccTotalResultType"
};
• This line creates a more complex SqlParameter in the third slot (sqlparam[2]). It is used to pass a table-
valued parameter (TVP) named @AccTotalResult.
- ParameterName = "@AccTotalResult": This specifies the name of the parameter in the SQL query or stored
procedure.
- SqlDbType = SqlDbType.Structured: Indicates that the parameter is of type structured. In this case, it's used for
passing a structured data type, likely a table.
- Value = dt: Assigns the value of the DataTable named dt to this parameter. This means the data from the DataTable
will be passed to the SQL query or stored procedure through this parameter.
- TypeName = "dbo.AccTotalResultType": Specifies the type name of the structured parameter. In this context, it's
indicating the type of the table-valued parameter, which is probably a user-defined table type named
"AccTotalResultType" in the database.
• This line is calling a method named ExecuteSP on an instance of the DataAccess class (da). The method
seems to execute a stored procedure named "InsertAccTotalResult" and takes an array of SqlParameter
objects (sqlparam) as parameters.
#objMsg.Text = ...:
• The result of the ExecuteSP method is assigned to the Text property of the objMsg object. The Text
property is likely used to store messages or information related to the execution of the stored procedure.
#if (!string.IsNullOrEmpty(objMsg.Text))
objMsg.Type = Msg.danger;
}
else
objMsg.Type = Msg.success;
After executing the stored procedure, the code checks if the Text property of the objMsg object is not null or empty.
if (!string.IsNullOrEmpty(objMsg.Text)):
If the Text property is not empty, it means there was some issue or error during the execution of the stored
procedure.
In this case, it sets the Type property of objMsg to Msg.danger, which might be a predefined constant indicating an
error or danger message.
else:
If the Text property is empty, it means the stored procedure executed successfully without any errors.
In this case, it sets the Type property of objMsg to Msg.success, indicating a successful operation.
Additionally, it sets the Data property of objMsg to the string "Bulk data inserted successfully," which might be a
success message.
* To show updated values in column of SQL server table just change the code in SQL server Stored procedure :
USE [BudgetHouse]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
@idUser NVARCHAR(255),
@idCustomer NVARCHAR(255),
AS
BEGIN
ON target.AccountCategory = source.AccountCategory
UPDATE target
ON target.AccountCategory = source.AccountCategory
FROM @AccTotalResult t
SELECT 1
);
*/
END;
Note: We can also do this using the commented code i.e by writing update and insert command.