Monday, October 7, 2024

Friday, November 3, 2023

A/C Rule

 

Example of the Golden Rules of Accounting

In the below example, we have listed different type of transactions along with the type of accounts and details of debit/credit after applying the accounting rules.

Sl No.

Accounting Transaction

Accounts Involved

Type of account

Debit/ Credit

1.

Mr Sham started a business with Rs.60,000 cash.

Cash A/c
Capital A/c

Real
Personal

Debit what comes in
Credit the giver

2.


Purchased goods for cash 25,000 Tk

Purchase A/c
Cash A/c
Real
Real

Debit what comes in
Credit what goes out

3.

Sold goods for cash 20,000 Indo Rupiah

Cash A/c
Sales A/c ( Inventory sold )

Real
Real

Debit what comes in
Credit what goes out

4.

Purchased goods from Mr Bhasha for cash 10,000 dirham

Purchase A/c (Inventory Purchased)
Cash A/c

Real
Real

Debit what comes in
Credit what goes out

5.

Sold goods to Mr Sam  8,000 KES on credit.

Mr Sam  A/c
Sales A/c ( Inventory sold )

Personal
Real

Debit the receiver
Credit what goes out

6.

Purchased furniture for Rs.6,000

Furniture A/c
Cash A/c

Real
Real

Debit what comes in
Credit what goes out

7.

Paid rent 1,500 Tk

Rent A/c
Cash A/c

Nominal
Real

Debit expenses
Credit what goes out

8.

Paid wages 10,000 Indo rupiah from Bank

Wages A/c
Bank A/c

Nominal
Real

Debit expenses
Credit what goes out

9.

Purchased goods from Ali Ltd on credit

Purchase A/c ( Inventory purchased )
Ali Ltd

Real
Personal

Debit what comes in
Credit the giver

10.

Dividend received in cash

Cash A/c
Dividend

Real
Nominal

Debit what comes in
Credit income

11.

Salary outstanding

Salary A/c
Salary Outstanding A/c

Nominal
Representative
personal

Debit expenses
Credit the representative personal account

Tuesday, March 15, 2022

oops

 Functional programming has the following problems.

  1. Reusability
  2. Extensibility
  3. Simplicity
  4. Maintainability

 

Reusability:

In Functional Programming, we need to write the same code or logic at multiple places which increases the code duplication. Later if we want to change the logic, then we need to change it at all places.

Extensibility:

It is not possible in functional programming to extend the features of a function. Suppose you have a function and you want to extend it with some additional features then it is not possible. You have to create a completely new function and then change the function as per your requirement.

Simplicity:

As extensibility and reusability are not possible in functional programming, usually we end up with lots of functions and lots of scattered code.

Maintainability:

As we don’t have Reusability, Extensibility, and Simplicity in functional Programming, so it is very difficult to manage and maintain the application code.

 

 

How we can overcome Functional Programming Problems?

We can overcome the functional programming problems (Reusability, Extensibility, Simplicity, and Maintainability) using Object-Oriented Programming. OOPs provide some principles and using those principles we can overcome the functional programming problems.

What Is Object-Oriented Programming?

Let us understand Object-Oriented Programming i.e. OOPs Concepts using C#. Object-Oriented Programming (OOPs) in C# is a design approach where we think in terms of real-world objects rather than functions or methods. Unlike procedural programming language, here in oops, programs are organized around objects and data rather than action and logic. Please have a look at the following diagram to understand this better.

 

 


Reusability:

To address reusability, object-oriented programming provides something called Classes and Objects. So, rather than copy-pasting the same code again and again in different places what you can do here is, create a class and make an instance of the class which is called object, and reuses them whenever you want.

Extensibility:

Suppose you have a function and you want to extend it with some new features that were not possible with functional programming. You have to create a completely new function and then change the whole function whatever you want. In OOPs, this problem is addressed by using some concepts called Inheritance, Aggregation, and Composition. In our upcoming article, we will discuss all these concepts in detail.

Simplicity:

Because we don’t have extensibility and reusability in functional programming, we end up with lots of functions and lots of scattered code. In OOPs, this problem is addressed by using some concepts called Abstraction, Encapsulation, and Polymorphism.

Maintainability:

As OOPs address Reusability, Extensibility, and Simplicity, we have good maintainable code and clean code which increases the maintainability of the application.

What are the OOPs Principles or OOPs Concepts in C#?

OOPs, provide 4 principles. They are

  1. Encapsulation
  2. Inheritance
  3. Polymorphism
  4. Abstraction

 

OOP stands for Object-Oriented Programming.

Procedural programming is about writing procedures or methods that perform operations on the data, while object-oriented programming is about creating objects that contain both data and methods.

Object-oriented programming has several advantages over procedural programming:

  • OOP is faster and easier to execute
  • OOP provides a clear structure for the programs
  • OOP helps to keep the C# code DRY "Don't Repeat Yourself", and makes the code easier to maintain, modify and debug
  • OOP makes it possible to create full reusable applications with less code and shorter development time

·        What are Classes and Objects?

·        Classes and objects are the two main aspects of object-oriented programming.

Class :- Car

Object volvo ,Audi,Toyota

Accept

a class is a template for objects, and an object is an instance of a class.

When the individual objects are created, they inherit all the variables and methods from the class.

 C# is associated with classes and objects, along with its attributes and methods. For example: in real life, a car is an object. The car has attributes, such as weight and color, and methods, such as drive and brake.

A Class is like an object constructor, or a "blueprint" for creating objects.

Methods normally belongs to a class, and they define how an object of a class behaves.

Just like with fields, you can access methods with the dot syntax. However, note that the method must be public. And remember that we use the name of the method followed by two parantheses () and a semicolon ; to call (execute) the method:

The public keyword is called an access modifierThe public keyword is an access modifier, which is used to set the access level/visibility for classes, fields, methods and properties.

Modifier

Description

public

The code is accessible for all classes

private

The code is only accessible within the same class

protected

The code is accessible within the same class, or in a class that is inherited from that class. 

internal

The code is only accessible within its own assembly, but not from another assembly. 

 

Sunday, March 13, 2022

Array

 

multidimensional arrays up to 32 dimensions. The multidimensional array can be declared by adding commas in the square brackets. For example, [,] declares two-dimensional array, [, ,] declares three-dimensional array, [, , ,] declares four-dimensional array, and so on. So, in a multidimensional array, no of commas = No of Dimensions - 1.

The following declares multidimensional arrays.

int[,] arr2d; // two-dimensional array

int[, ,] arr3d; // three-dimensional array

int[, , ,] arr4d ; // four-dimensional array

int[, , , ,] arr5d; // five-dimensional array

 

 

 

int[,] arr2d = new int[3,2]{ 
                                {1, 2}, 
                                {3, 4}, 
                                {5, 6} 
                            };
 
// or 
int[,] arr2d = { 
                    {1, 2}, 
                    {3, 4}, 
                    {5, 6} 
                };

 

 nt[,] arr2d = new int[3, 2]{

        {1, 2},
        {3, 4},
        {5, 6}
       };

   Console.WriteLine(arr2d[0, 0]);
   Console.WriteLine(arr2d[0, 1]);
   Console.WriteLine(arr2d[1, 0]);
   Console.WriteLine(arr2d[1, 1]);
   Console.WriteLine(arr2d[2, 0]);
   Console.WriteLine(arr2d[2, 1]);
   int[,,] arr3d1 = new int[1, 2, 2]{
   {{1, 2}, {3, 4}} // 1 row of two-dimensional array
  };

   int[,,] arr3d2 = new int[2, 2, 2]{ // 2 rows of two-dimensional array
   {{1, 2}, {3, 4}},
   {{5, 6}, {7, 8}}
  };

   int[,,] arr3d3 = new int[2, 2, 3]{ // 2 rows of two-dimensional array
   {{1, 2, 3}, {4, 5, 6}},
   {{7, 8, 9}, {10, 11, 12}}
  };

   Console.WriteLine("arr3d2 Values");
   Console.WriteLine(arr3d2[0, 0, 0]);
   Console.WriteLine(arr3d2[0, 0, 1]);
   Console.WriteLine(arr3d2[0, 1, 0]);
   Console.WriteLine(arr3d2[0, 1, 1]);
   Console.WriteLine(arr3d2[1, 0, 0]);
   Console.WriteLine(arr3d2[1, 0, 1]);
   Console.WriteLine(arr3d2[1, 1, 0]);
   Console.WriteLine(arr3d2[1, 1, 1]);


 

 

 

A jagged array is an array of array. Jagged arrays store arrays instead of literal values.

A jagged array is initialized with two square brackets [][]. The first bracket specifies the size of an array, and the second bracket specifies the dimensions of the array which is going to be stored.

 

 

 

int[][] jArray1 = new int[2][]; // can include two single-dimensional arrays 
int[][,] jArray2 = new int[3][,]; // can include three two-dimensional arrays 

 

 

int[][] jArray = new int[2][]; 
 
jArray[0] = new int[3]{1, 2, 3};
 
jArray[1] = new int[4]{4, 5, 6, 7 };

 

 // int[][] jArray = new int[2][]{

// new int[3]{1, 2, 3},


// new int[4]{4, 5, 6, 7}

//};


// Console.WriteLine(jArray[0][0]);

// Console.WriteLine(jArray[0][1]);

// Console.WriteLine(jArray[0][2]);

// Console.WriteLine(jArray[1][0]);

// Console.WriteLine(jArray[1][1]);

// Console.WriteLine(jArray[1][2]);

// Console.WriteLine(jArray[1][3]);


//int[][] jArray = new int[2][]{

// new int[3]{1, 2, 3},


// new int[4]{4, 5, 6, 7}

//};


//for (int i = 0; i < jArray.Length; i++)

//{

// for (int j = 0; j < (jArray[i]).Length; j++)

// Console.WriteLine(jArray[i][j]);

//}

Monday, November 8, 2021

What's the difference between a temp table and table variable in SQL Server?

It is very beneficial to store data in SQL Server temp tables rather than manipulate or work with permanent tables. Let’s say you want full DDL or DML access to a table, but don’t have it. You can use your existing read access to pull the data into a SQL Server temporary table and make adjustments from there. Or you don’t have permissions to create a table in the existing database, you can create a SQL Server temp table that you can manipulate. Finally, you might be in a situation where you need the data to be visible only in the current session.

SQL Server supports a few types of SQL Server temp tables that can be very helpful.

Before we proceed, if you want to follow along with any code samples, I suggest opening SQL Server Management Studio:





Local SQL temp tables

Local SQL Server temp tables are created using the pound symbol or “hashtag” followed by the table name. For example: #Table_name. SQL temp tables are created in the tempdb database. A local SQL Server temp table is only visible to the current session. It cannot be seen or used by processes or queries outside of the session it is declared in.

Here’s a quick example of taking a result set and putting it into a SQL Server temp table.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

 

/*Insert Databases names into SQL Temp Table*/

BEGIN TRY

DROP TABLE #DBRecovery

END TRY

BEGIN CATCH SELECT 1 END CATCH

 

SELECT ROWNUM = ROW_NUMBER() OVER (ORDER BY sys.[databases]),

    DBName = [name],

    RecoveryModel = [recovery_model_desc]

INTO #DBRecovery

FROM sys.[databases]

WHERE [recovery_model_desc] NOT IN ('Simple')

 

One of the most often used scenarios for SQL Server temp tables is within a loop of some sort. For example, you want to process data for a SQL statement and it you need a place to store items for your loop to read through. It provides a quick and efficient means to do so. See the code sample above, your loop can now reference the SQL Server temp table and process the records that meet the criteria of your goal.

Another reason to use SQL Server temp tables is you have some demanding processing to do in your sql statement. Let’s say that you create a join, and every time you need to pull records from that result set it has to process this join all over again. Why not just process this result set once and throw the records into a SQL temp table? Then you can have the rest of the sql statement refer to the SQL temp table name. Not only does this save on expensive query processing, but it may even make your code look a little cleaner.

There is one point that I want to make however. If the session that we’re working in has subsequent nested sessions, the SQL Server temp tables will be visible in sessions lower in the hierarchy, but not above in the hierarchy. Please allow me to visualize this.

In this quick diagram, a SQL temp table is created in Session 2. The sessions below it (sessions 3 and session 4) are able to see the SQL Server temp table. But Session 1, which is above session 2, will not be able to see the SQL Server temp table.



The SQL temp table is dropped or destroyed once the session disconnects. Many times you’ll see developers use the “DROP #Table_Name” command at the end of their statement just to clean up. But it is entirely up to you and what you’re trying to accomplish.

Also note, that in the event of name conflict (remember that SQL Server temp tables are created in the tempdb) SQL server will append a suffix to the end of the table name so that it is unique within the tempdb database. But this process is transparent to the developer/user. You can use the same name that you declared as it’s confined to that session.

Global SQL temp tables

Global SQL temp tables are useful when you want you want the result set visible to all other sessions. No need to setup permissions. Anyone can insert values, modify, or retrieve records from the table. Also note that anyone can DROP the table. Like Local SQL Server temp tables, they are dropped once the session disconnects and there are no longer any more references to the table. You can always use the “DROP” command to clean it up manually. Which is something that I would recommend.



To create a global SQL temp table, you simply use two pound symbols in front of the table name. Example: ##Global_Table_Name.

Table Variables

Table variables are created like any other variable, using the DECLARE statement. Many believe that table variables exist only in memory, but that is simply not true. They reside in the tempdb database much like local SQL Server temp tables. Also like local SQL temp tables, table variables are accessible only within the session that created them. However, unlike SQL temp tables the table variable is only accessible within the current batch. They are not visible outside of the batch, meaning the concept of session hierarchy can be somewhat ignored.

As far as performance is concerned table variables are useful with small amounts of data (like only a few rows). Otherwise a SQL Server temp table is useful when sifting through large amounts of data. So for most scripts you will most likely see the use of a SQL Server temp table as opposed to a table variable. Not to say that one is more useful than the other, it’s just you have to choose the right tool for the job.

Here is a quick example of setting up and using a table variable.

1

2

3

4

5

6

7

8

9

10

11

12

13

 

DECLARE @TotalProduct AS TABLE

(ProductID INT NOT NULL PRIMARY KEY,

 Quantity INT NOT NULL)

 

 INSERT INTO @TotalProduct

         ( [ProductID], [Quantity] )

 SELECT

  A.[ProductID],

  [Quantity] = SUM(B.Quantity)

FROM dbo.Product AS A

INNER JOIN dbo.SalesDetails AS B ON A.ProducitID = B.ProductID

 

We’ve created a table variable that will hold information regarding total quantities of a certain product sold. This is a very simplified example, and we wouldn’t use it if it contained a lot of rows. But if we were only looking at a few products this could really well. Once the table variable is populated you can then join this as a table to yet another table and gather whatever information you need. So there is a lot of flexibility and allows the developer to be quite creative.

Also, on a final note, in terms of transactions on table variables. If a developer rolls back a transaction which includes changes to the table variables, the changes made to the table variables within this particular transaction will remain intact. That is to say, other parts of this transaction in question will be rolled back, but anything referencing the table variable will not, unless that portion of your script is in error.