Вы находитесь на странице: 1из 418

Hindustan Zinc Ltd.

, Debari
A Report On Industrial Training & Project on Inventory Management System

www.studygalaxy.com

PREFACE

Depending on the sub-speciality(ies) involved, industrial engineering may also be known as operations management, management science, systems

engineering, or manufacturing engineering, usually depending on the viewpoint or motives of the user. While the term originally applied to manufacturing, nowadays the term "industrial" in industrial engineering can be somewhat misleading (leading to the typical extensions noted above). It has grown to encompass any methodical or quantitative approach to optimizing how a process, system, or organization operates. The various topics of concern to industrial engineers

include management management, supply chain

science, financial management, process

engineering, engineering engineering, operations

research, systems engineering, ergonomics, cost and value engineering, quality engineering, facilities planning, and the engineering design process.

Traditionally, a major aspect of industrial engineering was planning the layouts of factories and designing assembly lines and other manufacturing paradigms. While pursuing our industrial training here at HINDUSTAN ZINC LTD., DEBARI in IT department we developed this report covering a general overview of all the aspects of the industry and tried to lay emphasis on the computer oriented applications which also includes the project on Inventory Management System

which

we

developed

as

learning

procedure

for

in-house

software

development. The management of inventory is a significant task in sequence of operations in all the industries and being a tedious and sensitive task, performing it with the help of a well designed and organized computer application can be a great boon. The same made us choose this as the subject of our project development.

ACKNOWLEDGEMENT

Firstly, I express deep gratitude towards Mr. T.A. KOTANGLE (HOD: Department of IT, ZSD) for helping us accomplish this task by sparing his valuable time and providing us his priceless guidance. We would also like to thank all the executives of Hindustan Zinc Ltd. for providing us with all the relevant data as per the project and innovative ideas to update it with the latest technology and functions.

Last but not the least we would like to thank the college administration for allowing us to pursue our industrial training in this esteemed organization.

All Rights Reserved

No part of this report may be reproduced, stored in a retrieval system or transmitted in any form or by any means (except for review or criticism) without prior permission of the author(s). If any individual/publication/institute/ is found indulging in any such activity, legal action will be taken against accordingly.

CONTENTS

S.no.
1. 1

Topic
The Company Profile

Page

Section A Overview of Zinc Smelting & Allied Subjects of the Industry 2. 3. 4. 5. 6. 7. 15 8. 17 9. 18 10. 19 Section B Applications of Computer Science In The Industry 11. 12. 13. 25 Section C A Project On Inventory Management System SAP VSAT Simulation & Control 21 23 Industrial Engineering Logistics Finance Introduction Roasting Leaching Electrolysis Safety Engineering Human Resource 4 8 10 12 13

14. 15. 32 16. 34 17. 18. 19. 288 20. 310

General Perspective Technical Perspective

31

Design Concept

Forms Modules Reports

35 269

User Interface

THE COMPANY PROFILE

Hindustan Zinc Limited was incorporated from the erstwhile Metal Corporation of India on 10 January 1966 as a Public Sector Undertaking. In April 2002, Sterlite Opportunities and Ventures Limited (SOVL) made an open offer for acquisition of shares of the company; consequent to the disinvestment of Government of India's (GOI) stake of 26% including management control to SOVL and acquired additional 20% of shares from public, pursuant to the SEBI Regulations 1997. In August 2003, SOVL acquired additional shares to the extent of 18.92% of the paid up capital from GOI in exercise of "call option" clause in the share holder's agreement between GOI and SOVL.

With the above additional acquisition, SOVL's stake in the company has gone up to 64.92%. Thus GOI's stake in the company now stands at 29.54%. The Group's principal activities are mining and smelting of zinc and lead operations. It's products include zinc ingots, lead ingots, silver, sulphuric acid, cadmium ingots, copper cathode and others. The Group operates with two segments namely Zinc and Other. It operates through three mining and three smelter Complexes. Mining complexes are located in Rampura Agucha, Rajpura Dariba and Zawar - all in Rajasthan. Smelter complexes are located at Chanderiya and Debari in Rajasthan and Vizag in Andhra Pradesh.

Hindustan Zinc Limited Key Data:


Ticker: Exchanges: 500188 OTH BOM Country: Major Industry: INDIA Metal Producers & Products

Manufacturers Sub Industry: 80,169,700,000 2010 Sales (Year Ending Jan 2011). Currency: Indian Rupees Market Cap: Shares Outstanding: Closely Held Shares: 408,017,929,235 422,531,900 Employees: 6,661 Miscellaneous Metal Producers

Fiscal Yr Ends: March

Share Type:

Ordinary

274,315,431

SECTION A
OVERVIEW OF ZINC SMELTING & ALLIED SUBJECTS OF THE INDUSTRY

INTRODUCTION

Zinc and zinc-containing products contribute around US$ 40 billion to the global economy each year. US$ 18.5 billion is related to mining, smelting, and refining of zinc. The rest is related to its many applications. Galvanizing, the protection of steel against corrosion by metallurgical bonding of zinc to steel, is the most important application of zinc. Other applications include die casting of precision components, alloys such as brass, as a component in

pharmaceuticals and cosmetics, in batteries and as a micronutrient for humans, animals, and plants.

Zinc smelting is the process of converting zinc concentrates (ores that contain zinc) into pure zinc. The most common zinc concentrate processed is zinc sulfide, which is obtained by concentrating Sphalerite using the froth

flotation method. Secondary (recycled) zinc material, such as zinc oxide, is also processed with the zinc sulfide. Approximately 30% of all zinc produced is from recycled sources.

The principal processes by which zinc is extracted from its ores can be categorized processes. under pyro-metallurgical processes and hydro-metallurgical

A. Pyrometallurgical Processes: Horizontal Retort Process Vertical Retort Process Electro Thermal Process Imperial Smelting Process

B. Hydrometallurgical Processes: Roast Leach Electrowin Process Pressure Leaching Process

About 80% of worlds total zinc output is produced through conventional hydrometallurgical route i.e. Roast-leach-electrowin (RLE) route. The prerequisite condition for zinc metal extraction from sulphide concentrate through a hydro-metallurgical route is the elimination of its sulphur content in order to make it amenable to further treatment by leaching, i.e., the zinc mineral into dissolved state in solution. Since zinc sulphide mineral is not easily leached, it is first converted into zinc oxide, which is easily leached. This is predominantly accomplished by roasting of zinc concentrate in fluid bed roasters and fixation of SO2 bearing off gases thus generated as sulphuric acid by contact process. In the recent past, an alternative technology to conventional roasting followed by leaching, has been developed by Sherritt-Gordon of Canada, commonly known as Pressure Leach Process which eliminates the need of roasting step prior to leaching. The process fixes the sulphide content of concentrate as elemental sulphur, thus eliminates the need for a separate sulphuric acid production facility, whereas the zinc metal content of the concentrate is converted into a zinc sulphate solution, thus combining both roast-leach steps of conventional process into a single unit operation. Thus there are two-process route for extraction of zinc hydrometallurgically.

ROAST LEACH ELECTROWIN (RLE) PROCESS: The main purpose of roasting of zinc sulphide concentrate is to convert it into a product, which is amenable to further treatment through hydrometallurgical process for extraction of zinc. Secondly, to fix the sulphide contents into

sulphur dioxide gases for subsequent economical recovery as sulphuric acid.The principal reaction during fluid bed roasting is: 2 ZnS + 3O2 = 2ZnO + 2SO2

These rich gases are cleaned and cooled to recover dust content as zinc calcine and to remove the various harmful impurities such as Hg, Se, F, Cl, As, etc., before being led to double contact and double conversion process (DCDA) plant for manufacture of sulphuric acid. The dead roasted product, zinc calcine, is subjected to leaching with recycled electrolyte to extract zinc content. The enriched zinc sulphate solution is further subjected to purification with zinc dust to eliminate impurities like copper, cadmium, cobalt, nickel etc. before being subjected to electrolysis. The zinc sulphate solution is fortified with return electrolyte solution, undergoes electrolysis in lined concrete cells for deposition of zinc on aluminium cathodes. The lead- silver plates are used as anodes. The deposited zinc on the cathodes are periodically stripped by automatic stripping machines, melted in induction furnace and cast into saleable zinc ingots man automatic casting and stacking machine. In order to maximise zinc extractions the leach residues mainly zinc- ferrites, a bye product of leaching process, are subjected to treatment to hydrolyse its iron content into disposable Jarosite / goethite / hematite. The zinc plants are also integrated with bye-product cadmium recovery unit in order to maximise sales realization.

The standard zinc product is Special High Grade zinc (normally obtained from RLE process route), with an assay of 99.995% zinc, i.e. it can contain a maximum of 50 parts per million of impurities. There is also a grade of 98.5% zinc, the main impurity being lead, and this used to be the standard grade, called GOB (Good Ordinary Brand) or PW (Prime Western), normally a product from the Imperial smelting process (ISP). A SHG product from the ISP can also be produced by distillation process of refining. PRESSURE LEACH PROCESS: The pressure leach technique was first successfully commercially applied for zinc extraction with the commissioning of first plant in 1981 at Cominco, Trail, Canada. In this process zinc sulphide or bulk zinc concentrates are oxidized under oxygen overpressures of 1200 kpa abs. at a temperature of 1500C in sulphuric acid medium to produce zinc sulphate solution directly and the sulphide content is precipitated as elemental sulphur according to the following overall reaction: ZnS + H2S04 + 0.5 02 = ZnSO4 + H20 + S

The various factors influencing the kinetics of above reaction are the particle size, mineralogy, surface active additives, acidities, reaction time, temperature and oxygen over-pressures where by maximising metal extraction and fixation of lead and iron constituents into disposable Jarosite and other types of

residues. The zinc sulphate solution thus produced is amenable to further processing for final zinc extraction through conventional leach-electrowin units.

Fig: General flow diagram of the zinc smelting process

ROASTING

Roasting is a metallurgical process involving gas-solids reactions at elevated temperatures. A common example is the process in which sulfide ores are converted to oxides, prior to smelting. Roasting differs from calcination, which merely involves decomposition at elevated temperatures. A typical sulfide roasting chemical reaction takes the following form: MSn + 1.5nO2 MOn + nSO2. For example: CuS + 1.5O2 CuO + SO2 and 2ZnS + 3O2 2ZnO + 2SO2 Roasting is a process of oxidizing zinc sulfide concentrates at high temperatures into an impure zinc oxide, called "Zinc Calcine". The chemical reactions taking place during the process are:

Approximately 90% of zinc in concentrates are oxidized to zinc oxide, but at the roasting temperatures around 10% of the zinc reacts with the iron impurities of the zinc sulfide concentrates to form zinc ferrite. A byproduct of roasting is sulfur dioxide, which is further processed into sulfuric acid, a commodity. The linked refinery flow sheet shows a schematic of Noranda's eastern Canadian zinc roasting operation. The process of roasting varies based on the type of roaster used. There are three types of roasters: multiple-hearth, suspension, and fluidized-bed. Multiple-hearth roaster In a multiple-hearth roaster, the concentrate drops through a series of 9 or more hearths stacked inside a brick-lined cylindrical column. As the feed concentrate drops through the furnace, it is first dried by the hot gases passing through the hearths and then oxidized to produce calcine. The reactions are slow and can be sustained only by the addition of fuel. Multiple hearth roasters are unpressurized and operate at about 690 C (1,270 F). Operating time depends upon the composition of concentrate and the amount of the sulfur removal required. Multiple hearth roasters have the capability of producing a high-purity calcine.

Suspension roaster In a suspension roaster, the concentrates are blown into a combustion chamber very similar to that of a pulverized coal furnace. The roaster consists of a refractory-lined cylindrical steel shell, with a large combustion space at the top and 2 to 4 hearths in the lower portion, similar to those of a multiple hearth furnace. Additional grinding, beyond that required for a multiple hearth furnace, is normally required to ensure that heat transfer to the material is sufficiently rapid for the desulfurization and oxidation reactions to occur in the furnace chamber. Suspension roasters are unpressurized and operate at about 980 C (1,800 F). Fluidized-bed roaster In a fluidized-bed roaster, finely ground sulfide concentrates are suspended and oxidized in a feedstock bed supported on an air column. As in the suspension roaster, the reaction rates for desulfurization are more rapid than in the older multiple-hearth processes. Fluidized-bed roasters operate under a pressure slightly lower than atmospheric and at temperatures averaging 1,000 C (1,830 F). In the fluidized-bed process, no additional fuel is required after ignition has been achieved. The major advantages of this roaster are greater throughput capacities, greater sulfur removal capabilities, and lower maintenance.

LEACHING

4
salts in aqueous media. Compared

Leaching is a widely used extractive metallurgy technique which converts metals into soluble

to pyrometallurgical operations, leaching is easier to perform and much less harmful, because no gaseous pollution occurs. The only drawback of leaching is its lower efficiency caused by the low temperatures of the operation, which dramatically affect chemical reaction rates. There are a variety of leaching processes, usually classified by the types of reagents used in the operation. The reagents required depend on the ores or pretreated material to be processed. A typical feed for leaching is

either oxide or sulfide.

For material in oxide form, a simple acid leaching reaction can be illustrated by the zinc oxide leaching reaction: ZnO + H2SO4 ZnSO4 + H2O In this reaction solid ZnO dissolves, forming soluble zinc sulfate. In many cases other reagents are used to leach oxides. For example, in the metallurgy of aluminium, aluminium oxide is subject to leaching by alkali solutions: Al2O3 + 3H2O + 2NaOH 2NaAl(OH)4 Leaching of sulfides is a more complex process due to the refractory nature of sulfide ores. It often involves the use of pressurized vessels, called autoclaves. A good example of the autoclave leach process can be found in the metallurgy of zinc. It is best described by the following chemical reaction: 2ZnS + O2 + 2H2SO4 2ZnSO4 + 2H2O + 2S This reaction proceeds at temperatures above the boiling point of water, thus creating a vapor pressure inside the vessel. Oxygen is injected under pressure, making the total pressure in the autoclave more than 0.6 MPa.

Fig: Flow-diagram of the first stage leach process

Fig: Flow-diagram of the second, third and fourth stage leach process

ELECTROLYSIS

Zinc is extracted from the purified zinc sulfate solution by electrowinning, which is a specialized form of electrolysis. The process works by passing an electric current through the solution in a series of cells. This causes the zinc to deposits on the cathodes (aluminum sheets) and oxygen to form at the anodes. Sulfuric acid is also formed in the process and reused in the leaching process. Every 24 to 48 hours, each cell is shut down, the zinc-coated cathodes are removed and rinsed, and the zinc is mechanically stripped from the aluminum plates. Electrolytic zinc smelters contain as many as several hundred cells. A portion of the electrical energy is converted into heat, which increases the temperature of the electrolyte. Electrolytic cells operate at temperature ranges from 30 to 35 C (86 to 95 F) and at atmospheric pressure. A portion of the electrolyte is continuously circulated through the cooling towers both to cool and concentrate the electrolyte through evaporation of water. The cooled and concentrated electrolyte is then recycled to the cells. This process accounts for approximately one-third of all the energy usage when smelting zinc. There are two common processes for electrowinning the metal: the low current

density process, and the Tainton high current density process. The former uses
a 10% sulfuric acid solution as the electolyte, with current density of 270325

amperes per square meter. The latter uses 2228% sulfuric acid solution as the electrolyte with a current density of about 1,000 amperes per square meter. The latter gives better purity and has higher production capacity per volume of electrolyte, but has the disadvantage of running hotter and being more corrosive to the vessel in which it is done. In either of the electrolytic processes, each metric ton of zinc production expends about 3,900 kWh (14 GJ) of electric power.

SAFETY ENGINEERING
Safety engineering is an applied science strongly related

6
to systems

engineering and the subset System Safety Engineering. Safety engineering assures that a life-critical system behaves as needed even when pieces fail. Ideally, safety-engineers take an early design of a system, analyze it to find what faults can occur, and then propose safety requirements in design specifications up front and changes to existing systems to make the system safer. In an early design stage, often a fail-safe system can be made acceptably

safe with a few sensors and some software to read them. Probabilistic faulttolerant systems can often be made by using more, but smaller and lessexpensive pieces of equipment. Far too often, rather than actually influencing the design, safety engineers are assigned to prove that an existing, completed design is safe. If a safety engineer then discovers significant safety problems late in the design process, correcting them can be very expensive. This type of error has the potential to waste large sums of money. The exception to this conventional approach is the way some large government agencies approach safety engineering from a more proactive and proven process perspective, known as "system safety". The system safety philosophy is to be applied to complex and critical systems, such as commercial airliners, complex weapon systems, spacecraft, rail and transportation systems, air traffic control system and other complex and safety-critical industrial systems. The proven system safety methods and techniques are to prevent, eliminate and control hazards and risks through designed influences by a collaboration of key engineering disciplines and product teams. Software safety is a fast growing field since functionality of modern systems is increasingly being put under control of software. The whole concept of system safety and software safety, as a subset of systems engineering, is to influence safety-critical systems designs by conducting several types of hazard analyses to identify risks and to specify design safety features and procedures to strategically mitigate risk to acceptable levels before the system is certified.

Additionally, failure mitigation can go beyond design recommendations, particularly in the area of maintenance. There is an entire realm of safety and reliability engineering known asReliability Centered Maintenance (RCM), which is a discipline that is a direct result of analyzing potential failures within a system and determining maintenance actions that can mitigate the risk of failure. This methodology is used extensively on aircraft and involves understanding the failure modes of the serviceable replaceable assemblies in addition to the means to detect or predict an impending failure. Every automobile owner is familiar with this concept when they take in their car to have the oil changed or brakes checked. Even filling up one's car with fuel is a simple example of a failure mode (failure due to fuel exhaustion), a means of detection (fuel gauge), and a maintenance action (filling the car's fuel tank). For large scale complex systems, hundreds if not thousands of maintenance actions can result from the failure analysis. These maintenance actions are based on conditions (e.g., gauge reading or leaky valve), hard conditions (e.g., a component is known to fail after 100 hrs of operation with 95% certainty), or require inspection to determine the maintenance action (e.g., metal fatigue). The RCM concept then analyzes each individual maintenance item for its risk contribution to safety, mission, operational readiness, or cost to repair if a failure does occur. Then the sum total of all the maintenance actions are bundled into maintenance intervals so that maintenance is not occurring around the clock, but rather, at regular intervals. This bundling process introduces further complexity, as it might stretch some maintenance cycles,

thereby increasing risk, but reduce others, thereby potentially reducing risk, with the end result being a comprehensive maintenance schedule, purpose built to reduce operational risk and ensure acceptable levels of operational readiness and availability.

HUMAN RESOURCE
Human resource management is

7
to

the strategic and coherent approach

the management of an organization's most valued assets - the people working there who individually and collectively contribute to the achievement of the objectives of the business. The terms "human resource management" and "human resources" (HR) have largely replaced the term "personnel management" as a description of the processes involved in managing people in organizations. In simple words, HRM means employing people, developing their capacities,

utilizing, maintaining and compensating their services in tune with the job and organizational requirement. Its features include: Organizational management Personnel administration Manpower management Industrial management

But these traditional expressions are becoming less common for the theoretical discipline. Sometimes even employee and industrial relations are confusingly listed as synonyms, although these normally refer to the relationship between management and workers and the behavior of workers in companies. The theoretical discipline is based primarily on the assumption that employees are individuals with varying goals and needs, and as such should not be thought of as basic business resources, such as trucks and filing cabinets. The field takes a positive view of workers, assuming that virtually all wish to contribute to the enterprise productively, and that the main obstacles to their endeavors are lack of knowledge, insufficient training, and failures of process. Human Resource Management (HRM) is seen by practitioners in the field as a more innovative view of workplace management than the traditional approach. Its techniques force the managers of an enterprise to express their goals with specificity so that they can be understood and undertaken by the workforce and to provide the resources needed for them to successfully accomplish their

assignments. As such, HRM techniques, when properly practiced, are expressive of the goals and operating practices of the enterprise overall. HRM is also seen by many to have a key role in risk reduction within organizations. Synonyms such as personnel management are often used in a more restricted sense to describe activities that are necessary in the recruiting of a workforce, providing its members with payroll and benefits, and administrating their worklife needs.

FINANCE

8
finance,
and public

Finance is the science of funds management. The general areas of finance are business

finance, personal

finance.

Finance

includes saving money and often includes lending money. The field of finance deals with the concepts of time, money, and risk and how they are interrelated. It also deals with how money is spent and budgeted. Managerial or corporate finance is the task of providing the funds for a corporation's activities. For small business, this is referred to as SME

finance (Small and Medium Enterprises). It generally involves balancing risk and profitability, while attempting to maximize an entity's wealth and the value of its stock. Long term funds are provided by ownership equity and long-term credit, often in the form of bonds. The balance between these elements forms the company's capital structure. Short-term funding or working capital is mostly provided by banks extending a line of credit.

Another

business

decision

concerning

finance

is

investment,

or fund

management. An investment is an acquisition of an asset in the hope that it will maintain or increase its value. In investment in choosing a portfolio one has to decide what, how much and when to invest. To do this, a company must: Identify relevant objectives and constraints: institution or individual goals, time horizon, risk aversion and tax considerations;

Identify the appropriate strategy: active v. passive hedging strategy Measure the portfolio performance

Financial management is duplicate with the financial function of the Accounting profession. However, financial accounting is more concerned with the reporting of historical financial information, while the financial decision is directed toward the future of the firm.

LOGISTICS

Logistics is the management of the flow of goods, information and other resources between the point of origin and the point of consumption in order to meet the requirements of consumers. Logistics involves the integration of

information,

transportation, inventory, warehousing,

material-handling,

and packaging, and occasionally security. Logistics is a channel of the chain which adds the value of time and place utility. Today the complexity of production logistics can be modeled, analyzed, visualized and optimized by plant simulation software. Logistics as a business concept evolved only in the 1950s. This was mainly due to the increasing complexity of supplying one's business with materials and shipping out products in an increasingly globalized supply chain, calling for experts in the field who are called Supply Chain Logisticians. This can be defined as having the right item in the right quantity at the right time at the

right place for the right price in the right condition to the right customer and is
the science of process and incorporates all industry sectors. The goal of logistics work is to manage the fruition of project life cycles, supply chains and resultant efficiencies. In business, logistics may have either internal focus (inbound logistics), or external focus (outbound logistics) covering the flow and storage of materials from point of origin to point of consumption (see supply chain management). The main functions of a qualified logistician include inventory

management, purchasing, transportation, warehousing, consultation and the organizing and planning of these activities. Logisticians combine a professional knowledge of each of these functions so that there is a coordination of resources in an organization. There are two fundamentally different forms of logistics. One optimizes a steady flow of material through a network

of transport links and storage nodes. The other coordinates a sequence of resources to carry out some project.

10 INDUSTRIAL ENGINEERING
Industrial Engineering (often now supplemented as "Industrial & Systems Engineering" or "Industrial & Operations Engineering") is a branch of engineering dealing with optimizing complex processes or systems. It is concerned with the development, improvement, implementation and evaluation of integrated systems of people, money, knowledge, information, equipment, energy, materials and/or processes. It also deals with designing new product prototypes more efficiently and more effectively. Industrial engineering draws upon the principles and methods of engineering analysis and synthesis, as well as the mathematical, physical and social sciences together with the principles and methods of engineering design to specify, predict, and evaluate the results to be obtained from such systems or processes. Its underlying concepts overlap considerably with certain business-oriented disciplines such as Operations

Management,

but

the

engineering

side

tends

to

greater

emphasize

extensive mathematical proficiency and utilization of quantitative methods. While the term originally applied to manufacturing, nowadays the term "industrial" in industrial engineering can be somewhat misleading (leading to the typical extensions noted above). It has grown to encompass any methodical or quantitative approach to optimizing how a process, system, or organization operates. In fact, the primary U.S. professional organization for Industrial Engineers, the Institute of Industrial Engineers (IIE) has been considering changing its name to something broader (such as the Institute of Industrial & Systems Engineers), although the latest vote among membership deemed this unnecessary for the time being. The various topics of concern to industrial engineers include management chain science, financial engineering, engineering engineering, operations

management, supply

management, process

research, systems engineering, ergonomics, cost and value engineering, quality engineering, facilities planning, and the engineering design process.

Traditionally, a major aspect of industrial engineering was planning the layouts of factories and designing assembly lines and other manufacturing paradigms. And now, in so-called lean manufacturing systems, industrial engineers work to eliminate wastes of time, money, materials, energy, and other resources.

SECTION B
APPLICATIONS OF COMPUTER SCIENCE IN THE INDUSTRY

SAP

11

SAP the company was founded in Germany in 1972 by five ex-IBM engineers. In case youre ever asked, SAP stands for Systeme, Andwendungen, Produkte in

der Datenverarbeitung which - translated to English - means Systems, Applications, Products in Data Processing. So now you know! Being
incorporated in Germany, the full name of the parent company is SAP AG. It is located in Walldorf, Germany which is close to the beautiful town of Heidelberg. SAP has subsidiaries in over 50 countries around the world from Argentina to Venezuela (and pretty much everything in between). SAP America (with responsibility for North America, South America and Australia - go figure!) is located just outside Philadelphia, PA.

The original five founders have been so successful that they have multiplied many times over such that SAP AG is now the third largest independent software maker in the world, with over 80,000 customers (including way more than half of the world's 500 top companies). SAP employs over 50,000 people worldwide today, and had revenues of $16.9 billion and Net Income of $2.7 billion in FY08. SAP is listed in Germany (where it is one of the 30 stocks which make up the DAX) and on the NYSE (ticker:SAP). There are now more than 121,000 installations of SAP, in 120 countries, with more than 12 million users! So now, what is SAP? It is a company, but it is also a product. So and what made this company so successful? Back in 1979 SAP released SAP R/2 (which runs on mainframes) into the German market. SAP R/2 was the first integrated, enterprise wide package and was an immediate success. For years SAP stayed within the German borders until it had penetrated practically every large German company. Looking for more growth, SAP expanded into the remainder of Europe during the 80's. Towards the end of the 80's, client-server architecture became popular and SAP responded with the release of SAP R/3 (in 1992). This turned out to be a killer app for SAP, especially in the North American region into which SAP expanded in 1988. The success of SAP R/3 in North America has been nothing short of stunning. Within a 5 year period, the North American market went from virtually zero to 44% of total SAP worldwide sales. SAP America alone employs more than 5,000

people and has added the names of many of the Fortune 500 to its customer list (8 of the top 10 semiconductor companies, 7 of the top 10 pharmaceutical companies etc). SAP today is available in 46 country-specific versions, incorporating 28 languages including Kanji and other double-byte character languages. SAP also comes in 21 industry-specific versions. SAP R/3 is delivered to a customer with selected standard process turned on, and many many other optional processes and features turned off. At the heart of SAP R/3 are about 10,000 tables which control the way the processes are executed. Configuration is the process of adjusting the settings of these tables to get SAP to run the way you want it to. Think of a radio with 10,000 dials to tune and youll get the picture. SAP functionality included is truly enterprise wide including: Financial Accounting (e.g. general ledger, accounts receivable etc), Management Accounting (e.g. cost centers, profitability analysis etc), Sales, Distribution, Manufacturing, Production Planning, Purchasing, Human

Resources, Payroll etc. All of these modules are tightly integrated which as you will find out is a huge blessing ... but brings with it special challenges.

VSAT

12

A Very Small Aperture Terminal (VSAT), is a two-way satellite ground station or a stabilized maritime Vsat antenna with a dish antenna that is smaller than 3 meters. The majority of VSAT antennas range from 75 cm to 1.2 m. Data rates typically range from 56 Kbit/s up to 4 Mbit/s. VSATs access satellites in geosynchronous orbit to relay data from small remote earth stations (terminals) to other terminals (in mesh configurations) or master earth station "hubs" (in star configurations). VSATs are most commonly used to transmit narrowband data (point of sale transactions such as credit card, polling or RFID data; or SCADA),

or broadband data (for the provision of Satellite Internet access to remote locations, VoIP or video). VSATs are also used for transportable, on-the-move (utilizing phased array antennas) or mobile maritime communications. Most VSAT networks are configured in one of these topologies:

A star topology, using a central uplink site, such as a network operations center (NOC), to transport data back and forth to each VSAT terminal via satellite,

A mesh topology, where each VSAT terminal relays data via satellite to another terminal by acting as a hub, minimizing the need for a centralized uplink site,

A combination of both star and mesh topologies. Some VSAT networks are configured by having several centralized uplink sites (and VSAT terminals stemming from it) connected in a multi-star topology with each star (and each terminal in each star) connected to each other in a mesh topology. Others configured in only a single star topology sometimes will have each terminal connected to each other as well, resulting in each terminal acting as a central hub. These configurations are utilized to minimize the overall cost of the network, and to alleviate the amount of data that has to be relayed through a central uplink site (or sites) of a star or multi-star network.

Constituent Components of a VSAT Antenna Block upconverter (BUC) Low-noise block converter (LNB) Orthomode transducer (OMT) Interfacility Link Cable (IFL) Indoor unit (IDU)

All the outdoor parts on the dish are collectively called the ODU (Outdoor Unit), i.e. OMT to split signal between BUC and LNB. The IDU is effectively a Modem, usually with Ethernet port and 2 x F-connectors for the coax to BUC (Transmit) and from LNB (Receive). The Astra2Connect has an all-in-one OMT/BUC/LNA that looks like a QUAD LNB in shape and size which mounts on a regular TV sat mount. As a consequence it is only 500 mW compared with the normal 2W, thus is poorer in rain.

SIMULATION & CONTROL


Honeywells Advanced Control & Optimization

13

Improve profitability by increasing production and decreasing costs with Honeywells modeling and multivariable advanced control and optimization products. Ongoing advanced control and optimization of plant operations ensures responsiveness to inevitable changes in business demands through close linkages with planning, scheduling, and management functions. Delivered through the unified Experion solutions Process improve Knowledge profitability System by (PKS)

architecture, Honeywell

increasing

throughput, reducing costs, increasing yields, and improving product quality. Advanced Control and Optimization products address all aspects of advanced process control and optimizationfrom improving regulatory loop controlto globally optimizing the entire process based on a unique layered approach. This model allows new technologies to be easily added at any time to a common platform that meets optimization objectives without compromising future opportunities to improve business performance.

Honeywells Simulation Solution

UniSim software and services improve plant performance and overall business results for the process industry through:

Better plant design Better plant operations Better plant optimization.

UniSim solution software is built from the best simulation technologies available. UniSim offers a series of unified simulation solutions to support improved performance throughout the lifecycle of a plantfrom off-line use in steady-state design simulation, control check-out, and operator training, to online use in control and optimization, performance monitoring, and business planning.

With the launch of UniSim, Honeywells vision of providing best-in-class simulation solutions is realized, generating benefits across the lifecycle of a plant. UniSim substantially improves capabilities for simulation of on-line and off-line process unit design and optimization applications. Customers can more easily capture and share process knowledge, improve plant profitability, and maximize the return on their simulation investments. The UniSim family of software and services includes:

The UniSim Design suiteoffers a powerful steady-state tool that helps engineers create optimal process designs based on critical business objectives. A dynamic simulation option is also available to gain valuable insights into process behavior at every phase of a plant's lifecycle.

The UniSim Operations suiteprovides an advanced operator training solution plus capabilities for control system checkout. Well-trained personnel react more quickly and diffuse process situations before incidents occur. This is also a tool for learning a new system before commissioning, or for quickly training new hires.

The UniSim Optimization suiteoffers optimization of plant operations to ensure responsiveness to changes in business demands through close linkages with planning, scheduling, and management functions.

Dynamic Engineering Studies servicesevaluate the impact of future process design changes prior to plant modifications. Honeywell experts help

customers evaluate the impact of future process design changes before committing time and money to intensive plant modifications.

Honeywells Terminal Automation Products


1. Tank Gauging Tank gauging is essential for the assessment of tank contents, tank inventory control and tank farm management. In addition to accurate measurement, reliability to prevent product loss, performance to optimize product movement and safety to protect the environment and personnel are critical to successful inventory management. Honeywell Enraf provides a comprehensive range of products and systems for accurate tank gauging, inventory management and tank terminal operations. For optimal benefit Engauge is a service tool that provides the required functionality for site device management, gauge configuration and analyses.

Open connectivity, modular design and solid migration paths maximize the use of tank storage capacity to optimize operations and increase revenues.

2. Temperature Measurement Systems Honeywell Enraf offers a comprehensive line of products for accurate temperature measurement, ranging from single spot temperature probes to the advanced VITO multiple thermosensor thermometers (MTT) for temperature and volume measurement. Honeywell Enrafs VITO interface guarantees faultless communication with level gauging systems based on radar or servo technology. The gauging systems can easily be provided with additional functionality for water bottom measurement, keeping the number of instruments and

components in and on the tank to a minimum. Honeywell Enrafs temperature gauging systems offer reliability, high

measurement accuracy, minimal maintenance cost and easy installation. Honeywell Enraf offers several types of temperature measurement instruments: A. Spot Temperature MeasurementHoneywell Enraf supports and supplies spot temperature probes of third-party origin for direct connection to a level gauge. The probes can be attached at any desired location in the tank. Communication with servo or radar measurement systems can take place either directly or via the VITO interface.

B. Average Temperature MeasurementFor average temperature measurement Honeywell Enraf offers the VITO MRT which consists of multiple resistor elements each with a different length. Depending on the liquid level measured by the level gauge, the longest element which is completely submerged is selected to represent the average temperature of the stored product. C. Multiple Temperature MeasurementThe VITO LT measures average product temperature and average gas temperature with a nine-element probe. The VITO LT exceeds the requirements of all standards for in-tank measurements. It can be used with products stored at between -55 degrees Celsius and +135 degrees Celsius in tanks up to 20 meters high. The temperature gauging system is suitable for customs transfer purposes in conformity with weights and measures regulations. Honeywell Enrafs top model is the VITO MTT for various temperature ranges for diverse applications and is available in any desired length. The temperature measurement is performed by a 16-element probe. The VITO MTT is able not only to measure average product and gas temperature but also to determine temperature profiles. The VITO MTT fully complies with all major standards for tank applications and is suitable for customs transfer purposes in conformity with weights and measures regulations. In addition, the VITO MTT is fit for LNG storage.

Fig: Tank Gauging Devices

Fig: Temperature Measurement Systems

SECTION C
A PROJECT ON INVENTORY MANAGEMENT SYSTEM

GENERAL PERSPECTIVE

14

A database management system (DBMS) consists of software that organizes the storage of data. A DBMS controls the creation, maintenance, and use of the database storage structures of social organizations and of their users. It allows organizations to place control of organization wide database development in the hands of Database Administrators (DBAs) and other specialists. In large systems, a DBMS allows users and other software to store and retrieve data in a structured way. Databases function in many applications, spanning virtually the entire range of computer software. Databases have become the preferred method of storage for large multiuser applications, where coordination between many users is needed. Even individual users find them convenient, and many electronic mail

programs and personal organizers are based on standard database technology. Software database drivers are available for most database platforms so that application software can use a common API to retrieve the information stored in a database. Commonly used database APIs include JDBC and ODBC. We look forward to the development of an integrated database management application that could serve all the systematic data storage and data manipulation requirements for any specific department of the corporation. Logistics, Human Resources, Finance, Materials, etc are some such possible fields that can be targeted at for the development of the software. The prime objectives of the system we plan to develop are as under: Integrated data operations implemented through an innovative and efficient configuration. Stronger security features ensuring high safety of the data. Easy user interface maximizing the convenience in authenticated access. Robust design making the system more reliable and sustainable.

TECHNICAL PERSPECTIVE

15

Justification of Integration
The standard of business computing as of 2009, relational databases are the most commonly used database today. It uses the table to structure information so that it can be readily and easily searched through. Thus, we plan the same, i.e. to develop the database according to the relational model. When we assert the development of an integrated database management application, obviously we need to justify it. So, we state under the tasks that are provided in the database package: Database Development: used to define and organize the content, relationships, and structure of the data needed to build a database. Database Interrogation: can access the data in a database for information retrieval and report generation. End users can selectively retrieve and display information and produce printed reports and documents. Database Maintenance: used to add, delete, update, correct, and protect the data in a database. Application Development: used to develop prototypes of data entry screens, queries, forms, reports, tables, and labels for a prototyped application.

Justification of High Security


Database security denotes the system, processes, and procedures that protect a database from unintended activity. Enforcing security is one of the major tasks

of the DBA. DBMSs usually enforce security through access control, auditing, and encryption: Access control ensures and restricts who can connect and what they can do to the database. Auditing logs what action or change has been performed, when and by whom. Encryption includes built-in encryption mechanisms to encode data natively into tables and to decipher information "on the fly" when a query comes in. DBAs can also secure and encrypt connections if required using DSA, MD5, SSL or legacy encryption standards.

Justification of Easy User Interface and Robustness


Generally, databases are provided with a CLI (Command Line Interface) that makes it very tedious even for authenticated users to access it as it requires thorough knowledge of commands. An extremely user friendly GUI (Graphical User Interface) not only makes it more convenient for the end users but indirectly it also affects the productivity by reducing time and effort. The reliable design of the relational database model is least prone to crash and thus it makes the system less prone to bugs and unrecoverable deadlocks. Moreover the in-built check mechanisms ensure obliteration of typical erroneous conditions and other logical bugs.

DESIGN CONCEPT

16

The proposed design of the integrated database can be explained with the help of the following graphical layout:

The above diagrammatic representation of the development concept shows the bifurcation of various modules giving an introductory idea of the development strategy. The systematic modular development of the system ensures perfection at each level and in each sub-system. Moreover, it also makes the development procedure more easy and clear.

FORMS

17

The design of the Inventory Management System is divided into 7 major forms:

1. frmLogin.frm
It is the first opening screen of the application which prompts the user to enter the application through a valid login ID. Coding:
Private Sub cmdCancel_Click() Unload Me End Sub

Private Sub cmdNew_Click() If Not txtUserName.Text = "Admin" Or Not txtPassword.Text = "Admin" Then MsgBox "Invalid user or password", vbCritical, "Invald user/password" txtUserName.SetFocus Exit Sub End If

If FrmMain.Enabled = False Then FrmMain.Enabled = True Else

FrmMain.Show Unload frmLogin End If End Sub Private Sub Form_Load() End Sub

2. frmMain.frm
It is the main screen which provides access to all the features of the application namely purchase, sales, accounts, journal voucher and reports etc. Coding:
Dim VIndex As Integer Dim SideMenuVisible As Boolean 'On click if frame(Side menu) is visible the invisibole it or if invisible then visible it

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 27 Then

PicBar_Click (10) End If

If KeyCode = vbKeyA And Shift = 2 Then PicBar_Click (11) End If 'Accounts

End Sub

Private Sub Form_Load() Dim i% For i% = 0 To PicBar.Count - 1 PicBar(i%).Picture = LoadResPicture("Light", 0) Next

LblHelpLine.Caption = "" SetPicCaption

imgPurchase.Picture = img2.ListImages(11).Picture imgSale.Picture = img1.ListImages(9).Picture imgAccount.Picture = img1.ListImages(14).Picture imgVoucher.Picture = img1.ListImages(11).Picture imgReports.Picture = img1.ListImages(35).Picture imgBackUp.Picture = img1.ListImages(41).Picture ImgRestore.Picture = img1.ListImages(25).Picture

imgLogoff.Picture = img1.ListImages(18).Picture imgCalc.Picture = img1.ListImages(47).Picture imgNotepad.Picture = img1.ListImages(48).Picture imgPaint.Picture = img1.ListImages(49).Picture imgExit.Picture = img1.ListImages(50).Picture

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Call SetColorToDefault End Sub

Private Sub PicBar_Click(Index As Integer)

'Getting CLICK Action Select Case Index Case 0 frmPurchase.Show 1 'Purchases

Case 1 frmSale.Show 1

'Sales

Case 2 frmTransaction.Show 1

'Journal Vouchers / Transaction

Case 3 FrmRep.Show 1

'Reports

Case 4

'BackUp

Case 5

'Restore

Case 6 FrmMain.Enabled = False frmLogin.Show

'Log off

Case 7

'Calculator

Shell "C:\windows\system32\calc.exe", vbNormalFocus

Case 8

'Notepad

Shell "C:\windows\system32\notepad.exe", vbNormalFocus

Case 9

'MS Paint

Shell "C:\windows\system32\mspaint.exe", vbNormalFocus

Case 10

'Exit

If MsgBox("Do you want to exit?", vbQuestion + vbYesNo, "Exit?") = vbYes Then Unload Me End If

Case 11 frmAccounts.Show 1

End Select

End Sub

Private Sub PicBar_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)

VIndex = Index

Select Case Index '---------------------------- MAIN MENU Case 0 PicBar(Index).Picture = LoadResPicture("Down", 0) 'Purchases

LblHelpLine.Caption = "Add your Purchases" Case 1 PicBar(Index).Picture = LoadResPicture("Down", 0) LblHelpLine.Caption = "Add your Sales" Case 2 PicBar(Index).Picture = LoadResPicture("Down", 0) LblHelpLine.Caption = "Add your Transactions" Case 3 PicBar(Index).Picture = LoadResPicture("Down", 0) LblHelpLine.Caption = "View Reports" Case 4 PicBar(Index).Picture = LoadResPicture("Down", 0) LblHelpLine.Caption = "Create Database Backup" Case 5 PicBar(Index).Picture = LoadResPicture("Down", 0) LblHelpLine.Caption = "Restore Database" Case 6 PicBar(Index).Picture = LoadResPicture("Down", 0) LblHelpLine.Caption = "Logoff the System" Case 7 PicBar(Index).Picture = LoadResPicture("Down", 0) LblHelpLine.Caption = "Calculator" Case 8 'Calculator 'Logoff 'Restore 'Back Up 'Reports 'Journal Vouchers 'Sales

PicBar(Index).Picture = LoadResPicture("Down", 0) LblHelpLine.Caption = "Note pad" Case 9 PicBar(Index).Picture = LoadResPicture("Down", 0) LblHelpLine.Caption = "MS Paint" Case 10 PicBar(Index).Picture = LoadResPicture("Down", 0) LblHelpLine.Caption = "Exit to Windows"

'Notepad

'MS Paint

'Exit

Case 11 PicBar(Index).Picture = LoadResPicture("Down", 0) LblHelpLine.Caption = "Add Transactional Accounts" 'Accounts

End Select

SetPicCaption

End Sub

Public Sub SetColorToDefault() PicBar(VIndex).Picture = LoadResPicture("Light", 0) LblHelpLine.Caption = "" SetPicCaption

End Sub

Private Sub PicMenu_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) On Error Resume Next

LblHelpLine.Caption = ""

SetPicCaption

End Sub

Private Sub PicMnu_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim i% For i% = 0 To PicBar.Count - 1 PicBar(i%).Picture = LoadResPicture("Light", 0) Next

LblHelpLine.Caption = "" SetPicCaption End Sub

Public Sub SetPicCaption() Call ReplaceCap End Sub

Public Sub ReplaceCap() Dim a As Integer For a = 0 To 11 Select Case a Case 0 PrintToCenter "Purchases", PicBar(a), False Case 1 PrintToCenter "Sales", PicBar(a), False Case 2 PrintToCenter "Journal Voucher", PicBar(a), False Case 3 PrintToCenter "Reports", PicBar(a), False Case 4 PrintToCenter "Backup", PicBar(a), False Case 5 PrintToCenter "Restore", PicBar(a), False Case 6

PrintToCenter "Log Off", PicBar(a), False Case 7 PrintToCenter "Calculator", PicBar(a), False Case 8 PrintToCenter "Notepad", PicBar(a), False Case 9 PrintToCenter "MS Paint", PicBar(a), False Case 10 PrintToCenter "Exit to Windows", PicBar(a), False Case 11 PrintToCenter "Accounts", PicBar(a), False

End Select Next End Sub

3. frmAccounts.frm
This form creates the interface for the function of creating accounts of various types.

Coding:
Dim ProdSalePrice As Single Dim ProdReOrderPoint As Single Dim SQLQry As String Dim AvgPrice As Single

Private Sub cmbType_LostFocus() If cmbType.Text = "Product" Then cmdProdInfo.Enabled = True Else cmdProdInfo.Enabled = False End If

End Sub

Private Sub cmdCancel_Click() Clear Me 'Calling form load event Call Form_Load

'Changing the mode of button Modes False, True, Me

'Setting focus on TxtName cmbType.SetFocus

'Highlighting TxtName High txtName

'Unlock Navigation UnLockNav Me

End Sub

Private Sub cmdDelete_Click() MsgBox "In process" End Sub

Private Sub cmdExit_Click() Unload Me End Sub

Private Sub cmdFind_Click() If optTitle.Value = True Then If Trim(txtFindTitle.Text) = "" Then MsgBox "Enter Account Title to find", vbCritical, "Message ..." txtFindTitle.SetFocus Exit Sub Else

FindRecord "Title" End If ElseIf optId.Value = True Then If Trim(txtFindId.Text) = "" Or Val(txtFindId) = 0 Then MsgBox "Enter Account ID to find", vbCritical, "Message ..." txtFindId.SetFocus Exit Sub Else FindRecord "Id" End If End If

End Sub

Private Sub cmdFindCancel_Click() picFind.Visible = False cmbType.SetFocus End Sub

Private Sub cmdFindRecord_Click() picFind.Visible = True

optTitle.Value = True txtFindTitle.SetFocus

End Sub

Private Sub cmdOk_Click()

If txtSalePrice.Text = "" Or Val(txtSalePrice) = 0 Then MsgBox "Enter Sale Price for this Product", vbCritical, "Message" txtSalePrice.SetFocus Exit Sub End If

picAccounts.Enabled = True picProdInfo.Visible = False

txtName.Text = txtProdName.Text cmbHead.Text = "Assets" txtName.SetFocus End Sub

Private Sub cmdProdCancel_Click()

picAccounts.Enabled = True picProdInfo.Visible = False

End Sub

Private Sub cmdProdInfo_Click() picProdInfo.Visible = True txtProdName.SetFocus

picAccounts.Enabled = False

End Sub

Private Sub cmdSave_Click() 'If Name field is blank If txtName.Text = "" Then MsgBox "Enter Account Title", vbCritical, "Message" txtName.SetFocus Exit Sub End If

'If account head not selected then If cmbHead.ListIndex = -1 Then

MsgBox "Select Account Head", vbCritical, "Message" cmbHead.SetFocus Exit Sub End If

'If account Type not selected then If cmbType.ListIndex = -1 Then MsgBox "Select Account Type", vbCritical, "Message" cmbType.SetFocus Exit Sub End If

'If Account Type = Product (as we have other option to enter product detail) If cmbType.Text = "Product" Then If txtProdName.Text = "" Or txtSalePrice.Text = "" Or txtReOrder.Text = "" Then MsgBox "Please enter product informations", vbCritical, "Message" cmdProdInfo_Click Exit Sub End If End If

'Finding Head Account ID through CMBHead.Text If cmbHead.Text = "Assets" Then

mHeadId = 1 ElseIf cmbHead.Text = "Liabilities" Then mHeadId = 2 ElseIf cmbHead.Text = "Capital" Then mHeadId = 3 ElseIf cmbHead.Text = "Revenue" Then mHeadId = 4 ElseIf cmbHead.Text = "Expense" Then mHeadId = 5 End If

'Check if Account Type is Product or anyother If Not cmbType.Text = "Product" Then txtSalePrice.Text = "0" txtReOrder.Text = "0" End If

'If New record If cmdNew.Enabled = False Then

Con.Execute "Insert into Accounts(AcId,HeadId,AcTitle,AcType,SalePrice,ReOrderPoint) Values(" & Val(txtId) & ", " & Val(mHeadId) & ", '" & txtName.Text & "', '" & cmbType.Text & "', " & Val(txtSalePrice) & ", " & Val(txtReOrder) & " )"

If cmbType.Text = "Product" Then Con.Execute "Insert into Product_Openings(ProdId, Qty, Amount) values(" & Val(txtId) & ", " & Val(txtOpStock) & ", " & Val(txtOpAmount) & ")" End If

MsgBox "New Account Created", vbInformation, "Done"

'Updating Maximum Number UpdateMaxNumber "AcId", Val(txtId)

'If Existing Record ElseIf cmdNew.Enabled = True Then If UpdateRecord.State = 1 Then UpdateRecord.Close

Set UpdateRecord = New ADODB.Recordset UpdateRecord.Open "Update Accounts set HeadId = " & Val(mHeadId) & ", AcTitle = '" & txtName.Text & "', AcType = '" & cmbType & "' , SalePrice = " & Val(txtSalePrice) & ", ReOrderPoint = " & Val(txtReOrder) & " where AcId = " & Val(txtId) & " ", Con, adOpenDynamic, adLockOptimistic

If cmbType.Text = "Product" Then Con.Execute "Update Product_Openings set Qty = " & Val(txtOpStock) & ", Amount = " & Val(txtOpAmount) & " Where ProdId = " & Val(txtId) & "" End If

MsgBox "Existing Record Updated", vbInformation, "Done" End If

cmdCancel_Click End Sub

Private Sub Command1_Click()

End Sub

Private Sub fgAccounts_DblClick() Dim mRow As Integer mRow = fgAccounts.RowSel

txtId.Text = fgAccounts.TextMatrix(mRow, 0) txtName.Text = fgAccounts.TextMatrix(mRow, 1) cmbType.Text = fgAccounts.TextMatrix(mRow, 2) cmbHead.Text = fgAccounts.TextMatrix(mRow, 3)

cmbType.SetFocus

If cmbType.Text = "Product" Then Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select AcTitle,SalePrice,ReOrderPoint from Accounts where AcId = " & Val(txtId) & "", Con, adOpenStatic, adLockOptimistic txtProdName.Text = RS(0) txtSalePrice.Text = Val(RS(1)) txtReOrder.Text = Val(RS(2))

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Qty,Amount from Product_Openings where ProdId = " & Val(txtId) & "", Con, adOpenStatic, adLockOptimistic txtOpStock.Text = Val(RS(0)) txtOpAmount.Text = Val(RS(1))

cmdProdInfo.Enabled = True Else cmdProdInfo.Enabled = False

End If

End Sub

Private Sub Form_KeyPress(KeyAscii As Integer) 'Changing Control focus on Enter ChangeFocusOnEnter KeyAscii, Me End Sub

Private Sub Form_Load() 'Setting up flexgrid data Call fgAccountsData Call GridSetting

'Setting Navigational Recordset If RsNAV.State = 1 Then RsNAV.Close

Set RsNAV = New ADODB.Recordset RsNAV.Open "Select AcId, HeadId, AcTitle, AcType, SalePrice, ReOrderPoint from Accounts", Con, adOpenStatic, adLockOptimistic If RsNAV.RecordCount > 0 Then Call BoundData 'Showing Data in textboxes Else Exit Sub End If

cmdProdInfo.Enabled = False

End Sub

Public Sub fgAccountsData() If RS.State = 1 Then RS.Close

Set RS = New ADODB.Recordset RS.Open "Select * from ViewHeadWise order by AcId", Con, adOpenStatic, adLockOptimistic

Set fgAccounts.DataSource = RS

End Sub

Public Sub GridSetting() With fgAccounts .ColWidth(0) = 950 .ColWidth(1) = 2000 .ColWidth(2) = 1350 .ColWidth(3) = 1350

.TextMatrix(0, 0) = "ID" .TextMatrix(0, 1) = "Account Title"

.TextMatrix(0, 2) = "Account Type" .TextMatrix(0, 3) = "Head Account"

.ColAlignmentFixed(0) = 4 .ColAlignmentFixed(1) = 4 .ColAlignmentFixed(2) = 4 .ColAlignmentFixed(3) = 4

.ColAlignment(0) = 5

.RowHeight(0) = 400 End With End Sub

Public Sub BoundData() txtId.Text = Val(RsNAV(0)) If Val(RsNAV(1)) = 1 Then cmbHead.Text = "Assets" ElseIf Val(RsNAV(1)) = 2 Then cmbHead.Text = "Liabilities" ElseIf Val(RsNAV(1)) = 3 Then cmbHead.Text = "Capital" ElseIf Val(RsNAV(1)) = 4 Then

cmbHead.Text = "Revenue" ElseIf Val(RsNAV(1)) = 5 Then cmbHead.Text = "Expense" End If

txtName.Text = RsNAV(2) cmbType.Text = RsNAV(3)

If cmbType.Text = "Product" Then txtProdName.Text = RsNAV(2) txtSalePrice.Text = Val(RsNAV(4)) txtReOrder.Text = Val(RsNAV(5)) End If

End Sub

Private Sub Form_Resize() Me.Left = Me.Left + 1200 Me.Top = Me.Top + 200 End Sub

Private Sub Label19_Click() Unload Me

End Sub

Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) MouseNormalOnLbl

End Sub

Private Sub lbl_Click(Index As Integer) Select Case Index Case 0 'NEW

'Clearing controls of the form Clear Me

'Calling Max Number Call AutoId

'Changing the mode of button Modes True, False, Me

'Setting focus on TxtName cmbType.SetFocus

'Locking Navigation

LockNav Me

Case 1

'Save

'If Name field is blank If txtName.Text = "" Then MsgBox "Enter Account Title", vbCritical, "Message" txtName.SetFocus Exit Sub End If

'If account head not selected then If cmbHead.ListIndex = -1 Then MsgBox "Select Account Head", vbCritical, "Message" cmbHead.SetFocus Exit Sub End If

'If account Type not selected then If cmbType.ListIndex = -1 Then MsgBox "Select Account Type", vbCritical, "Message" cmbType.SetFocus Exit Sub

End If

'If Account Type = Product (as we have other option to enter product detail) If cmbType.Text = "Product" Then If txtProdName.Text = "" Or txtSalePrice.Text = "" Or txtReOrder.Text = "" Then MsgBox "Please enter product informations", vbCritical, "Message" cmdProdInfo_Click Exit Sub End If End If

'Finding Head Account ID through CMBHead.Text If cmbHead.Text = "Assets" Then mHeadId = 1 ElseIf cmbHead.Text = "Liabilities" Then mHeadId = 2 ElseIf cmbHead.Text = "Capital" Then mHeadId = 3 ElseIf cmbHead.Text = "Revenue" Then mHeadId = 4 ElseIf cmbHead.Text = "Expense" Then mHeadId = 5 End If

'Check if Account Type is Product or anyother If Not cmbType.Text = "Product" Then txtSalePrice.Text = "0" txtReOrder.Text = "0" End If

'If New record If lbl(0).Enabled = False Then

Con.Execute "Insert into Accounts(AcId,HeadId,AcTitle,AcType,SalePrice,ReOrderPoint) Values(" & Val(txtId) & ", " & Val(mHeadId) & ", '" & txtName.Text & "', '" & cmbType.Text & "', " & Val(txtSalePrice) & ", " & Val(txtReOrder) & " )"

If cmbType.Text = "Product" Then Con.Execute "Insert into Product_Openings(ProdId, Qty, Amount) values(" & Val(txtId) & ", " & Val(txtOpStock) & ", " & Val(txtOpAmount) & ")"

'Average Cost Price / Sale Price AvgPrice = Val(txtOpAmount) / Val(txtOpStock) Con.Execute "Insert into Avg_Cost(ProdId, PurAvg, SalAvg) Values(" & Val(txtId) & ", " & Val(AvgPrice) & ", " & Val(txtSalePrice) & ")"

End If

MsgBox "New Account Created", vbInformation, "Done"

'Updating Maximum Number UpdateMaxNumber "AcId", Val(txtId)

'If Existing Record ElseIf lbl(0).Enabled = True Then If UpdateRecord.State = 1 Then UpdateRecord.Close

Set UpdateRecord = New ADODB.Recordset UpdateRecord.Open "Update Accounts set HeadId = " & Val(mHeadId) & ", AcTitle = '" & txtName.Text & "', AcType = '" & cmbType & "' , SalePrice = " & Val(txtSalePrice) & ", ReOrderPoint = " & Val(txtReOrder) & " where AcId = " & Val(txtId) & " ", Con, adOpenDynamic, adLockOptimistic

If cmbType.Text = "Product" Then Con.Execute "Update Product_Openings set Qty = " & Val(txtOpStock) & ", Amount = " & Val(txtOpAmount) & " Where ProdId = " & Val(txtId) & "" 'Average Cost Price AvgPrice = Val(txtOpAmount) / Val(txtOpStock)

Con.Execute "Update Avg_Cost SET PurAvg = " & Val(AvgPrice) & " where ProdID = " & Val(txtId) & ""

End If

MsgBox "Existing Record Updated", vbInformation, "Done" End If

cmdCancel_Click Case 2 Clear Me 'Calling form load event Call Form_Load 'Cancel

'Changing the mode of button Modes False, True, Me

'Setting focus on TxtName cmbType.SetFocus

'Highlighting TxtName High txtName

'Unlock Navigation UnLockNav Me

Case 3 MsgBox "In process"

Case 4 picFind.Visible = True optTitle.Value = True txtFindTitle.SetFocus

Case 5 Unload Me End Select

End Sub

Private Sub lbl_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Select Case Index Case 0, 1, 2, 3, 4, 5 MouseOver lbl(Index)

End Select

End Sub

Private Sub lblnav_Click(Index As Integer) Select Case Index Case 0 'Move First

RsNAV.MoveFirst

If RsNAV.BOF = True Then MsgBox "First Record", vbInformation, "Message" RsNAV.MoveFirst Else Call BoundData End If

Case 1

'Move previous

RsNAV.MovePrevious

If RsNAV.BOF = True Then MsgBox "First Record", vbInformation, "Message" RsNAV.MoveFirst Else Call BoundData End If

Case 2

'Move Next

RsNAV.MoveNext

If RsNAV.EOF = True Then MsgBox "Last Record", vbInformation, "Message" RsNAV.MoveLast Else Call BoundData End If

Case 3 RsNAV.MoveLast

If RsNAV.EOF = True Then MsgBox "Last Record", vbInformation, "Message" RsNAV.MoveLast Else Call BoundData End If End Select

End Sub

Private Sub lblnav_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Select Case Index Case 0, 1, 2, 3 MouseOver lblnav(Index) End Select

End Sub

Private Sub picAccounts_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) MouseNormalOnLbl End Sub

Public Sub AutoId() 'Calling MaxNumber function to get Auto Id for the record MaxNumber "AcId", "Max_Codes" txtId.Text = Val(MaxNmbr) End Sub

Private Sub Picture4_Click()

End Sub

Private Sub txtFindId_KeyPress(KeyAscii As Integer) ONU KeyAscii, txtFindId End Sub

Private Sub txtId_GotFocus() txtName.SetFocus End Sub

Private Sub txtOpAmount_KeyPress(KeyAscii As Integer) ONU KeyAscii, txtOpAmount End Sub

Private Sub txtOpAmount_Validate(Cancel As Boolean) If txtOpAmount.Text = "" Then txtOpAmount.Text = "0" End If End Sub

Private Sub txtOpStock_KeyPress(KeyAscii As Integer) ONU KeyAscii, txtOpStock End Sub

Private Sub txtOpStock_Validate(Cancel As Boolean) If txtOpStock.Text = "" Then txtOpStock.Text = "0" End If End Sub

Private Sub txtReOrder_KeyPress(KeyAscii As Integer) ONU KeyAscii, txtReOrder End Sub

Private Sub txtReOrder_Validate(Cancel As Boolean) If txtReOrder.Text = "" Then txtReOrder.Text = "0" End If End Sub

Private Sub txtSalePrice_KeyPress(KeyAscii As Integer) ONU KeyAscii, txtSalePrice End Sub

Private Sub txtSalePrice_Validate(Cancel As Boolean) If txtSalePrice.Text = "" Or Val(txtSalePrice) = 0 Then MsgBox "Enter Sale Price for this Product", vbCritical, "Message"

txtSalePrice.SetFocus End If End Sub

Public Sub FindRecord(MatchWith As String) Select Case MatchWith Case "Title" SQLQry = "SELECT Accounts.AcId,Accounts.HeadId, Accounts.AcTitle, Accounts.AcType, Accounts.SalePrice, Accounts.ReOrderPoint " & _ "FROM Account_Heads INNER JOIN Accounts ON Account_Heads.Id = Accounts.HeadId where AcTitle = '" & txtFindTitle.Text & "'"

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open SQLQry, Con, adOpenStatic, adLockOptimistic If RS.RecordCount <= 0 Then MsgBox "No account found with this Title", vbCritical, "Message.." txtFindTitle.SetFocus Exit Sub Else ShowFoundData End If

Case "Id" SQLQry = "SELECT Accounts.AcId,Accounts.HeadId, Accounts.AcTitle, Accounts.AcType, Accounts.SalePrice, Accounts.ReOrderPoint " & _ "FROM Account_Heads INNER JOIN Accounts ON Account_Heads.Id = Accounts.HeadId where AcId = " & Val(txtFindId) & ""

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open SQLQry, Con, adOpenStatic, adLockOptimistic If RS.RecordCount <= 0 Then MsgBox "No account found with this ID", vbCritical, "Message.." txtFindId.SetFocus Exit Sub Else ShowFoundData End If

End Select End Sub

Public Sub ShowFoundData() txtId.Text = Val(RS(0)) If Val(RS(1)) = 1 Then cmbHead.Text = "Assets"

ElseIf Val(RS(1)) = 2 Then cmbHead.Text = "Liabilities" ElseIf Val(RS(1)) = 3 Then cmbHead.Text = "Capital" ElseIf Val(RS(1)) = 4 Then cmbHead.Text = "Revenue" ElseIf Val(RS(1)) = 5 Then cmbHead.Text = "Expense" End If

txtName.Text = RS(2) cmbType.Text = RS(3)

If cmbType.Text = "Product" Then txtProdName.Text = RS(2) txtSalePrice.Text = Val(RS(4)) txtReOrder.Text = Val(RS(5)) End If

If cmbType.Text = "Product" Then Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select AcTitle,SalePrice,ReOrderPoint from Accounts where AcId = " & Val(txtId) & "", Con, adOpenStatic, adLockOptimistic

txtProdName.Text = RS(0) txtSalePrice.Text = Val(RS(1)) txtReOrder.Text = Val(RS(2))

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Qty,Amount from Product_Openings where ProdId = " & Val(txtId) & "", Con, adOpenStatic, adLockOptimistic txtOpStock.Text = Val(RS(0)) txtOpAmount.Text = Val(RS(1))

cmdProdInfo.Enabled = True Else cmdProdInfo.Enabled = False

End If

picFind.Visible = False cmbType.SetFocus End Sub

Public Sub MouseNormalOnLbl() 'Commands Lable

lbl(0).ForeColor = vbWhite lbl(0).Font.Underline = False

lbl(1).ForeColor = vbWhite lbl(1).Font.Underline = False

lbl(2).ForeColor = vbWhite lbl(2).Font.Underline = False

lbl(3).ForeColor = vbWhite lbl(3).Font.Underline = False

lbl(4).ForeColor = vbWhite lbl(4).Font.Underline = False

lbl(5).ForeColor = vbWhite lbl(5).Font.Underline = False

'Navigation Label lblnav(0).ForeColor = vbWhite lblnav(0).Font.Underline = False

lblnav(1).ForeColor = vbWhite

lblnav(1).Font.Underline = False

lblnav(2).ForeColor = vbWhite lblnav(2).Font.Underline = False

lblnav(3).ForeColor = vbWhite lblnav(3).Font.Underline = False

End Sub

4. frmPurchase.frm
This form creates the interface for the function of creating purchase entries.

Coding:
Dim Duplicate As Boolean Dim RowSelect As Integer Dim FgRow As Integer Dim rCount As Integer Dim mSqlQry As String Dim PurchaseId As Single Dim PurMainCode As Single Dim ObjectFoucs As Boolean 'True if Focus on TxtName(Supplier Name) . False if Focus on Grid Dim OpQty As Single Dim OpAmount As Single

Dim AvgCost As Single

Private Sub Form_Resize() Me.Top = 1500 Me.Left = 4200

End Sub

Private Sub lbl_Click(Index As Integer) Select Case Index Case 0 'New

'Clearing all controls for New Data Clear Me fgPurchase.Clear

modWriteInGrid.SetPSGRID fgPurchase

Call AutoId

Dtp1.SetFocus Dtp1.Value = Now

Modes True, False, Me

'Lock Navigation LockNav Me

Case 1

'Save

Dim TranDetId As Single Dim PurchaseRef As String Dim TranMainId As Single

'Checking Data to Save If Val(fgPurchase.Rows) < 3 Then MsgBox "No data to save", vbInformation, "Message" Exit Sub End If

'If Account not selected If TxtAcCode.Text = "" Or Val(TxtAcCode) = 0 Then MsgBox "Select Account Name", vbCritical, "Message" TxtName.SetFocus Exit Sub End If

'If New Purchase

If lbl(0).Enabled = False Then

TransactionRef = "Purchase-" & Val(txtId)

'Getting Maximum Code for Purchase Main MaxNumber "PurId", "Max_Codes" PurMainCode = Val(MaxNmbr)

'Getting Maximum Code for Transaction Main MaxNumber "TransId", "Max_Codes" TranMainId = Val(MaxNmbr)

'Inserting Data to TransactionMain Table Con.Execute "insert into Transaction_Main (TransId,TransDate,TransType,Posted,TransRef) values (" & Val(TranMainId) & ", '" & Format(Dtp1.Value, "mm/dd/yyyy") & "' , '" & TransactionType & "' ,'" & "N" & "', '" & TransactionRef & "')"

'---------------------INSERTING DATA INTO TRANSACTION_DETAIL for CREDIT ENTRY 'Getting Maximum Code for Transaction_Detail MaxNumber "TransDetId", "Max_Codes" TranDetId = Val(MaxNmbr)

PurchaseRef = "Purchase # " & Val(txtId) 'Inserting Data to Transaction Detail Con.Execute "Insert into Transaction_Detail (TranDetId, TranId, AcId, Descript, DrAmount, CrAmount) values (" & Val(TranDetId) & ", " & Val(TranMainId) & ", " & Val(TxtAcCode) & ", '" & PurchaseRef & "', 0 , " & Val(txtTotal) & ")"

'Updating MaxCode for Transaction Detail UpdateMaxNumber "TransDetId", Val(TranDetId)

'----------------------------- Inserting to Purchase Main ----------------------------

'Inserting Data to PurchaseMain Table Con.Execute "insert into Purchase_Main (PurId,PurDate,TotalAmount) values (" & Val(txtId) & ", '" & Format(Dtp1.Value, "mm/dd/yyyy") & "' , " & Val(txtTotal) & " )"

'----------------------------- Inserting to Purchase Detail ----------------------------

For FgRow = 1 To fgPurchase.Rows - 2

'Getting Maximum Code for Purchase_Detail MaxNumber "PurDetId", "Max_Codes"

PurchaseId = Val(MaxNmbr)

'Inserting Data to Purchase Detail Con.Execute "Insert into Purchase_Detail (PurDetId, PurId, AcId, ProdId, Qty, Price) values (" & Val(PurchaseId) & ", " & Val(txtId) & ", " & Val(TxtAcCode) & ", '" & fgPurchase.TextMatrix(FgRow, 5) & "', " & Val(fgPurchase.TextMatrix(FgRow, 2)) & ", " & Val(fgPurchase.TextMatrix(FgRow, 3)) & ")" 'Updating MaxCode for Purchase Detail UpdateMaxNumber "PurDetId", Val(PurchaseId)

'---------------------INSERTING DATA INTO TRANSACTION_DETAIL for DEBIT ENTRY 'Getting Maximum Code for Transaction_Detail MaxNumber "TransDetId", "Max_Codes" TranDetId = Val(MaxNmbr)

PurchaseRef = "Purchase # " & Val(txtId) 'Inserting Data to Transaction Detail Con.Execute "Insert into Transaction_Detail (TranDetId, TranId, AcId, Descript, DrAmount, CrAmount) values (" & Val(TranDetId) & ", " & Val(TranMainId) & ", " & Val(fgPurchase.TextMatrix(FgRow, 5)) & ", '" & PurchaseRef & "', " & Val(fgPurchase.TextMatrix(FgRow, 4)) & ", 0)"

'Updating MaxCode for Transaction Detail UpdateMaxNumber "TransDetId", Val(TranDetId)

Next

'Updating Purchase Main Id UpdateMaxNumber "PurId", Val(txtId)

'Updating Transaction Main Id UpdateMaxNumber "TransId", Val(TranMainId)

'Getting Average Cost for the specifig product Call GetTheAverage

MsgBox "Record saved", vbInformation, "Done" lbl_Click (2)

Else

Dim MTranId As Single 'If existing record

PurMainCode = Val(txtId) TransactionRef = "Purchase-" & Val(txtId)

'Deleting old records from PurchaseMain and Purchase Detail Con.Execute "Delete from Purchase_Detail where PurId = " & Val(txtId) & "" Con.Execute "Delete from Purchase_Main where PurId = " & Val(txtId) & ""

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select * from Transaction_Main where TransRef = '" & TransactionRef & "'", Con, adOpenStatic, adLockOptimistic

MTranId = Val(RS(0))

Con.Execute "Delete from Transaction_Detail Where TranId = " & Val(MTranId) & "" Con.Execute "Delete from Transaction_Main where TransRef = '" & TransactionRef & "'"

'Checking Data to Save If Val(fgPurchase.Rows) < 3 Then MsgBox "No data to save", vbInformation, "Message" Exit Sub End If

'If Account not selected If TxtAcCode.Text = "" Or Val(TxtAcCode) = 0 Then MsgBox "Select Account Name", vbCritical, "Message" TxtName.SetFocus Exit Sub End If

'Inserting Data to TransactionMain Table Con.Execute "insert into Transaction_Main (TransId,TransDate,TransType,Posted,TransRef) values (" & Val(MTranId) & ", '" & Format(Dtp1.Value, "mm/dd/yyyy") & "' , '" & TransactionType & "' ,'" & "N" & "', '" & TransactionRef & "')"

'---------------------INSERTING DATA INTO TRANSACTION_DETAIL for CREDIT ENTRY 'Getting Maximum Code for Transaction_Detail MaxNumber "TransDetId", "Max_Codes" TranDetId = Val(MaxNmbr)

PurchaseRef = "Purchase # " & Val(txtId) 'Inserting Data to Transaction Detail Con.Execute "Insert into Transaction_Detail (TranDetId, TranId, AcId, Descript, DrAmount, CrAmount) values (" & Val(TranDetId) & ", " & Val(MTranId) & ", " & Val(TxtAcCode) & ", '" & PurchaseRef & "', 0 , " & Val(txtTotal) & ")"

'Updating MaxCode for Transaction Detail UpdateMaxNumber "TransDetId", Val(TranDetId)

'----------------------------- Inserting to Purchase Main ----------------------------

'Inserting Data to PurchaseMain Table Con.Execute "insert into Purchase_Main (PurId,PurDate,TotalAmount) values (" & Val(txtId) & ", '" & Format(Dtp1.Value, "mm/dd/yyyy") & "' , " & Val(txtTotal) & " )"

'----------------------------- Inserting to Purchase Detail ----------------------------

For FgRow = 1 To fgPurchase.Rows - 2

'Getting Maximum Code for Purchase_Detail MaxNumber "PurDetId", "Max_Codes" PurchaseId = Val(MaxNmbr)

'Inserting Data to Purchase Detail Con.Execute "Insert into Purchase_Detail (PurDetId, PurId, AcId, ProdId, Qty, Price) values (" & Val(PurchaseId) & ", " & Val(txtId) & ", " & Val(TxtAcCode) & ", '" & fgPurchase.TextMatrix(FgRow, 5) & "', " & Val(fgPurchase.TextMatrix(FgRow, 2)) & ", " & Val(fgPurchase.TextMatrix(FgRow, 3)) & ")"

'Updating MaxCode for Purchase Detail UpdateMaxNumber "PurDetId", Val(PurchaseId)

'---------------------INSERTING DATA INTO TRANSACTION_DETAIL for DEBIT ENTRY (Product in grid Entry) 'Getting Maximum Code for Transaction_Detail MaxNumber "TransDetId", "Max_Codes" TranDetId = Val(MaxNmbr)

PurchaseRef = "Purchase # " & Val(txtId) 'Inserting Data to Transaction Detail Con.Execute "Insert into Transaction_Detail (TranDetId, TranId, AcId, Descript, DrAmount, CrAmount) values (" & Val(TranDetId) & ", " & Val(MTranId) & ", " & Val(fgPurchase.TextMatrix(FgRow, 5)) & ", '" & PurchaseRef & "', " & Val(fgPurchase.TextMatrix(FgRow, 4)) & ", 0)"

'Updating MaxCode for Transaction Detail UpdateMaxNumber "TransDetId", Val(TranDetId)

Next

'Getting Average Cost for the specifig product Call GetTheAverage

MsgBox "Record Updated", vbInformation, "Done" lbl_Click (2)

End If

Case 2 Clear Me

'Cancel

'UnLock Navigation UnLockNav Me

fgPurchase.Clear

modWriteInGrid.SetPSGRID fgPurchase

Call ExistData

Modes False, True, Me

Dtp1.SetFocus

If RsNAV.RecordCount <= 0 Then

Exit Sub Else RsNAV.Requery RsNAV.MoveFirst End If

Case 3 Dim mRef As String Dim mTransID As Integer

'Delete

mRef = "Purchase-" & Val(txtId)

If MsgBox("Do you want to delete this purchase?", vbQuestion + vbYesNo, "Delete Voucher") = vbYes Then If MsgBox("System will be unable to recover the loss data. Continue ?", vbQuestion + vbYesNo, "Delete Voucher") = vbYes Then 'Deleting data from Transaction Main and Detail Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select TransId from Transaction_Main where TransRef = '" & mRef & "'", Con, adOpenStatic, adLockOptimistic mTransID = Val(RS(0))

Con.Execute "Delete from Transaction_Main where TransID = " & mTransID & "" Con.Execute "Delete from Transaction_Detail where TranId = " & mTransID & ""

'Deleting data from Prucase Main and Detial Con.Execute "Delete from Purchase_Detail where PurId = " & Val(txtId) & "" Con.Execute "Delete from Purchase_Main where PurId = " & Val(txtId) & "" MsgBox "Record Deleted", vbInformation, "Message" lbl_Click (2) End If End If

Case 4 picFind.Visible = True optId.Value = True txtFindId.SetFocus txtFindId.Text = ""

'Find

Case 5 Unload Me End Select

'Exit

End Sub

Private Sub lblnav_Click(Index As Integer) Select Case Index

Case 0

'Move First

On Error Resume Next RsNAV.MoveFirst

If RsNAV.BOF = True Then MsgBox "First Record", vbInformation, "Message" RsNAV.MoveFirst Exit Sub Else Call NAVData End If

Case 1

'Move previous

On Error Resume Next RsNAV.MovePrevious

If RsNAV.BOF = True Then MsgBox "First Record", vbInformation, "Message" RsNAV.MoveFirst Else

Call NAVData End If

Case 2

'Move Next

On Error Resume Next RsNAV.MoveNext

If RsNAV.EOF = True Then MsgBox "Last Record", vbInformation, "Message" RsNAV.MoveLast Else Call NAVData End If

Case 3

'Move last

On Error Resume Next RsNAV.MoveLast

If RsNAV.EOF = True Then MsgBox "Last Record", vbInformation, "Message" RsNAV.MoveLast Else

Call NAVData End If

End Select

End Sub

Private Sub lblnav_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Select Case Index Case 0, 1, 2, 3 MouseOver lblnav(Index) End Select

End Sub

Private Sub cmdFind_Click() If txtFindId.Text = "" Or Val(txtFindId) = 0 Then MsgBox "Enter Purchase ID", vbCritical, "Message.." txtFindId.SetFocus Exit Sub

End If

Call FindRecord

End Sub

Private Sub cmdFindCancel_Click() picFind.Visible = False Dtp1.SetFocus

End Sub

Private Sub Dtp1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then TxtName.SetFocus End If End Sub

Private Sub fgpurchase_Click() RowSelect = fgPurchase.RowSel

End Sub

Private Sub fgPurchase_GotFocus() ObjectFoucs = False End Sub

Private Sub fgpurchase_KeyDown(KeyCode As Integer, Shift As Integer) 'If CTRL + SPACE is pressed If fgPurchase.Col = 1 Then If KeyCode = 32 And Shift = 2 Then PicSrchGrid.Visible = True TxtGrdSrch.Text = ""

FillGridAccounts SetGridAccounts

MshSearch.Col = 0 MshSearch.Row = 1 MshSearch.SetFocus End If End If

'Delete Row from Grid If KeyCode = vbKeyDelete Then

If fgPurchase.Rows > 2 And fgPurchase.TextMatrix(fgPurchase.Row, 1) <> "" Then If MsgBox("Do you want to delete this line?", vbQuestion + vbYesNo, "Delete Line") = vbYes Then txtTotal.Text = Val(txtTotal) - Val(fgPurchase.TextMatrix(fgPurchase.Row, 4))

fgPurchase.RemoveItem RowSelect End If

Else MsgBox "Blank or Last line can not be deleted", vbCritical, "Message " Exit Sub End If

End If

End Sub

Private Sub fgpurchase_KeyPress(KeyAscii As Integer) EditGridPS fgPurchase, KeyAscii End Sub

Private Sub fgPurchase_LeaveCell() Select Case fgPurchase.Col Case 1 Call Calculatetotal

Case 2, 3 'Total of Row i.e Qty * Price fgPurchase.TextMatrix(fgPurchase.Row, 4) = Val(fgPurchase.TextMatrix(fgPurchase.Row, 2)) * Val(fgPurchase.TextMatrix(fgPurchase.Row, 3))

End Select

End Sub

Private Sub Form_KeyPress(KeyAscii As Integer) 'Changing Control focus on Enter ChangeFocusOnEnter KeyAscii, Me

End Sub

Private Sub Form_Load()

'Setting up flexgrid SetPSGRID fgPurchase

'Call Existing Data Call ExistData

'Calculating Total Call Calculatetotal

'Calling Data for navigation Set RsNAV = New ADODB.Recordset If RsNAV.State = 1 Then RsNAV.Close RsNAV.Open "Select * from Purchase_Main Order By PurId", Con, adOpenStatic, adLockOptimistic

'Defining Purchase Type TransactionType = "Purchase"

' Setting ObjectFocus variable to True ObjectFoucs = True

End Sub

Public Sub FillGridAccounts() 'Filling all Accounts Data in Search grid If ObjectFoucs = True Then ' If focus on TxtName SQLQry = "SELECT ViewHeadWise.AcId, ViewHeadWise.AcTitle, ViewHeadWise.AcType FROM ViewHeadWise Where AcType NOT IN ('Product')" Else ' If focus on Product Grid

SQLQry = "SELECT ViewHeadWise.AcId, ViewHeadWise.AcTitle, ViewHeadWise.AcType FROM ViewHeadWise Where AcType IN ('Product')" End If

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open SQLQry, Con, adOpenStatic, adLockReadOnly

Set MshSearch.DataSource = RS End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) MouseNormalOnLbl End Sub

Private Sub Image_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) MouseNormalOnLbl

End Sub

Private Sub lbl_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Select Case Index Case 0, 1, 2, 3, 4, 5 MouseOver lbl(Index)

End Select

End Sub

Private Sub TxtGrdSrch_Change() Call SearchRecord End Sub Public Sub SearchRecord() 'Filling the Search grid with Critarial Data

Dim SearchedRowCount As Integer

If PicSrchGrid.Visible = True Then

MshSearch.Rows = 2

MshSearch.Row = 0

SearchedRowCount = 0

If ObjectFoucs = True Then ' If focus on TxtName SQLQry = "SELECT ViewHeadWise.AcId, ViewHeadWise.AcTitle, ViewHeadWise.AcType FROM ViewHeadWise Where AcType NOT IN ('Product') And AcTitle Like '" & TxtGrdSrch.Text & "%'" Else ' If focus on Product Grid

SQLQry = "SELECT ViewHeadWise.AcId, ViewHeadWise.AcTitle, ViewHeadWise.AcType FROM ViewHeadWise Where AcType IN ('Product') And AcTitle Like '" & TxtGrdSrch.Text & "%'" End If

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open SQLQry, Con, adOpenStatic, adLockReadOnly

If RS.RecordCount <= 0 Then MshSearch.Clear

With MshSearch .TextMatrix(0, 0) = "ID" .TextMatrix(0, 1) = "Account Title" .TextMatrix(0, 2) = "Account Type"

End With

MshSearch.Rows = 2 Exit Sub End If

'Fetching data into Search Grid Set MshSearch.DataSource = RS

'' '' '' '' '' '' '' '' '' '' '' '' ''

For SearchedRowCount = 1 To RS.RecordCount

If SearchedRowCount >= MshSearch.Rows - 1 Then MshSearch.Rows = MshSearch.Rows + 1 MshSearch.Row = MshSearch.Row + 1 End If

MshSearch.TextMatrix(SearchedRowCount, 0) = RS(0) MshSearch.TextMatrix(SearchedRowCount, 1) = RS(1) MshSearch.TextMatrix(SearchedRowCount, 2) = RS(2)

RS.MoveNext

''

Next

MshSearch.Col = 0 MshSearch.Row = 0 MshSearch.ColAlignment(0) = 3 End If

End Sub

Private Sub MshSearch_DblClick() If MshSearch.Row = 0 Then Exit Sub End If

If ObjectFoucs = True Then TxtAcCode.Text = Val(MshSearch.TextMatrix(MshSearch.Row, 0)) TxtName.Text = MshSearch.TextMatrix(MshSearch.Row, 1) TxtName.SetFocus ObjectFoucs = False Else 'Checking for duplicate entry in grid Call CheckDuplicate

If Duplicate = True Then Exit Sub End If fgPurchase.TextMatrix(fgPurchase.Row, 1) = MshSearch.TextMatrix(MshSearch.Row, 1) fgPurchase.TextMatrix(fgPurchase.Row, 5) = MshSearch.TextMatrix(MshSearch.Row, 0) fgPurchase.SetFocus End If

PicSrchGrid.Visible = False fgPurchase.Col = 1

End Sub

Public Sub CheckDuplicate() Dim dRow As Integer

For dRow = 1 To fgPurchase.Rows - 2 If fgPurchase.TextMatrix(dRow, 5) = MshSearch.TextMatrix(MshSearch.Row, 0) Then MsgBox "Account Title aleready selected", vbInformation, "Message" Duplicate = True Exit Sub Else

Duplicate = False End If Next

End Sub

Private Sub MshSearch_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then MshSearch_DblClick End If

If KeyAscii = 27 Then PicSrchGrid.Visible = False fgPurchase.SetFocus Exit Sub End If

If KeyAscii = 8 Then If TxtGrdSrch.Text <> "" Then TxtGrdSrch.Text = Left$(TxtGrdSrch.Text, (Len(TxtGrdSrch.Text) - 1)) ElseIf KeyAscii = 13 Then KeyAscii = 0 Else

TxtGrdSrch.Text = TxtGrdSrch.Text + Chr$(KeyAscii) End If

End Sub

Private Sub TxtGrdSrch_KeyPress(KeyAscii As Integer) If KeyAscii = 27 Then PicSrchGrid.Visible = False fgPurchase.SetFocus Exit Sub End If End Sub

Public Sub ExistData()

'Getting data from Purchase Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open "SELECT PurId, PurDate, TotalAmount from Purchase_Main", Con, adOpenStatic, adLockOptimistic

If RS.EOF = True Then Exit Sub

End If

txtId.Text = Val(RS(0)) Dtp1.Value = RS(1) RS.Close

'Getting Supplier Data Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "SELECT Accounts.AcId, Accounts.AcTitle, Purchase_Detail.PurId FROM Accounts INNER JOIN Purchase_Detail ON Accounts.AcId = Purchase_Detail.AcId where PurId = " & Val(txtId) & "", Con, adOpenStatic, adLockOptimistic TxtAcCode.Text = Val(RS(0)) TxtName.Text = RS(1)

'Getting data from Purchase_Detail Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

mSqlQry = "SELECT * from ViewPurchase where PurId = " & Val(txtId) & ""

RS.Open mSqlQry, Con, adOpenStatic, adLockOptimistic

If RS.RecordCount <= 0 Then Exit Sub End If

fgPurchase.Rows = 2 fgPurchase.Row = 1

For rCount = 1 To RS.RecordCount fgPurchase.TextMatrix(fgPurchase.Row, 1) = RS(0) fgPurchase.TextMatrix(fgPurchase.Row, 2) = Val(RS(1)) fgPurchase.TextMatrix(fgPurchase.Row, 3) = Val(RS(2)) 'Prod Name 'Qty 'Price

fgPurchase.TextMatrix(fgPurchase.Row, 4) = Val(RS(1)) * Val(RS(2)) 'Amount fgPurchase.TextMatrix(fgPurchase.Row, 5) = Val(RS(3)) 'Prod Code

fgPurchase.Rows = fgPurchase.Rows + 1 fgPurchase.Row = fgPurchase.Row + 1

RS.MoveNext Next

End Sub

Public Sub NAVData()

'Getting data from Purchase

txtId.Text = Val(RsNAV(0)) Dtp1.Value = RsNAV(1)

'Getting Supplier Data Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "SELECT Accounts.AcId, Accounts.AcTitle, Purchase_Detail.PurId FROM Accounts INNER JOIN Purchase_Detail ON Accounts.AcId = Purchase_Detail.AcId where PurId = " & Val(txtId) & "", Con, adOpenStatic, adLockOptimistic TxtAcCode.Text = Val(RS(0)) TxtName.Text = RS(1)

'Getting data from Purchase_Detail Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

mSqlQry = "SELECT * from ViewPurchase where PurId = " & Val(txtId) & ""

RS.Open mSqlQry, Con, adOpenStatic, adLockOptimistic

If RS.RecordCount <= 0 Then Exit Sub End If

fgPurchase.Rows = 2 fgPurchase.Row = 1

For rCount = 1 To RS.RecordCount fgPurchase.TextMatrix(fgPurchase.Row, 1) = RS(0) fgPurchase.TextMatrix(fgPurchase.Row, 2) = Val(RS(1)) fgPurchase.TextMatrix(fgPurchase.Row, 3) = Val(RS(2)) 'Prod Name 'Qty 'Price

fgPurchase.TextMatrix(fgPurchase.Row, 4) = Val(RS(1)) * Val(RS(2)) 'Amount fgPurchase.TextMatrix(fgPurchase.Row, 5) = Val(RS(3)) 'Prod Code

fgPurchase.Rows = fgPurchase.Rows + 1 fgPurchase.Row = fgPurchase.Row + 1

RS.MoveNext Next

Calculatetotal

End Sub

Public Sub AutoId() 'Calling MaxNumber function to get Auto Id for the record MaxNumber "PurId", "Max_Codes" txtId.Text = Val(MaxNmbr) End Sub

Public Sub Calculatetotal() Dim mRow As Integer

txtTotal.Text = "" For mRow = 1 To fgPurchase.Rows - 1 txtTotal.Text = Val(txtTotal) + Val(fgPurchase.TextMatrix(mRow, 4)) Next mRow End Sub

Private Sub TxtAcCode_GotFocus() TxtName.SetFocus End Sub

Private Sub TxtName_GotFocus() ObjectFoucs = True End Sub

Private Sub TxtName_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 32 And Shift = 2 Then PicSrchGrid.Visible = True TxtGrdSrch.Text = ""

FillGridAccounts SetGridAccounts

MshSearch.Col = 0 MshSearch.Row = 1 MshSearch.SetFocus End If

End Sub

Public Sub SetGridAccounts() 'Setting of Search Grid With MshSearch .ColWidth(1) = 2500

.ColWidth(2) = 1500

.TextMatrix(0, 0) = "ID" .TextMatrix(0, 1) = "Account Title" .TextMatrix(0, 2) = "Account Type"

.RowHeight(0) = 400

.ColAlignmentFixed(0) = 4 .ColAlignmentFixed(1) = 4 .ColAlignmentFixed(2) = 4

End With

End Sub

Private Sub TxtName_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then fgPurchase.SetFocus Else KeyAscii = 0 Exit Sub End If

End Sub

Public Sub FindRecord() mSqlQry = "Select * from Purchase_Main Where PurId = " & Val(txtFindId) & ""

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open mSqlQry, Con, adOpenStatic, adLockOptimistic If RS.RecordCount <= 0 Then MsgBox "No purchase found with this ID", vbCritical, "Message.." txtFindId.SetFocus Exit Sub Else ShowFoundData End If

End Sub

Public Sub ShowFoundData() 'Getting data from Purchase

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open "SELECT PurId, PurDate, TotalAmount from Purchase_Main Where PurId = " & Val(txtFindId) & "", Con, adOpenStatic, adLockOptimistic

If RS.EOF = True Then Exit Sub End If

txtId.Text = Val(RS(0)) Dtp1.Value = RS(1) RS.Close

'Getting Supplier Data Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "SELECT Accounts.AcId, Accounts.AcTitle, Purchase_Detail.PurId FROM Accounts INNER JOIN Purchase_Detail ON Accounts.AcId = Purchase_Detail.AcId where PurId = " & Val(txtId) & "", Con, adOpenStatic, adLockOptimistic TxtAcCode.Text = Val(RS(0)) TxtName.Text = RS(1)

'Getting data from Purchase_Detail Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

mSqlQry = "SELECT * from ViewPurchase where PurId = " & Val(txtId) & ""

RS.Open mSqlQry, Con, adOpenStatic, adLockOptimistic

If RS.RecordCount <= 0 Then Exit Sub End If

fgPurchase.Rows = 2 fgPurchase.Row = 1

For rCount = 1 To RS.RecordCount fgPurchase.TextMatrix(fgPurchase.Row, 1) = RS(0) fgPurchase.TextMatrix(fgPurchase.Row, 2) = Val(RS(1)) fgPurchase.TextMatrix(fgPurchase.Row, 3) = Val(RS(2)) 'Prod Name 'Qty 'Price

fgPurchase.TextMatrix(fgPurchase.Row, 4) = Val(RS(1)) * Val(RS(2)) 'Amount fgPurchase.TextMatrix(fgPurchase.Row, 5) = Val(RS(3)) 'Prod Code

fgPurchase.Rows = fgPurchase.Rows + 1 fgPurchase.Row = fgPurchase.Row + 1

RS.MoveNext Next

picFind.Visible = False Dtp1.SetFocus

End Sub

Public Sub MouseNormalOnLbl() 'Commands Lable lbl(0).ForeColor = vbWhite lbl(0).Font.Underline = False

lbl(1).ForeColor = vbWhite lbl(1).Font.Underline = False

lbl(2).ForeColor = vbWhite lbl(2).Font.Underline = False

lbl(3).ForeColor = vbWhite

lbl(3).Font.Underline = False

lbl(4).ForeColor = vbWhite lbl(4).Font.Underline = False

lbl(5).ForeColor = vbWhite lbl(5).Font.Underline = False

'Navigation Label lblnav(0).ForeColor = vbWhite lblnav(0).Font.Underline = False

lblnav(1).ForeColor = vbWhite lblnav(1).Font.Underline = False

lblnav(2).ForeColor = vbWhite lblnav(2).Font.Underline = False

lblnav(3).ForeColor = vbWhite lblnav(3).Font.Underline = False

End Sub

Public Sub GetTheAverage() Dim CurQty As Single Dim CurAmount As Single Dim mTotalQty As Single Dim mTotalAmount As Single Dim myRow As Integer

For myRow = 1 To fgPurchase.Rows - 2 Set RsMisc = New ADODB.Recordset If RsMisc.State = 1 Then RsMisc.Close RsMisc.Open "Select Qty, Amount, ProdId from Product_Openings where ProdId = " & Val(fgPurchase.TextMatrix(myRow, 5)) & "", Con, adOpenStatic, adLockOptimistic If Not IsNull(RsMisc(0)) Then OpQty = Val(RsMisc(0)) OpAmount = Val(RsMisc(1)) Else OpQty = 0 OpAmount = 0 End If

CurQty = Val(fgPurchase.TextMatrix(myRow, 2)) CurAmount = Val(fgPurchase.TextMatrix(myRow, 4))

mTotalQty = Val(OpQty) + Val(CurQty) mTotalAmount = Val(OpAmount) + Val(CurAmount)

AvgCost = Round(Val(mTotalAmount) / Val(mTotalQty), 2)

Con.Execute "Update Avg_Cost set PurAvg = " & Val(AvgCost) & " Where ProdId = " & Val(fgPurchase.TextMatrix(myRow, 5)) & ""

Next

End Sub

5. frmSale.frm
This form creates the interface for the function of creating sales entries.

Coding:
Dim Duplicate As Boolean Dim RowSelect As Integer Dim rCount As Integer Dim mSqlQry As String Dim SaleId As Single Dim SaleMainCode As Single Dim ObjectFoucs As Boolean 'True if Focus on TxtName(Supplier Name) . False if Focus on Grid

Dim OpQty As Single Dim PurQty As Single Dim SaleQty As Single Dim Stock As Single Dim mAvgCost As Single Dim PLAmount As Single Dim FgRow As Integer

Private Sub Form_Resize() Me.Top = 1500 Me.Left = 4200

End Sub

Private Sub lbl_Click(Index As Integer) Select Case Index Case 0 'New

'Clearing all controls for New Data Clear Me fgSale.Clear

modWriteInGrid.SetPSGRID fgSale

Call AutoId

Dtp1.SetFocus Dtp1.Value = Now

Modes True, False, Me

'Lock Navigation LockNav Me

Case 1 Dim TranDetId As Single Dim SaleRef As String Dim TranMainId As Single

'Save

'Checking Data to Save If Val(fgSale.Rows) < 3 Then MsgBox "No data to save", vbInformation, "Message" Exit Sub End If

'If Account not selected If TxtAcCode.Text = "" Or Val(TxtAcCode) = 0 Then

MsgBox "Select Account Name", vbCritical, "Message" TxtName.SetFocus Exit Sub End If

'If New Sale

If lbl(0).Enabled = False Then

TransactionRef = "Sale-" & Val(txtId)

'Getting Maximum Code for Sale Main MaxNumber "SaleId", "Max_Codes" SaleMainCode = Val(MaxNmbr)

'Getting Maximum Code for Transaction Main MaxNumber "TransId", "Max_Codes" TranMainId = Val(MaxNmbr)

'Inserting Data to TransactionMain Table Con.Execute "insert into Transaction_Main (TransId,TransDate,TransType,Posted,TransRef) values (" & Val(TranMainId) & ", '" & Format(Dtp1.Value, "mm/dd/yyyy") & "' , '" & TransactionType & "' ,'" & "N" & "', '" & TransactionRef & "')"

'---------------------INSERTING DATA INTO TRANSACTION_DETAIL for DEBIT ENTRY (Customer or th whom the goods sold) 'Getting Maximum Code for Transaction_Detail MaxNumber "TransDetId", "Max_Codes" TranDetId = Val(MaxNmbr)

SaleRef = "Sale # " & Val(txtId) 'Inserting Data to Transaction Detail Con.Execute "Insert into Transaction_Detail (TranDetId, TranId, AcId, Descript, DrAmount, CrAmount) values (" & Val(TranDetId) & ", " & Val(TranMainId) & ", " & Val(TxtAcCode) & ", '" & SaleRef & "', " & Val(txtTotal) & " , 0)"

'Updating MaxCode for Transaction Detail UpdateMaxNumber "TransDetId", Val(TranDetId)

'----------------------------- Inserting to Sale Main ----------------------------

Con.Execute "insert into Sale_Main (SaleId,SaleDate,TotalAmount) values (" & Val(txtId) & ", '" & Format(Dtp1.Value, "mm/dd/yyyy") & "' , " & Val(txtTotal) & " )"

'----------------------------- Inserting to Sale Detail ----------------------------

For FgRow = 1 To fgSale.Rows - 2

'Getting Maximum Code for Sale_Detail MaxNumber "SaleDetId", "Max_Codes" SaleId = Val(MaxNmbr)

'Inserting Data to Sale Detail Con.Execute "Insert into Sale_Detail (SaleDetId, SaleId, AcId, ProdId, Qty, Price) values (" & Val(SaleId) & ", " & Val(txtId) & ", " & Val(TxtAcCode) & ", '" & fgSale.TextMatrix(FgRow, 5) & "', " & Val(fgSale.TextMatrix(FgRow, 2)) & ", " & Val(fgSale.TextMatrix(FgRow, 3)) & ")"

'Updating MaxCode for Sale Detail UpdateMaxNumber "SaleDetId", Val(SaleId)

'Inserting Data Into ProfitLoss Call GetAvgCostUpdate PLAmount = Val(fgSale.TextMatrix(FgRow, 3)) - Val(fgSale.TextMatrix(FgRow, 6)) PLAmount = Val(PLAmount) * Val(fgSale.TextMatrix(FgRow, 2)) Con.Execute "Insert Into ProfitLoss Values('" & Format(Dtp1.Value, "mm/dd/yyyy") & "', " & Val(txtId) & ", " & fgSale.TextMatrix(FgRow, 5) & ", " & Val(fgSale.TextMatrix(FgRow, 2)) & ", " & Val(fgSale.TextMatrix(FgRow, 6)) & ", " & Val(fgSale.TextMatrix(FgRow, 3)) & ", " & Val(PLAmount) & " )"

'---------------------INSERTING DATA INTO TRANSACTION_DETAIL for CREDIT ENTRY (Product entry) 'Getting Maximum Code for Transaction_Detail MaxNumber "TransDetId", "Max_Codes" TranDetId = Val(MaxNmbr)

SaleRef = "Sale # " & Val(txtId) 'Inserting Data to Transaction Detail Con.Execute "Insert into Transaction_Detail (TranDetId, TranId, AcId, Descript, DrAmount, CrAmount) values (" & Val(TranDetId) & ", " & Val(TranMainId) & ", " & Val(fgSale.TextMatrix(FgRow, 5)) & ", '" & SaleRef & "', 0, " & Val(fgSale.TextMatrix(FgRow, 4)) & ")"

'Updating MaxCode for Transaction Detail UpdateMaxNumber "TransDetId", Val(TranDetId)

Next

'Updating Sale Main Id UpdateMaxNumber "SaleId", Val(txtId)

'Updating Transaction Main Id UpdateMaxNumber "TransId", Val(TranMainId)

MsgBox "Record saved", vbInformation, "Done" lbl_Click (2)

Else

Dim MTranId As Single 'If existing record SaleMainCode = Val(txtId) TransactionRef = "Sale-" & Val(txtId)

'Deleting old records from SaleMain and Sale Detail Con.Execute "Delete from Sale_Detail where SaleId = " & Val(txtId) & "" Con.Execute "Delete from Sale_Main where SaleId = " & Val(txtId) & ""

'Deleting Record from ProfitLoss Table Con.Execute "Delete from ProfitLoss where SaleId = " & Val(txtId) & ""

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select * from Transaction_Main where TransRef = '" & TransactionRef & "'", Con, adOpenStatic, adLockOptimistic

MTranId = Val(RS(0))

Con.Execute "Delete from Transaction_Detail Where TranId = " & Val(MTranId) & "" Con.Execute "Delete from Transaction_Main where TransRef = '" & TransactionRef & "'"

'Checking Data to Save If Val(fgSale.Rows) < 3 Then MsgBox "No data to save", vbInformation, "Message" Exit Sub End If

'If Account not selected If TxtAcCode.Text = "" Or Val(TxtAcCode) = 0 Then MsgBox "Select Account Name", vbCritical, "Message" TxtName.SetFocus Exit Sub End If

'Inserting Data to TransactionMain Table Con.Execute "insert into Transaction_Main (TransId,TransDate,TransType,Posted,TransRef) values (" & Val(MTranId) & ", '" & Format(Dtp1.Value, "mm/dd/yyyy") & "' , '" & TransactionType & "' ,'" & "N" & "', '" &

TransactionRef & "')"

'---------------------INSERTING DATA INTO TRANSACTION_DETAIL for DEBIT ENTRY (Customer or to whome the goods sold) 'Getting Maximum Code for Transaction_Detail MaxNumber "TransDetId", "Max_Codes" TranDetId = Val(MaxNmbr)

SaleRef = "Sale # " & Val(txtId) 'Inserting Data to Transaction Detail Con.Execute "Insert into Transaction_Detail (TranDetId, TranId, AcId, Descript, DrAmount, CrAmount) values (" & Val(TranDetId) & ", " & Val(MTranId) & ", " & Val(TxtAcCode) & ", '" & SaleRef & "', " & Val(txtTotal) & " , 0)"

'Updating MaxCode for Transaction Detail UpdateMaxNumber "TransDetId", Val(TranDetId)

'----------------------------- Inserting to Sale Main ----------------------------

'Inserting Data to SaleMain Table Con.Execute "insert into Sale_Main (SaleId,SaleDate,TotalAmount) values (" & Val(txtId) & ", '" & Format(Dtp1.Value, "mm/dd/yyyy") & "' , " & Val(txtTotal) & " )"

'----------------------------- Inserting to Sale Detail ----------------------------

For FgRow = 1 To fgSale.Rows - 2

'Getting Maximum Code for Sale_Detail MaxNumber "SaleDetId", "Max_Codes" SaleId = Val(MaxNmbr)

'Inserting Data to Sale Detail Con.Execute "Insert into Sale_Detail (SaleDetId, SaleId, AcId, ProdId, Qty, Price) values (" & Val(SaleId) & ", " & Val(txtId) & ", " & Val(TxtAcCode) & ", '" & fgSale.TextMatrix(FgRow, 5) & "', " & Val(fgSale.TextMatrix(FgRow, 2)) & ", " & Val(fgSale.TextMatrix(FgRow, 3)) & ")"

'Updating MaxCode for Sale Detail UpdateMaxNumber "SaleDetId", Val(SaleId)

'Inserting Data Into ProfitLoss Call GetAvgCostUpdate PLAmount = Val(fgSale.TextMatrix(FgRow, 3)) - Val(fgSale.TextMatrix(FgRow, 6)) PLAmount = Val(PLAmount) * Val(fgSale.TextMatrix(FgRow, 2)) Con.Execute "Insert Into ProfitLoss Values('" & Format(Dtp1.Value, "mm/dd/yyyy") & "', " & Val(txtId) & ", " & fgSale.TextMatrix(FgRow, 5) & ", " & Val(fgSale.TextMatrix(FgRow, 2)) & ", " & Val(fgSale.TextMatrix(FgRow, 6)) & ", " & Val(fgSale.TextMatrix(FgRow, 3)) & ", " & Val(PLAmount) & " )"

'---------------------INSERTING DATA INTO TRANSACTION_DETAIL for CREDIT ENTRY (Product in grid Entry) 'Getting Maximum Code for Transaction_Detail MaxNumber "TransDetId", "Max_Codes" TranDetId = Val(MaxNmbr)

SaleRef = "Sale # " & Val(txtId) 'Inserting Data to Transaction Detail Con.Execute "Insert into Transaction_Detail (TranDetId, TranId, AcId, Descript, DrAmount, CrAmount) values (" & Val(TranDetId) & ", " & Val(MTranId) & ", " & Val(fgSale.TextMatrix(FgRow, 5)) & ", '" & SaleRef & "', 0, " & Val(fgSale.TextMatrix(FgRow, 4)) & ")"

'Updating MaxCode for Transaction Detail UpdateMaxNumber "TransDetId", Val(TranDetId)

Next

MsgBox "Record Updated", vbInformation, "Done" lbl_Click (2)

End If Case 2 Clear Me 'Cancel

'UnLock Navigation UnLockNav Me

fgSale.Clear

modWriteInGrid.SetPSGRID fgSale

Call ExistData

Modes False, True, Me

Dtp1.SetFocus

If RsNAV.RecordCount <= 0 Then Exit Sub Else RsNAV.Requery RsNAV.MoveFirst End If

Case 3 Dim mRef As String

'Delete

Dim mTransID As Integer mRef = "Sale-" & Val(txtId)

If MsgBox("Do you want to delete this purchase?", vbQuestion + vbYesNo, "Delete Voucher") = vbYes Then If MsgBox("System will be unable to recover the loss data. Continue ?", vbQuestion + vbYesNo, "Delete Voucher") = vbYes Then 'Deleting data from Transaction Main and Detail Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select TransId from Transaction_Main where TransRef = '" & mRef & "'", Con, adOpenStatic, adLockOptimistic mTransID = Val(RS(0))

Con.Execute "Delete from Transaction_Main where TransID = " & mTransID & "" Con.Execute "Delete from Transaction_Detail where TranId = " & mTransID & "" 'Deleting data from Transaction Main and Detail Con.Execute "Delete from Sale_Detail where SaleId = " & Val(txtId) & "" Con.Execute "Delete from Sale_Main where SaleId = " & Val(txtId) & "" MsgBox "Record Deleted", vbInformation, "Message" lbl_Click (2) End If End If

Case 4 picFind.Visible = True optId.Value = True txtFindId.SetFocus txtFindId.Text = ""

'Find

Case 5 Unload Me

'Exit

End Select

End Sub

Private Sub lbl_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Select Case Index Case 0, 1, 2, 3, 4, 5 MouseOver lbl(Index)

End Select

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) MouseNormalOnLbl End Sub

Private Sub Image_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) MouseNormalOnLbl End Sub

Private Sub lblnav_Click(Index As Integer) Select Case Index

Case 0

'Move First

On Error Resume Next RsNAV.MoveFirst

If RsNAV.BOF = True Then MsgBox "First Record", vbInformation, "Message" RsNAV.MoveFirst Exit Sub Else Call NAVData End If

Case 1

'Move previous

On Error Resume Next RsNAV.MovePrevious

If RsNAV.BOF = True Then MsgBox "First Record", vbInformation, "Message" RsNAV.MoveFirst Else Call NAVData End If

Case 2

'Move Next

On Error Resume Next RsNAV.MoveNext

If RsNAV.EOF = True Then MsgBox "Last Record", vbInformation, "Message" RsNAV.MoveLast Else Call NAVData End If

Case 3

'Move last

On Error Resume Next RsNAV.MoveLast

If RsNAV.EOF = True Then MsgBox "Last Record", vbInformation, "Message" RsNAV.MoveLast Else Call NAVData End If

End Select

End Sub

Private Sub lblnav_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Select Case Index Case 0, 1, 2, 3 MouseOver lblnav(Index) End Select

End Sub

Private Sub cmdFind_Click() If txtFindId.Text = "" Or Val(txtFindId) = 0 Then MsgBox "Enter Sale ID", vbCritical, "Message.." txtFindId.SetFocus Exit Sub End If

Call FindRecord End Sub

Private Sub cmdFindCancel_Click() picFind.Visible = False Dtp1.SetFocus

End Sub

Private Sub Dtp1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then

TxtName.SetFocus End If End Sub

Private Sub fgSale_Click() RowSelect = fgSale.RowSel End Sub

Private Sub fgSale_EnterCell()

Select Case fgSale.Col

Case 1 lblstock.Caption = "Available Stock : "

Case 3 Call CheckStock_n_Price If Val(Stock) < Val(fgSale.TextMatrix(fgSale.Row, 2)) Then MsgBox "Not enough stock to sale", vbCritical, "Message" fgSale.Col = 2 Exit Sub End If End Select

End Sub

Private Sub fgSale_GotFocus() ObjectFoucs = False End Sub

Private Sub fgSale_KeyDown(KeyCode As Integer, Shift As Integer) 'If CTRL + SPACE is pressed If fgSale.Col = 1 Then If KeyCode = 32 And Shift = 2 Then PicSrchGrid.Visible = True TxtGrdSrch.Text = ""

FillGridAccounts SetGridAccounts

MshSearch.Col = 0 MshSearch.Row = 1 MshSearch.SetFocus End If End If

'Delete Row from Grid

If KeyCode = vbKeyDelete Then

If fgSale.Rows > 2 And fgSale.TextMatrix(fgSale.Row, 1) <> "" Then If MsgBox("Do you want to delete this line?", vbQuestion + vbYesNo, "Delete Line") = vbYes Then txtTotal.Text = Val(txtTotal) - Val(fgSale.TextMatrix(fgSale.Row, 4))

fgSale.RemoveItem RowSelect End If

Else MsgBox "Blank or Last line can not be deleted", vbCritical, "Message " Exit Sub End If

End If End Sub

Private Sub fgSale_KeyPress(KeyAscii As Integer) EditGridPS fgSale, KeyAscii End Sub

Private Sub fgSale_LeaveCell()

Select Case fgSale.Col Case 1 Call Calculatetotal

Case 2, 3 'Total of Row i.e Qty * Price fgSale.TextMatrix(fgSale.Row, 4) = Val(fgSale.TextMatrix(fgSale.Row, 2)) * Val(fgSale.TextMatrix(fgSale.Row, 3))

End Select End Sub

Private Sub Form_KeyPress(KeyAscii As Integer) 'Changing Control focus on Enter ChangeFocusOnEnter KeyAscii, Me

End Sub

Private Sub Form_Load()

Me.Top = 1500 Me.Left = 3000

'Setting up flexgrid SetPSGRID fgSale

'Call Existing Data Call ExistData

'Calculating Total Call Calculatetotal

'Calling Data for navigation Set RsNAV = New ADODB.Recordset If RsNAV.State = 1 Then RsNAV.Close RsNAV.Open "Select * from Sale_Main Order By SaleId", Con, adOpenStatic, adLockOptimistic

'Defining Sale Type TransactionType = "Sale"

' Setting ObjectFocus variable to True ObjectFoucs = True

End Sub

Public Sub FillGridAccounts() 'Filling all Accounts Data in Search grid If ObjectFoucs = True Then ' If focus on TxtName SQLQry = "SELECT ViewHeadWise.AcId, ViewHeadWise.AcTitle, ViewHeadWise.AcType FROM ViewHeadWise Where AcType NOT IN ('Product')" Else ' If focus on Product Grid

SQLQry = "SELECT ViewHeadWise.AcId, ViewHeadWise.AcTitle, ViewHeadWise.AcType FROM ViewHeadWise Where AcType IN ('Product')" End If

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open SQLQry, Con, adOpenStatic, adLockReadOnly

Set MshSearch.DataSource = RS End Sub

Private Sub TxtGrdSrch_Change() Call SearchRecord End Sub Public Sub SearchRecord() 'Filling the Search grid with Critarial Data

Dim SearchedRowCount As Integer

If PicSrchGrid.Visible = True Then

MshSearch.Rows = 2 MshSearch.Row = 0

SearchedRowCount = 0

If ObjectFoucs = True Then ' If focus on TxtName SQLQry = "SELECT ViewHeadWise.AcId, ViewHeadWise.AcTitle, ViewHeadWise.AcType FROM ViewHeadWise Where AcType NOT IN ('Product') And AcTitle Like '" & TxtGrdSrch.Text & "%'" Else ' If focus on Product Grid

SQLQry = "SELECT ViewHeadWise.AcId, ViewHeadWise.AcTitle, ViewHeadWise.AcType FROM ViewHeadWise Where AcType IN ('Product') And AcTitle Like '" & TxtGrdSrch.Text & "%'" End If

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open SQLQry, Con, adOpenStatic, adLockReadOnly

If RS.RecordCount <= 0 Then

MshSearch.Clear

With MshSearch .TextMatrix(0, 0) = "ID" .TextMatrix(0, 1) = "Account Title" .TextMatrix(0, 2) = "Account Type" End With

MshSearch.Rows = 2 Exit Sub End If

'Fetching data into Search Grid Set MshSearch.DataSource = RS

MshSearch.Col = 0 MshSearch.Row = 0 MshSearch.ColAlignment(0) = 3 End If

End Sub

Private Sub MshSearch_DblClick() If MshSearch.Row = 0 Then Exit Sub End If

If ObjectFoucs = True Then TxtAcCode.Text = Val(MshSearch.TextMatrix(MshSearch.Row, 0)) TxtName.Text = MshSearch.TextMatrix(MshSearch.Row, 1) TxtName.SetFocus ObjectFoucs = False Else 'Checking for duplicate entry in grid Call CheckDuplicate

If Duplicate = True Then Exit Sub End If fgSale.TextMatrix(fgSale.Row, 1) = MshSearch.TextMatrix(MshSearch.Row, 1) fgSale.TextMatrix(fgSale.Row, 5) = MshSearch.TextMatrix(MshSearch.Row, 0) fgSale.TextMatrix(fgSale.Row, 6) = Val(mAvgCost)

fgSale.SetFocus

Call CheckStock_n_Price End If

PicSrchGrid.Visible = False fgSale.Col = 1

End Sub

Public Sub CheckDuplicate() Dim dRow As Integer

For dRow = 1 To fgSale.Rows - 2 If fgSale.TextMatrix(dRow, 5) = MshSearch.TextMatrix(MshSearch.Row, 0) Then MsgBox "Account Title aleready selected", vbInformation, "Message" Duplicate = True Exit Sub Else Duplicate = False End If Next

End Sub

Private Sub MshSearch_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then MshSearch_DblClick End If

If KeyAscii = 27 Then PicSrchGrid.Visible = False fgSale.SetFocus Exit Sub End If

If KeyAscii = 8 Then If TxtGrdSrch.Text <> "" Then TxtGrdSrch.Text = Left$(TxtGrdSrch.Text, (Len(TxtGrdSrch.Text) - 1)) ElseIf KeyAscii = 13 Then KeyAscii = 0 Else TxtGrdSrch.Text = TxtGrdSrch.Text + Chr$(KeyAscii) End If

End Sub

Private Sub TxtGrdSrch_KeyPress(KeyAscii As Integer) If KeyAscii = 27 Then PicSrchGrid.Visible = False fgSale.SetFocus Exit Sub End If End Sub

Public Sub ExistData()

'Getting data from Sale Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open "SELECT SaleId, SaleDate, TotalAmount from Sale_Main", Con, adOpenStatic, adLockOptimistic

If RS.EOF = True Then Exit Sub End If

txtId.Text = Val(RS(0)) Dtp1.Value = RS(1) RS.Close

'Getting Supplier Data Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "SELECT Accounts.AcId, Accounts.AcTitle, Sale_Detail.SaleId FROM Accounts INNER JOIN Sale_Detail ON Accounts.AcId = Sale_Detail.AcId where SaleId = " & Val(txtId) & "", Con, adOpenStatic, adLockOptimistic TxtAcCode.Text = Val(RS(0)) TxtName.Text = RS(1)

'Getting data from Sale_Detail Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

mSqlQry = "SELECT * from ViewSale where SaleId = " & Val(txtId) & ""

RS.Open mSqlQry, Con, adOpenStatic, adLockOptimistic

If RS.RecordCount <= 0 Then Exit Sub End If

fgSale.Rows = 2 fgSale.Row = 1

For rCount = 1 To RS.RecordCount fgSale.TextMatrix(fgSale.Row, 1) = RS(0) fgSale.TextMatrix(fgSale.Row, 2) = Val(RS(1)) fgSale.TextMatrix(fgSale.Row, 3) = Val(RS(2)) 'Prod Name 'Qty 'Price

fgSale.TextMatrix(fgSale.Row, 4) = Val(RS(1)) * Val(RS(2)) 'Amount fgSale.TextMatrix(fgSale.Row, 5) = Val(RS(3)) 'Prod Code

fgSale.Rows = fgSale.Rows + 1 fgSale.Row = fgSale.Row + 1

RS.MoveNext Next

End Sub

Private Sub PicFirst_Click() On Error Resume Next RsNAV.MoveFirst lblnav.Caption = "1"

If RsNAV.BOF = True Then MsgBox "First Record", vbInformation, "Message" RsNAV.MoveFirst Exit Sub Else Call NAVData End If End Sub

Private Sub PicLast_Click() On Error Resume Next RsNAV.MoveLast lblnav.Caption = Val(RsNAV.RecordCount)

If RsNAV.EOF = True Then MsgBox "Last Record", vbInformation, "Message" RsNAV.MoveLast Else Call NAVData End If

End Sub

Private Sub PicNext_Click() On Error Resume Next RsNAV.MoveNext

lblnav.Caption = Val(lblnav) + 1

If RsNAV.EOF = True Then lblnav.Caption = Val(lblnav) - 1 MsgBox "Last Record", vbInformation, "Message" RsNAV.MoveLast Else Call NAVData End If End Sub

Private Sub PicPrev_Click() On Error Resume Next RsNAV.MovePrevious

lblnav.Caption = Val(lblnav) - 1

If RsNAV.BOF = True Then

lblnav.Caption = Val(lblnav) + 1 MsgBox "First Record", vbInformation, "Message" RsNAV.MoveFirst Else Call NAVData End If

End Sub

Public Sub NAVData()

'Getting data from Sale

txtId.Text = Val(RsNAV(0)) Dtp1.Value = RsNAV(1)

'Getting Supplier Data Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "SELECT Accounts.AcId, Accounts.AcTitle, Sale_Detail.SaleId FROM Accounts INNER JOIN Sale_Detail ON Accounts.AcId = Sale_Detail.AcId where SaleId = " & Val(txtId) & "", Con, adOpenStatic, adLockOptimistic TxtAcCode.Text = Val(RS(0)) TxtName.Text = RS(1)

'Getting data from Sale_Detail Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

mSqlQry = "SELECT * from ViewSale where SaleId = " & Val(txtId) & ""

RS.Open mSqlQry, Con, adOpenStatic, adLockOptimistic

If RS.RecordCount <= 0 Then Exit Sub End If

fgSale.Rows = 2 fgSale.Row = 1

For rCount = 1 To RS.RecordCount fgSale.TextMatrix(fgSale.Row, 1) = RS(0) fgSale.TextMatrix(fgSale.Row, 2) = Val(RS(1)) fgSale.TextMatrix(fgSale.Row, 3) = Val(RS(2)) 'Prod Name 'Qty 'Price

fgSale.TextMatrix(fgSale.Row, 4) = Val(RS(1)) * Val(RS(2)) 'Amount

fgSale.TextMatrix(fgSale.Row, 5) = Val(RS(3))

'Prod Code

fgSale.Rows = fgSale.Rows + 1 fgSale.Row = fgSale.Row + 1

RS.MoveNext Next

Calculatetotal

End Sub

Public Sub AutoId() 'Calling MaxNumber function to get Auto Id for the record MaxNumber "SaleId", "Max_Codes" txtId.Text = Val(MaxNmbr) End Sub

Public Sub Calculatetotal() Dim mRow As Integer

txtTotal.Text = ""

For mRow = 1 To fgSale.Rows - 1 txtTotal.Text = Val(txtTotal) + Val(fgSale.TextMatrix(mRow, 4)) Next mRow End Sub

Private Sub TxtAcCode_GotFocus() TxtName.SetFocus End Sub

Private Sub TxtName_GotFocus() ObjectFoucs = True End Sub

Private Sub TxtName_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 32 And Shift = 2 Then PicSrchGrid.Visible = True TxtGrdSrch.Text = ""

FillGridAccounts SetGridAccounts

MshSearch.Col = 0 MshSearch.Row = 1

MshSearch.SetFocus End If

End Sub

Public Sub SetGridAccounts() 'Setting of Search Grid With MshSearch .ColWidth(1) = 2500 .ColWidth(2) = 1500

.TextMatrix(0, 0) = "ID" .TextMatrix(0, 1) = "Account Title" .TextMatrix(0, 2) = "Account Type"

.RowHeight(0) = 400

.ColAlignmentFixed(0) = 4 .ColAlignmentFixed(1) = 4 .ColAlignmentFixed(2) = 4

End With

End Sub

Private Sub TxtName_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then fgSale.SetFocus Else KeyAscii = 0 Exit Sub End If

End Sub

Public Sub CheckStock_n_Price() 'Checking Available Stock

'Opening Stock Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Qty from Product_Openings where ProdId = " & Val(fgSale.TextMatrix(fgSale.Row, 5)) & "", Con, adOpenStatic, adLockOptimistic OpQty = Val(RS(0))

'Purchases Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(Qty) from Purchase_Detail where ProdId = " & Val(fgSale.TextMatrix(fgSale.Row, 5)) & " GROUP By AcId", Con, adOpenStatic, adLockOptimistic PurQty = Val(RS(0))

'Sales Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(Qty) from Sale_Detail where ProdId = " & Val(fgSale.TextMatrix(fgSale.Row, 5)) & " Group By AcId", Con, adOpenStatic, adLockOptimistic SaleQty = Val(RS(0))

'Stock Stock = Val(OpQty) + Val(PurQty) - Val(SaleQty)

lblstock.Caption = "Available Stock : " & Val(Stock) 'Getting Product Price Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select SalePrice from Accounts where AcId = " & Val(fgSale.TextMatrix(fgSale.Row, 5)) & "", Con, adOpenStatic, adLockOptimistic

fgSale.TextMatrix(fgSale.Row, 3) = Val(RS(0))

End Sub

Public Sub FindRecord() mSqlQry = "Select * from Sale_Main Where SaleId = " & Val(txtFindId) & ""

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open mSqlQry, Con, adOpenStatic, adLockOptimistic If RS.RecordCount <= 0 Then MsgBox "No sale found with this ID", vbCritical, "Message.." txtFindId.SetFocus Exit Sub Else ShowFoundData End If

End Sub

Public Sub ShowFoundData() 'Getting data from Salechase

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open "SELECT SaleId, SaleDate, TotalAmount from Sale_Main Where SaleId = " & Val(txtFindId) & "", Con, adOpenStatic, adLockOptimistic

If RS.EOF = True Then Exit Sub End If

txtId.Text = Val(RS(0)) Dtp1.Value = RS(1) RS.Close

'Getting Supplier Data Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "SELECT Accounts.AcId, Accounts.AcTitle, Sale_Detail.SaleId FROM Accounts INNER JOIN Sale_Detail ON Accounts.AcId = Sale_Detail.AcId where SaleId = " & Val(txtId) & "", Con, adOpenStatic, adLockOptimistic TxtAcCode.Text = Val(RS(0)) TxtName.Text = RS(1)

'Getting data from Sale_Detail Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

mSqlQry = "SELECT * from ViewSale where SaleId = " & Val(txtId) & ""

RS.Open mSqlQry, Con, adOpenStatic, adLockOptimistic

If RS.RecordCount <= 0 Then Exit Sub End If

fgSale.Rows = 2 fgSale.Row = 1

For rCount = 1 To RS.RecordCount fgSale.TextMatrix(fgSale.Row, 1) = RS(0) fgSale.TextMatrix(fgSale.Row, 2) = Val(RS(1)) fgSale.TextMatrix(fgSale.Row, 3) = Val(RS(2)) 'Prod Name 'Qty 'Price

fgSale.TextMatrix(fgSale.Row, 4) = Val(RS(1)) * Val(RS(2)) 'Amount fgSale.TextMatrix(fgSale.Row, 5) = Val(RS(3)) 'Prod Code

fgSale.Rows = fgSale.Rows + 1 fgSale.Row = fgSale.Row + 1

RS.MoveNext Next

picFind.Visible = False Dtp1.SetFocus

End Sub

Public Sub MouseNormalOnLbl() 'Commands Lable lbl(0).ForeColor = vbWhite lbl(0).Font.Underline = False

lbl(1).ForeColor = vbWhite lbl(1).Font.Underline = False

lbl(2).ForeColor = vbWhite lbl(2).Font.Underline = False

lbl(3).ForeColor = vbWhite

lbl(3).Font.Underline = False

lbl(4).ForeColor = vbWhite lbl(4).Font.Underline = False

lbl(5).ForeColor = vbWhite lbl(5).Font.Underline = False

'Navigation Label lblnav(0).ForeColor = vbWhite lblnav(0).Font.Underline = False

lblnav(1).ForeColor = vbWhite lblnav(1).Font.Underline = False

lblnav(2).ForeColor = vbWhite lblnav(2).Font.Underline = False

lblnav(3).ForeColor = vbWhite lblnav(3).Font.Underline = False

End Sub

Public Sub GetAvgCostUpdate() 'Getting Avg Price on Updating the existing task Dim myRow As Integer For myRow = 1 To fgSale.Rows - 2 Set RsMisc = New ADODB.Recordset If RsMisc.State = 1 Then RsMisc.Close RsMisc.Open "Select PurAvg,ProdId from Avg_Cost where ProdId = " & Val(fgSale.TextMatrix(myRow, 5)) & "", Con, adOpenStatic, adLockOptimistic If IsNull(RsMisc(0)) Then fgSale.TextMatrix(myRow, 6) = 0 Else fgSale.TextMatrix(myRow, 6) = Val(RsMisc(0)) End If

Next End Sub

6. frmTransaction.frm
This form creates the interface for the function of creating transaction entries, i.e. credit and debit.

Coding:
Dim Duplicate As Boolean Dim RowSelect As Integer Dim rCount As Integer

Dim mSqlQry As String Dim TransactionId As Single Dim TranMainCode As Single

Private Sub lbl_Click(Index As Integer) Select Case Index Case 0 'New

'Clearing all controls for New Data Clear Me fgTransaction.Clear

GridSetting

Call AutoId

Dtp1.SetFocus Dtp1.Value = Now

Modes True, False, Me

'Lock Navigation LockNav Me

Case 1

'Save

Dim FgTransactionRow As Integer

'Checking Data to Save If Val(fgTransaction.Rows) < 3 Then MsgBox "No data to save", vbInformation, "Message" Exit Sub End If

'Validation for Equal Balances of Debit and Credit Side If Not Val(txtDebit) = Val(txtCredit) Then MsgBox "Debit and Credit sides should be equal", vbCritical, "Message" Exit Sub End If

'If New Transaction If lbl(0).Enabled = False Then

'Getting Maximum Code for Transaction Main

MaxNumber "TransId", "Max_Codes" TranMainCode = Val(MaxNmbr)

TransactionRef = "Voucher-" & Val(txtId)

'Inserting Data to TransactionMain Table

Con.Execute "insert into Transaction_Main (TransId,TransDate,TransType,Posted,TransRef) values (" & Val(txtId) & ", '" & Format(Dtp1.Value, "mm/dd/yyyy") & "' , '" & TransactionType & "' ,'" & "N" & "', '" & TransactionRef & "')"

'----------------------------- Inserting to Transaction Detail ----------------------------

For FgTransactionRow = 1 To fgTransaction.Rows - 2

'Getting Maximum Code for transaction_Detail MaxNumber "TransDetId", "Max_Codes" TransactionId = Val(MaxNmbr) mdescript = fgTransaction.TextMatrix(FgTransactionRow, 2) + " V/No " & Val(txtId) Con.Execute "Insert into Transaction_Detail (TranDetId, TranId, AcId, Descript, DrAmount, CrAmount) values (" & Val(TransactionId) & ", " & Val(txtId) & ", " & Val(fgTransaction.TextMatrix(FgTransactionRow, 5)) & ", '" & mdescript & "', " & Val(fgTransaction.TextMatrix(FgTransactionRow, 3)) & ", " & Val(fgTransaction.TextMatrix(FgTransactionRow, 4)) & ")"

'Updating MaxCode for Transaction Detail

UpdateMaxNumber "TransDetId", Val(TransactionId)

Next

'Updating Transaction Main Id UpdateMaxNumber "TransId", Val(txtId)

MsgBox "Record saved", vbInformation, "Done" lbl_Click (2)

Else 'If existing record TranMainCode = Val(txtId)

'Deleting old records from TransactionMain and Transaction Detail Con.Execute "Delete from Transaction_Detail where TranId = " & Val(txtId) & "" Con.Execute "Delete from Transaction_Main where TransId = " & Val(txtId) & ""

'Checking Data to Save If Val(fgTransaction.Rows) < 3 Then MsgBox "No data to save", vbInformation, "Message" Exit Sub End If

'Validation for Equal Balances of Debit and Credit Side If Not Val(txtDebit) = Val(txtCredit) Then MsgBox "Debit and Credit sides should be equal", vbCritical, "Message" Exit Sub End If

'Inserting Data to TransactionMain Table

Con.Execute "insert into Transaction_Main (TransId,TransDate, TransType, Posted,TransRef) values (" & Val(txtId) & ", '" & Format(Dtp1.Value, "mm/dd/yyyy") & "' , '" & TransactionType & "' ,'" & "N" & "', '" & TransactionRef & "')"

'----------------------------- Inserting to Transaction Detail ----------------------------

For FgTransactionRow = 1 To fgTransaction.Rows - 2

'Getting Maximum Code for transaction_Detail MaxNumber "TransDetId", "Max_Codes" TransactionId = Val(MaxNmbr) mdescript = fgTransaction.TextMatrix(FgTransactionRow, 2) + " V/No " & Val(txtId) Con.Execute "Insert into Transaction_Detail (TranDetId, TranId, AcId, Descript, DrAmount, CrAmount) values (" & Val(TransactionId) & ", " & Val(txtId) & ", " & Val(fgTransaction.TextMatrix(FgTransactionRow, 5)) & ", '" & mdescript & "', " &

Val(fgTransaction.TextMatrix(FgTransactionRow, 3)) & ", " & Val(fgTransaction.TextMatrix(FgTransactionRow, 4)) & ")"

'Updating MaxCode for Transaction Detail UpdateMaxNumber "TransDetId", Val(TransactionId)

Next

MsgBox "Record updated", vbInformation, "Done" lbl_Click (2)

End If

Case 2 Clear Me

'Cancel

'UnLock Navigation UnLockNav Me

fgTransaction.Clear

GridSetting

Call ExistData

Modes False, True, Me

Dtp1.SetFocus

If RsNAV.RecordCount <= 0 Then Exit Sub Else RsNAV.Requery RsNAV.MoveFirst End If

Case 3

'Delete If MsgBox("Do you want to delete this Complete Voucher?", vbQuestion +

vbYesNo, "Delete Voucher") = vbYes Then If MsgBox("System will be unable to recover the loss data. Continue ?", vbQuestion + vbYesNo, "Delete Voucher") = vbYes Then 'Deleting data Con.Execute "Delete from transaction_Detail where TranId = " & Val(txtId) & "" Con.Execute "Delete from transaction_Main where TransId = " & Val(txtId) & "" MsgBox "Voucher Deleted", vbInformation, "Message" lbl_Click (2)

End If End If

Case 4 picFind.Visible = True optId.Value = 1 txtFindId.SetFocus

'Find

Case 5 Unload Me

'Exit

End Select

End Sub

Private Sub lblnav_Click(Index As Integer) Select Case Index

Case 0

'Move First

On Error Resume Next RsNAV.MoveFirst

If RsNAV.BOF = True Then MsgBox "First Record", vbInformation, "Message" RsNAV.MoveFirst Exit Sub Else Call NAVData End If

Case 1

'Move previous

On Error Resume Next RsNAV.MovePrevious

If RsNAV.BOF = True Then MsgBox "First Record", vbInformation, "Message" RsNAV.MoveFirst Else Call NAVData End If

Case 2

'Move Next

On Error Resume Next RsNAV.MoveNext

If RsNAV.EOF = True Then MsgBox "Last Record", vbInformation, "Message" RsNAV.MoveLast Else Call NAVData End If

Case 3

'Move last

On Error Resume Next RsNAV.MoveLast

If RsNAV.EOF = True Then MsgBox "Last Record", vbInformation, "Message" RsNAV.MoveLast Else Call NAVData End If

End Select

End Sub

Private Sub lblnav_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Select Case Index Case 0, 1, 2, 3 MouseOver lblnav(Index) End Select

End Sub

Private Sub Image_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) MouseNormalOnLbl End Sub

Private Sub lbl_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Select Case Index Case 0, 1, 2, 3, 4, 5 MouseOver lbl(Index)

End Select

End Sub

Private Sub cmdFind_Click() If txtFindId.Text = "" Or Val(txtFindId) = 0 Then MsgBox "Enter Transaction ID", vbCritical, "Message.." txtFindId.SetFocus txtFindId.Text = "" Exit Sub End If

Call FindRecord

End Sub

Private Sub cmdFindCancel_Click() picFind.Visible = False Dtp1.SetFocus End Sub

Private Sub Dtp1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then fgTransaction.SetFocus

End If End Sub

Private Sub fgTransaction_Click() RowSelect = fgTransaction.RowSel End Sub

Private Sub fgTransaction_KeyDown(KeyCode As Integer, Shift As Integer) 'If CTRL + SPACE is pressed If fgTransaction.Col = 1 Then If KeyCode = 32 And Shift = 2 Then PicSrchGrid.Visible = True TxtGrdSrch.Text = ""

FillGridAccounts SetGridAccounts

MshSearch.Col = 0 MshSearch.Row = 1 MshSearch.SetFocus End If End If

'Delete Row from Grid If KeyCode = vbKeyDelete Then

If fgTransaction.Rows > 2 And fgTransaction.TextMatrix(fgTransaction.Row, 1) <> "" Then If MsgBox("Do you want to delete this line>", vbQuestion + vbYesNo, "Delete Line") = vbYes Then txtDebit.Text = Val(txtDebit) - Val(fgTransaction.TextMatrix(fgTransaction.Row, 3)) txtCredit.Text = Val(txtCredit) - Val(fgTransaction.TextMatrix(fgTransaction.Row, 4))

fgTransaction.RemoveItem RowSelect End If

Else MsgBox "Blank or Last line can not be deleted", vbCritical, "Message " Exit Sub End If

End If End Sub

Private Sub fgTransaction_KeyPress(KeyAscii As Integer) EditGrid fgTransaction, KeyAscii End Sub

Private Sub fgTransaction_LeaveCell() '========================================= W O R K I N G ==============================

Dim RowNum As Integer Dim mDebit As Single Dim mCredit As Single

Select Case fgTransaction.Col

Case 1 txtDebit.Text = "" txtCredit.Text = "" For RowNum = 1 To fgTransaction.Rows - 1 mDebit = Val(mDebit) + Val(fgTransaction.TextMatrix(RowNum, 3)) mCredit = Val(mCredit) + Val(fgTransaction.TextMatrix(RowNum, 4)) Next

txtDebit.Text = mDebit txtCredit.Text = mCredit

End Select

End Sub

Private Sub Form_Load()

'Setting up flexgrid data Call GridSetting

'Calling Exist Data Call ExistData

'Calling Data for navigation Set RsNAV = New ADODB.Recordset If RsNAV.State = 1 Then RsNAV.Close RsNAV.Open "Select * from Transaction_Main Where TransType = '" & "Voucher" & "' Order By TransId", Con, adOpenStatic, adLockOptimistic

'Defining Transaction Type TransactionType = "Voucher"

End Sub

Private Sub Form_Resize() Me.Left = 3600 Me.Top = 1400

End Sub

Public Sub GridSetting() 'Setting of Transaction Grid With fgTransaction

.ColWidth(0) = 250 .ColWidth(1) = 2500 .ColWidth(2) = 4400 .ColWidth(3) = 1475 .ColWidth(4) = 1475 .ColWidth(5) = 0 .ColWidth(6) = 0

.RowHeight(0) = 400

.Rows = 2

.TextMatrix(0, 1) = "Account Name" .TextMatrix(0, 2) = "Description" .TextMatrix(0, 3) = "Debit"

.TextMatrix(0, 4) = "Credit"

.ColAlignmentFixed(1) = 4 .ColAlignmentFixed(2) = 4 .ColAlignmentFixed(3) = 4 .ColAlignmentFixed(4) = 4

End With End Sub

Public Sub SetGridAccounts() 'Setting of Search Grid With MshSearch .ColWidth(1) = 2500 .ColWidth(2) = 1500

.TextMatrix(0, 0) = "ID" .TextMatrix(0, 1) = "Account Title" .TextMatrix(0, 2) = "Account Type"

.RowHeight(0) = 400

.ColAlignmentFixed(0) = 4

.ColAlignmentFixed(1) = 4 .ColAlignmentFixed(2) = 4

End With

End Sub

Public Sub FillGridAccounts() 'Filling all Accounts Data in Search grid SQLQry = "Select AcId, AcTitle, AcType from ViewHeadWise"

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open SQLQry, Con, adOpenStatic, adLockReadOnly

Set MshSearch.DataSource = RS End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) MouseNormalOnLbl End Sub

Private Sub txtFindId_KeyPress(KeyAscii As Integer) ONU KeyAscii, txtFindId End Sub

Private Sub TxtGrdSrch_Change() Call SearchRecord End Sub Public Sub SearchRecord() 'Filling the Search grid with Critarial Data

Dim SearchedRowCount As Integer

If PicSrchGrid.Visible = True Then

MshSearch.Rows = 2 MshSearch.Row = 0

SearchedRowCount = 0

SQLQry = "Select AcId, AcTitle, AcType from ViewHeadWise where AcTitle Like '" & TxtGrdSrch.Text & "%'"

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open SQLQry, Con, adOpenStatic, adLockReadOnly

If RS.RecordCount <= 0 Then MshSearch.Clear

With MshSearch .TextMatrix(0, 0) = "ID" .TextMatrix(0, 1) = "Account Title" .TextMatrix(0, 2) = "Account Type" End With

MshSearch.Rows = 2 Exit Sub End If

For SearchedRowCount = 1 To RS.RecordCount

If SearchedRowCount >= MshSearch.Rows - 1 Then MshSearch.Rows = MshSearch.Rows + 1 MshSearch.Row = MshSearch.Row + 1 End If

MshSearch.TextMatrix(SearchedRowCount, 0) = RS(0) MshSearch.TextMatrix(SearchedRowCount, 1) = RS(1) MshSearch.TextMatrix(SearchedRowCount, 2) = RS(2)

RS.MoveNext Next

MshSearch.Col = 0 MshSearch.Row = 0 MshSearch.ColAlignment(0) = 3 End If

End Sub

Private Sub MshSearch_DblClick() If MshSearch.Row = 0 Then Exit Sub End If

'Checking for duplicate entry in grid Call CheckDuplicate

If Duplicate = True Then Exit Sub End If

fgTransaction.TextMatrix(fgTransaction.Row, 1) = MshSearch.TextMatrix(MshSearch.Row, 1) fgTransaction.TextMatrix(fgTransaction.Row, 5) = MshSearch.TextMatrix(MshSearch.Row, 0)

PicSrchGrid.Visible = False fgTransaction.Col = 1 fgTransaction.SetFocus End Sub

Public Sub CheckDuplicate() Dim dRow As Integer

For dRow = 1 To fgTransaction.Rows - 2 If fgTransaction.TextMatrix(dRow, 5) = MshSearch.TextMatrix(MshSearch.Row, 0) Then MsgBox "Account Title aleready selected", vbInformation, "Message" Duplicate = True Exit Sub Else Duplicate = False

End If Next

End Sub

Private Sub MshSearch_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then MshSearch_DblClick End If

If KeyAscii = 27 Then PicSrchGrid.Visible = False fgTransaction.SetFocus Exit Sub End If

If KeyAscii = 8 Then If TxtGrdSrch.Text <> "" Then TxtGrdSrch.Text = Left$(TxtGrdSrch.Text, (Len(TxtGrdSrch.Text) - 1)) ElseIf KeyAscii = 13 Then KeyAscii = 0 Else TxtGrdSrch.Text = TxtGrdSrch.Text + Chr$(KeyAscii)

End If

End Sub

Private Sub TxtGrdSrch_KeyPress(KeyAscii As Integer) If KeyAscii = 27 Then PicSrchGrid.Visible = False fgTransaction.SetFocus Exit Sub End If End Sub

Public Sub ExistData()

'Getting data from Purchase Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open "SELECT TransId, TransDate, TransType from Transaction_Main Where TransType = '" & "Voucher" & "'", Con, adOpenStatic, adLockOptimistic

If RS.EOF = True Then Exit Sub End If

txtId.Text = Val(RS(0)) Dtp1.Value = RS(1) RS.Close

'Getting data from TransactionDetail Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

mSqlQry = "SELECT Accounts.AcTitle, Transaction_Detail.Descript, Transaction_Detail.DrAmount, Transaction_Detail.CrAmount, Accounts.AcId, Transaction_Detail.TranDetId, Transaction_Main.TransId" & _ " FROM Transaction_Main INNER JOIN (Accounts INNER JOIN Transaction_Detail ON Accounts.AcId = Transaction_Detail.AcId) ON Transaction_Main.TransId = Transaction_Detail.TranId" & _ " WHERE Transaction_Main.TransId = " & Val(txtId) & ""

RS.Open mSqlQry, Con, adOpenStatic, adLockOptimistic

If RS.RecordCount <= 0 Then Exit Sub End If

fgTransaction.Rows = 2

fgTransaction.Row = 1

For rCount = 1 To RS.RecordCount fgTransaction.TextMatrix(fgTransaction.Row, 1) = RS(0) fgTransaction.TextMatrix(fgTransaction.Row, 2) = RS(1) fgTransaction.TextMatrix(fgTransaction.Row, 3) = RS(2) fgTransaction.TextMatrix(fgTransaction.Row, 4) = RS(3) fgTransaction.TextMatrix(fgTransaction.Row, 5) = RS(4)

txtDebit.Text = Val(txtDebit) + Val(RS(2)) txtCredit.Text = Val(txtCredit) + Val(RS(3))

fgTransaction.Rows = fgTransaction.Rows + 1 fgTransaction.Row = fgTransaction.Row + 1

RS.MoveNext Next

End Sub

Private Sub PicFirst_Click() On Error Resume Next RsNAV.MoveFirst

lblnav.Caption = "1"

If RsNAV.BOF = True Then MsgBox "First Record", vbInformation, "Message" RsNAV.MoveFirst Exit Sub Else Call NAVData End If End Sub

Private Sub PicLast_Click() On Error Resume Next RsNAV.MoveLast lblnav.Caption = Val(RsNAV.RecordCount)

If RsNAV.EOF = True Then MsgBox "Last Record", vbInformation, "Message" RsNAV.MoveLast Else Call NAVData End If

End Sub

Private Sub PicNext_Click() On Error Resume Next RsNAV.MoveNext

lblnav.Caption = Val(lblnav) + 1

If RsNAV.EOF = True Then lblnav.Caption = Val(lblnav) - 1 MsgBox "Last Record", vbInformation, "Message" RsNAV.MoveLast Else Call NAVData End If End Sub

Private Sub PicPrev_Click() On Error Resume Next RsNAV.MovePrevious

lblnav.Caption = Val(lblnav) - 1

If RsNAV.BOF = True Then lblnav.Caption = Val(lblnav) + 1 MsgBox "First Record", vbInformation, "Message" RsNAV.MoveFirst Else Call NAVData End If

End Sub

Public Sub NAVData()

'Getting data from Purchase

txtId.Text = Val(RsNAV(0)) Dtp1.Value = RsNAV(1)

'Getting data from TransactionDetail Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

mSqlQry = "SELECT Accounts.AcTitle, Transaction_Detail.Descript, Transaction_Detail.DrAmount, Transaction_Detail.CrAmount, Accounts.AcId, Transaction_Detail.TranDetId, Transaction_Main.TransId" & _ " FROM Transaction_Main INNER JOIN (Accounts INNER JOIN Transaction_Detail ON Accounts.AcId = Transaction_Detail.AcId) ON Transaction_Main.TransId = Transaction_Detail.TranId" & _ " WHERE Transaction_Main.TransId = " & Val(txtId) & ""

RS.Open mSqlQry, Con, adOpenStatic, adLockOptimistic

If RS.RecordCount <= 0 Then Exit Sub End If

fgTransaction.Rows = 2 fgTransaction.Row = 1

txtDebit.Text = "" txtCredit.Text = ""

For rCount = 1 To RS.RecordCount fgTransaction.TextMatrix(fgTransaction.Row, 1) = RS(0) fgTransaction.TextMatrix(fgTransaction.Row, 2) = RS(1) fgTransaction.TextMatrix(fgTransaction.Row, 3) = RS(2) fgTransaction.TextMatrix(fgTransaction.Row, 4) = RS(3)

fgTransaction.TextMatrix(fgTransaction.Row, 5) = RS(4)

txtDebit.Text = Val(txtDebit) + Val(RS(2)) txtCredit.Text = Val(txtCredit) + Val(RS(3))

fgTransaction.Rows = fgTransaction.Rows + 1 fgTransaction.Row = fgTransaction.Row + 1

RS.MoveNext Next

End Sub

Public Sub AutoId() 'Calling MaxNumber function to get Auto Id for the record MaxNumber "TransId", "Max_Codes" txtId.Text = Val(MaxNmbr) End Sub

Public Sub FindRecord() mSqlQry = "Select * from Transaction_Main Where TransType = '" & "Voucher" & "' and TransId = " & Val(txtFindId) & ""

Set RS = New ADODB.Recordset

If RS.State = 1 Then RS.Close RS.Open mSqlQry, Con, adOpenStatic, adLockOptimistic If RS.RecordCount <= 0 Then MsgBox "No transaction found with this ID", vbCritical, "Message.." txtFindId.SetFocus Exit Sub Else ShowFoundData End If

End Sub

Public Sub ShowFoundData() 'Getting data from TransactionMain Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open "Select * from Transaction_Main Where TransType = '" & "Voucher" & "' and TransId = " & Val(txtFindId) & "", Con, adOpenStatic, adLockOptimistic

If RS.EOF = True Then Exit Sub End If

txtId.Text = Val(RS(0)) Dtp1.Value = RS(1) RS.Close

'Getting data from TransactionDetail Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

mSqlQry = "SELECT Accounts.AcTitle, Transaction_Detail.Descript, Transaction_Detail.DrAmount, Transaction_Detail.CrAmount, Accounts.AcId, Transaction_Detail.TranDetId, Transaction_Main.TransId" & _ " FROM Transaction_Main INNER JOIN (Accounts INNER JOIN Transaction_Detail ON Accounts.AcId = Transaction_Detail.AcId) ON Transaction_Main.TransId = Transaction_Detail.TranId" & _ " WHERE Transaction_Main.TransId = " & Val(txtId) & ""

RS.Open mSqlQry, Con, adOpenStatic, adLockOptimistic

If RS.RecordCount <= 0 Then Exit Sub End If

fgTransaction.Rows = 2

fgTransaction.Row = 1

For rCount = 1 To RS.RecordCount fgTransaction.TextMatrix(fgTransaction.Row, 1) = RS(0) fgTransaction.TextMatrix(fgTransaction.Row, 2) = RS(1) fgTransaction.TextMatrix(fgTransaction.Row, 3) = RS(2) fgTransaction.TextMatrix(fgTransaction.Row, 4) = RS(3) fgTransaction.TextMatrix(fgTransaction.Row, 5) = RS(4)

txtDebit.Text = Val(txtDebit) + Val(RS(2)) txtCredit.Text = Val(txtCredit) + Val(RS(3))

fgTransaction.Rows = fgTransaction.Rows + 1 fgTransaction.Row = fgTransaction.Row + 1

RS.MoveNext Next

picFind.Visible = False Dtp1.SetFocus

End Sub Public Sub MouseNormalOnLbl()

'Commands Lable lbl(0).ForeColor = vbWhite lbl(0).Font.Underline = False

lbl(1).ForeColor = vbWhite lbl(1).Font.Underline = False

lbl(2).ForeColor = vbWhite lbl(2).Font.Underline = False

lbl(3).ForeColor = vbWhite lbl(3).Font.Underline = False

lbl(4).ForeColor = vbWhite lbl(4).Font.Underline = False

lbl(5).ForeColor = vbWhite lbl(5).Font.Underline = False

'Navigation Label lblnav(0).ForeColor = vbWhite lblnav(0).Font.Underline = False

lblnav(1).ForeColor = vbWhite lblnav(1).Font.Underline = False

lblnav(2).ForeColor = vbWhite lblnav(2).Font.Underline = False

lblnav(3).ForeColor = vbWhite lblnav(3).Font.Underline = False

End Sub

7. frmReport.frm
This form creates the interface for the generation of various reports of purchase, sales, accounts, stocks, income statement etc. depending upon the criterion of categorization and date chosen.

Coding:
Dim nodbb As Node Dim VRun As String '-----------------------------Dim RsLov As ADODB.Recordset Dim a As Single Dim DrBal As Double Dim CrBal As Double Dim mDateQry As String 'Variable For Loop 'Variable for Debit Balance 'Variable for Credit Balance 'Variable for storing BETWEEN DATES Query

Dim OpBal As Double Dim MaxId As Double Dim DtFrom As Date Dim DtTo As Date

'Difference between Total DR and Total CR for Opening 'Id for Ledger Report 'Date for COG (FROM) 'Date for COG (TO)

'-------------------------------

Public Sub cmdExit_Click() If PicSrchGrid.Visible = True Then PicSrchGrid.Visible = False Exit Sub End If

On Error Resume Next Unload Me On Error Resume Next End Sub

Private Sub CMDexit_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) CmdExit.Font.Bold = True End Sub Private Sub CMdexit_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) '' Shape1(6).BackColor = &H568C73

End Sub

Private Sub CMDexit_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) CmdExit.Font.Bold = False End Sub

Private Sub CmdLovCancel2_Click() Select Case VRun Case "Accounts Status" TxtLookup1.SetFocus Case "Daily Collection List" TxtDate.SetFocus End Select PicSrchGrid.Visible = False If RsLov.State = 1 Then RsLov.Close End Sub Private Sub CmdLovOK2_Click() Select Case VRun Case "Accounts Ledger" If MshSearch.Rows <= 1 Then CmdLovCancel2_Click: Exit Sub TxtLookupCode.Text = MshSearch.TextMatrix(MshSearch.Row, 0) TxtLookup.Text = MshSearch.TextMatrix(MshSearch.Row, 1)

Case "Account Wise Receipts" If MshSearch.Rows <= 1 Then CmdLovCancel2_Click: Exit Sub

TxtLookupCode.Text = MshSearch.TextMatrix(MshSearch.Row, 1) TxtLookup.Text = MshSearch.TextMatrix(MshSearch.Row, 0)

Case "Account Wise Payments" If MshSearch.Rows <= 1 Then CmdLovCancel2_Click: Exit Sub TxtLookupCode.Text = MshSearch.TextMatrix(MshSearch.Row, 1) TxtLookup.Text = MshSearch.TextMatrix(MshSearch.Row, 0)

Case "Supplier Wise Purchase History" If MshSearch.Rows <= 1 Then CmdLovCancel2_Click: Exit Sub TxtLookupCode.Text = MshSearch.TextMatrix(MshSearch.Row, 0) TxtLookup.Text = MshSearch.TextMatrix(MshSearch.Row, 1)

Case "Product Wise Purchase History" If MshSearch.Rows <= 1 Then CmdLovCancel2_Click: Exit Sub TxtLookupCode.Text = MshSearch.TextMatrix(MshSearch.Row, 0) TxtLookup.Text = MshSearch.TextMatrix(MshSearch.Row, 1)

Case "Product Wise Sale History" If MshSearch.Rows <= 1 Then CmdLovCancel2_Click: Exit Sub TxtLookupCode.Text = MshSearch.TextMatrix(MshSearch.Row, 0) TxtLookup.Text = MshSearch.TextMatrix(MshSearch.Row, 1)

Case "Customer Wise Sale History" If MshSearch.Rows <= 1 Then CmdLovCancel2_Click: Exit Sub TxtLookupCode.Text = MshSearch.TextMatrix(MshSearch.Row, 0) TxtLookup.Text = MshSearch.TextMatrix(MshSearch.Row, 1)

Case "Month Wise Account Status" If MshSearch.Rows <= 1 Then CmdLovCancel2_Click: Exit Sub TxtLookupCode.Text = MshSearch.TextMatrix(MshSearch.Row, 1) TxtLookup.Text = MshSearch.TextMatrix(MshSearch.Row, 0) TxtLookup.SetFocus

Case "Accounts Status" If MshSearch.Rows <= 1 Then CmdLovCancel2_Click: Exit Sub TxtLookupCode1.Text = MshSearch.TextMatrix(MshSearch.Row, 0) TxtLookup1.Text = MshSearch.TextMatrix(MshSearch.Row, 1)

Case "Receivable" If MshSearch.Rows <= 1 Then CmdLovCancel2_Click: Exit Sub TxtLookupCode1.Text = MshSearch.TextMatrix(MshSearch.Row, 0) TxtLookup1.Text = MshSearch.TextMatrix(MshSearch.Row, 1)

Case "Payable" If MshSearch.Rows <= 1 Then CmdLovCancel2_Click: Exit Sub

TxtLookupCode1.Text = MshSearch.TextMatrix(MshSearch.Row, 0) TxtLookup1.Text = MshSearch.TextMatrix(MshSearch.Row, 1)

End Select CmdLovCancel2_Click End Sub Private Sub CmdRun_Click()

If PicDateBw.Enabled = True Then If TxtFrom.Value > TxtTo.Value Then MsgBox "From Date value must be less than To Date value", vbInformation, "Date error" TxtFrom.SetFocus Exit Sub End If End If

DtFrom = TxtFrom.Value DtTo = TxtTo.Value

mDateQry = " BETWEEN #" & DtFrom & "# And #" & DtTo & "#"

Select Case VRun Case "Accounts Status"

If TxtLookupCode1.Text = "" Then

If TxtLookup.Text = "ALL" Then StrQry = "Select AcId, AcTitle, AcType, Balance from ViewAccountStatus Where AcType NOT IN ('Product') order By AcId" dataRepAccountStatus.Show vbModal

Else StrQry = "Select AcId, AcTitle, AcType, Balance from ViewAccountStatus where AcType = '" & TxtLookup.Text & "' order By AcId" dataRepAccountStatus.Show vbModal

End If

Else StrQry = "Select AcId, AcTitle, AcType, Balance from ViewAccountStatus where AcType = '" & TxtLookup.Text & "' and AcId = " & Val(TxtLookupCode1) & " order By AcId" dataRepAccountStatus.Show vbModal

End If

Case "Accounts Ledger" Call AccLedger

Case "Stock Status" Call ProductStock

Case "Reorder Status" Call ReOrderStatus

Case "Products To Reorder" Call ProductsToReorder

'' '' '' '' '' ''

Case "Receivable" If TxtLookupCode1.Text = "" Then

If TxtLookup.Text = "ALL" Then StrQry = "Select Code,Remarks from Accounts order By code" RepBalances.Sections("ReportHeader").Controls("LblRepType").Caption = "ALL

BALANCE"

'' ''

Else StrQry = "Select Code,Remarks from Accounts where AccType = '" &

TxtLookup.Text & "' order By code" '' RepBalances.Sections("ReportHeader").Controls("LblRepType").Caption =

UCase(TxtLookup.Text) & " BALANCE" '' '' '' '' Else StrQry = "Select Code,Remarks from Accounts where AccType = '" & End If

TxtLookup.Text & "' and Code = " & Val(TxtLookupCode1) & " order By code" '' '' '' Call BalanceRep End If

Case "Date Wise Purchase History" Call PurchaseHistoryByDate

Case "Supplier Wise Purchase History" Call PurchaseHistoryBySupplier

Case "Product Wise Purchase History" Call PurchaseHistoryByProduct

Case "Date Wise Sale History" Call DateWiseSaleHistory

Case "Customer Wise Sale History" Call CustomerWiseSaleHistory

Case "Product Wise Sale History" Call SaleHistoryByProduct

Case "Product Price List" Call ProductPriceList

Case "Trial Balance" Call TrialBalanceData DataRepTrialBalance.Show vbModal

Case "Balance Sheet"

If TxtLookup.Text = "" Then MsgBox "Select Month using Ctrl+Space", vbCritical, "Message" TxtLookup.SetFocus Exit Sub End If

If TxtLookup1.Text = "" Then MsgBox "Enter YEAR for Balance Sheet", vbCritical, "Message..." TxtLookup1.SetFocus Exit Sub End If

Call MonthDates

'' ''

Case "Stock Adjustment" Call StockAdjustment

'' '' '' '' '' ''

Case "Payable" If TxtLookupCode1.Text = "" Then

If TxtLookup.Text = "ALL" Then StrQry = "Select Code,Remarks from Accounts order By code" RepBalances.Sections("ReportHeader").Controls("LblRepType").Caption = "ALL

BALANCE" '' '' Else StrQry = "Select Code,Remarks from Accounts where AccType = '" &

TxtLookup.Text & "' order By code"

''

RepBalances.Sections("ReportHeader").Controls("LblRepType").Caption =

UCase(TxtLookup.Text) & " BALANCE" '' '' '' '' Else StrQry = "Select Code,Remarks from Accounts where AccType = '" & End If

TxtLookup.Text & "' and Code = " & Val(TxtLookupCode1) & " order By code" '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' If TxtLookup1.Text = "" Then MsgBox "Enter YEAR for COG", vbCritical, "Message..." TxtLookup1.SetFocus Exit Sub End If If TxtLookup.Text = "" Then MsgBox "Select Month using Ctrl+Space", vbCritical, "Message" TxtLookup.SetFocus Exit Sub End If Case "Cost Of Goods Sold" Call BalanceRep End If

'' '' Call MonthDates

Case "Income Statement" Call IncomeStatData

'' '' '' '' '' '' ''

Case "Date Wise Receipts" If DeRep.rsCashReceipts.State = 1 Then DeRep.rsCashReceipts.Close

DeRep.CashReceipts TxtFrom.Value, TxtTo.Value RepCashReceipts.Sections("ReportHeader").Controls("LblDate").Caption = "From : " & " & "To : " & TxtTo.Value

TxtFrom.Value & " '' '' '' '' ''

Load RepCashReceipts RepCashReceipts.Show 1

Case "Account Wise Receipts" If DeRep.rsCashReceiptsByAccount.State = 1 Then

DeRep.rsCashReceiptsByAccount.Close '' '' ''

'' ''

DeRep.CashReceiptsByAccount TxtFrom.Value, TxtTo.Value, Val(TxtLookupCode) RepCashReceiptsByAccount.Sections("ReportHeader").Controls("LblDate").Caption = " & "To : " & TxtTo.Value

"From : " & TxtFrom.Value & " '' '' '' '' '' '' '' '' '' ''

Load RepCashReceiptsByAccount RepCashReceiptsByAccount.Show 1

Case "Date Wise Payments" If DeRep.rsCashPayment.State = 1 Then DeRep.rsCashPayment.Close

DeRep.CashPayment TxtFrom.Value, TxtTo.Value RepCashPayments.Sections("ReportHeader").Controls("LblDate").Caption = "From : " " & "To : " & TxtTo.Value

& TxtFrom.Value & " '' '' '' '' ''

Load RepCashPayments RepCashPayments.Show 1

Case "Account Wise Payments" If DeRep.rsCashPaymentByAccount.State = 1 Then

DeRep.rsCashPaymentByAccount.Close '' '' '' '' DeRep.CashPaymentByAccount TxtFrom.Value, TxtTo.Value, Val(TxtLookupCode)

''

RepCashReceiptsByAccount.Sections("ReportHeader").Controls("LblDate").Caption = " & "To : " & TxtTo.Value

"From : " & TxtFrom.Value & " '' '' '' '' '' '' '' '' '' ''

Load RepCashPaymentByAccount RepCashPaymentByAccount.Show 1

Case "Department Vehicles" If DeRep.rsVehicleList.State = 1 Then DeRep.rsVehicleList.Close

DeRep.VehicleList Val(TxtLookupCode) RepVehicles.Sections("Section4").Controls("LblDept").Caption = "Department : " &

TxtLookup.Text '' '' '' '' '' '' '' '' '' '' '' If Not IsNumeric(TxtLookup) Then Case "Issues" If TxtLookup.Text = "" Then MsgBox "Enter meter number", vbInformation, "Message" TxtLookup.SetFocus Exit Sub End If Load RepVehicles RepVehicles.Show 1

'' '' '' '' '' '' '' '' '' '' ''

MsgBox "Enter digits only", vbInformation, "Message" TxtLookup.SetFocus Exit Sub End If

If DeRep.rsMeterIssue.State = 1 Then DeRep.rsMeterIssue.Close

DeRep.MeterIssue TxtFrom.Value, TxtTo.Value, Val(TxtLookup) RepMeterIssue.Sections("ReportHeader").Controls("LblDate").Caption = "From : " & " & "To : " & TxtTo.Value

TxtFrom.Value & " '' '' '' '' '' '' '' '' '' '' '' '' Case "Reading"

Load RepMeterIssue RepMeterIssue.Show 1

If TxtLookup.Text = "" Then MsgBox "Enter meter number", vbInformation, "Message" TxtLookup.SetFocus Exit Sub End If

If Not IsNumeric(TxtLookup) Then MsgBox "Enter digits only", vbInformation, "Message"

'' '' '' '' '' '' '' '' '' ''

TxtLookup.SetFocus Exit Sub End If

If DeRep.rsMeterReading.State = 1 Then DeRep.rsMeterReading.Close

DeRep.MeterReading TxtFrom.Value, TxtTo.Value, Val(TxtLookup) RepMeterReading.Sections("ReportHeader").Controls("LblDate").Caption = "From : " & " & "To : " & TxtTo.Value

TxtFrom.Value & " ''

RepMeterReading.Sections("ReportHeader").Controls("LblMeterCode").Caption = "Meter

Number : " & Val(TxtLookup) '' '' '' '' '' '' '' '' '' '' '' DeRep.MeterStock Case "Meter Stock" Call MeterStock If DeRep.rsMeterStock.State = 1 Then DeRep.rsMeterStock.Close Load RepMeterReading RepMeterReading.Show 1

'' ''

DeRep.rsMeterStock.Requery RepMeterStock.Sections("ReportHeader").Controls("LblDate").Caption = Format(Now,

"dd/mmm/yyyy - HH:MM") '' '' '' '' '' '' '' '' '' '' DeRep.ReminderMain TxtLookup.Text Load RepReminderByCode RepReminderByCode.Show 1 Case "Code Wise Remaining" If DeRep.rsReminderMain.State = 1 Then DeRep.rsReminderMain.Close Load RepMeterStock RepMeterStock.Show 1

'' '' '' '' ''

Call COGData Call IncomeStatement Call BalanceSheet Load RepIncomeStatement RepIncomeStatement.Show

End Select End Sub

Private Sub CmdRun_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) CmdRun.Font.Bold = True End Sub Private Sub CmdRun_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) '' Shape1(7).BackColor = &H568C73

End Sub Private Sub CmdRun_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) CmdRun.Font.Bold = False End Sub

Private Sub Command1_Click()

dataRepIncomeStat.Show vbModal

'''''Dim NetSale As Single '''''Dim BegInv As Single '''''Dim Purchase As Single '''''Dim AvblForSale As Single '''''Dim EndingInv As Single '''''Dim COGSold As Single '''''Dim Gross As Single '''''Dim OtherIncome As Single

'''''Dim Expense As Single '''''Dim NetProfit As Single ''''' '''''Dim mDateQry As String ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' "#" ''''' ''''' '''''' NET SALES OF THE DEFINED PERIOD ''''' Set RS = New ADODB.Recordset mDateQry = " BETWEEN #" & FrmRep.TxtFrom.Value & "# And #" & FrmRep.TxtTo.Value & NetSale = 0 BegInv = 0 Purchase = 0 AvblForSale = 0 EndingInv = 0 COGSold = 0 Gross = 0 OtherIncome = 0 Expense = 0 NetProfit = 0

''''' '''''

If RS.State = 1 Then RS.Close RS.Open "Select Sum(TotalAmount) from Sale_Main where SaleDate" & mDateQry, Con,

adOpenStatic, adLockOptimistic ''''' ''''' ''''' ''''' ''''' ''''' '''''' OPENING INVENTORY BEFORE DEFINED PERIOD ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' 'Value of Product Openings Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(Amount), Sum(Qty) from Product_Openings", Con, adOpenStatic, BeforePeriod = " < #" & FrmRep.TxtFrom.Value & "#" Dim ProductOpenings As Single Dim OpQty As Single Dim OpAvgPrice As Single Dim BeforePeriod As String Dim PurValueBefore As Single Dim SalValueBefore As Single If IsNull(RS(0)) Then NetSale = 0 Else NetSale = Val(RS(0)) End If

adLockOptimistic

''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' '''''

If IsNull(RS(0)) Then ProductOpenings = 0 Else ProductOpenings = Val(RS(0)) End If

If IsNull(RS(1)) Then OpQty = 0 Else OpQty = Val(RS(1)) End If

On Error Resume Next OpAvgPrice = Val(RS(0)) / Val(RS(1)) On Error Resume Next

'Value of Purchase before given period Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(TotalAmount) from Purchase_Main where PurDate " &

BeforePeriod, Con, adOpenStatic, adLockOptimistic ''''' ''''' ''''' If IsNull(RS(0)) Then PurValueBefore = 0 Else

''''' ''''' ''''' ''''' ''''' ''''' ''''' '''''

PurValueBefore = Val(RS(0)) End If

'Value of Sale before given period Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(TotalAmount) from Sale_Main where SaleDate " & BeforePeriod,

Con, adOpenStatic, adLockOptimistic ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' '''''' NET PURCHASES OF THE DEFINED PERIOD ''''' ''''' Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close 'Calculating Begining Inventory BegInv = Val(ProductOpenings) + Val(PurValueBefore) - Val(SalValueBefore) If IsNull(RS(0)) Then SalValueBefore = 0 Else SalValueBefore = Val(RS(0)) End If

'''''

RS.Open "Select Sum(TotalAmount) from Purchase_Main where PurDate" & mDateQry,

Con, adOpenStatic, adLockOptimistic ''''' ''''' ''''' ''''' ''''' ''''' '''''' CALCULATING VALUE OF GOODS AVAILABALE FOR SALE ''''' ''''' ''''' '''''' ENDING INVENTORY OF DEFINED PERIOD ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' 'Value of Product Openings 'Taken from Variable PRODUCTOPENINGS AfterPeriod = "#" & FrmRep.TxtTo.Value & "#" Dim AfterPeriod As String Dim PurValueAfter As Single Dim SalValue As Single Dim AvgCost As Single Dim SaleQty As Single AvblForSale = Val(BegInv) + Val(Purchase) If IsNull(RS(0)) Then Purchase = 0 Else Purchase = Val(RS(0)) End If

''''' ''''' ''''' ''''' ''''' 'Value of Purchase till Last Date Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(TotalAmount) from Purchase_Main where PurDate " &

AfterPeriod, Con, adOpenStatic, adLockOptimistic ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' 'Avg Purchase Cost till last date Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "SELECT Sum(Purchase_Detail.Qty) AS TotalQty, If IsNull(RS(0)) Then PurValueAfter = 0 Else PurValueAfter = Val(RS(0)) End If

Purchase_Main.TotalAmount AS TotalAmount, TotalAmount/TotalQty AS Cost FROM Purchase_Detail INNER JOIN Purchase_Main ON Purchase_Detail.PurId = Purchase_Main.PurId GROUP BY Purchase_Main.TotalAmount, Purchase_Detail.Qty where Purchase_Main.PurDate " & AfterPeriod, Con, adOpenStatic, adLockOptimistic ''''' ''''' ''''' ''''' ''''' If Val(Cost) > 0 Then AvgCost = Val(Cost) + Val(OpAvgPrice) / 2 Else AvgCost = Val(OpAvgPrice) End If

''''' ''''' ''''' ''''' ''''' ''''' ''''' Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "SELECT Sale_Main.SaleDate, Sum(Sale_Detail.Qty) AS SumOfQty FROM 'Cost of Sale till Last Date

Sale_Main INNER JOIN Sale_Detail ON Sale_Main.SaleId = Sale_Detail.SaleId GROUP BY Sale_Main.SaleDate, Sale_Detail.Qty HAVING Sale_Main.SaleDate <= " & AfterPeriod, Con, adOpenStatic, adLockOptimistic ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' 'Calculating Ending Inventory EndingInv = Val(ProductOpenings) + Val(PurValueAfter) - Val(SalValue) If Val(EndingInv) < 0 Then EndingInv = 0 End If If IsNull(RS(1)) Then SaleQty = 0 Else SaleQty = Val(RS(1)) SalValue = Val(AvgCost) * Val(SaleQty) End If

'''''' COST OF GOODS SOLD ''''' ''''' '''''' GROSS PROFIT ''''' ''''' Gross = Val(NetSale) - Val(COGSold) COGSold = Val(AvblForSale) - Val(EndingInv)

End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 116 Then CmdRun_Click End If End Sub 'F5

Private Sub Form_KeyPress(KeyAscii As Integer) If KeyAscii = 27 Then cmdExit_Click End If End Sub

Private Sub Form_Load()

Me.Left = Me.Left PicDateBw.Enabled = False PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = False PicLookup.BackColor = vbWhite PicDate.BackColor = vbWhite PicDateBw.BackColor = vbWhite PicCode.BackColor = vbWhite PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite

TxtDate.Day = Day(Date) TxtDate.Month = Month(Date) TxtDate.Year = Year(Date) TxtFrom.Day = Day(Date) TxtFrom.Month = Month(Date) TxtFrom.Year = Year(Date) TxtTo.Day = Day(Date) TxtTo.Month = Month(Date) TxtTo.Year = Year(Date)

Set nodbb = TV.Nodes.Add(, , "Root", "Reports", 3) 'Report

nodbb.Expanded = True ' ==============[PURCHASE]=============== TV.Nodes.Add "Root", tvwChild, "A", "Purchase", 6 TV.Nodes.Add "A", tvwChild, "A1", "Date Wise Purchase History", 1 TV.Nodes.Add "A", tvwChild, "A2", "Supplier Wise Purchase History", 1 TV.Nodes.Add "A", tvwChild, "A3", "Product Wise Purchase History", 1 TV.Nodes.Item("A").Bold = True

'

==============[SALES]=============== TV.Nodes.Add "Root", tvwChild, "B", "Sales", 6 TV.Nodes.Add "B", tvwChild, "B2", "Date Wise Sale History", 1 TV.Nodes.Add "B", tvwChild, "B3", "Customer Wise Sale History", 1 TV.Nodes.Add "B", tvwChild, "B4", "Product Wise Sale History", 1 TV.Nodes.Item("B").Bold = True

'

==============[ACCOUNTS]=============== TV.Nodes.Add "Root", tvwChild, "C", "Accounts", 6 TV.Nodes.Add "C", tvwChild, "C1", "Accounts Status", 1 TV.Nodes.Add "C", tvwChild, "C2", "Accounts Ledger", 1 TV.Nodes.Item("C").Bold = True

'

==============[STOCK]=============== TV.Nodes.Add "Root", tvwChild, "D", "Stock/Product Reports", 6

TV.Nodes.Add "D", tvwChild, "D1", "Stock Status", 1 TV.Nodes.Add "D", tvwChild, "D2", "Product Price List", 1 TV.Nodes.Add "D", tvwChild, "D3", "Reorder Status", 1 TV.Nodes.Add "D", tvwChild, "D4", "Products To Reorder", 1 TV.Nodes.Item("D").Bold = True

'

==============[FINANCIALS]=============== TV.Nodes.Add "Root", tvwChild, "E", "Financial Reports", 6 TV.Nodes.Add "E", tvwChild, "E1", "Trial Balance", 1 TV.Nodes.Add "E", tvwChild, "E2", "Income Statement", 1 TV.Nodes.Item("E").Bold = True

'Assigning values to LISTLOV Call AccountType End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) '' '' Shape1(6).BackColor = &H96BEAE Shape1(7).BackColor = &H96BEAE

End Sub

Private Sub MnuTitle_Click()

End Sub

Private Sub Form_Resize() Me.Left = Me.Left + 1300 End Sub

Private Sub ListLov_Click() TxtLookup.Text = ListLov.Text ListLov.Visible = False

If VRun = "Accounts Status" Then

If TxtLookup.Text = "ALL" Then PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite Else PicLookup1.Enabled = True PicLookup1.BackColor = &HC0C0C0 TxtLookup1.SetFocus End If

End If

End Sub

Private Sub ListLov_KeyPress(KeyAscii As Integer) TxtLookup.Text = ListLov.Text ListLov.Visible = False

If VRun = "Accounts Status" Then

If TxtLookup.Text = "ALL" Then PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite

Else

PicLookup1.Enabled = True PicLookup1.BackColor = &HC0C0C0 TxtLookup1.SetFocus

End If End If

End Sub

Private Sub MshSearch_DblClick() CmdLovOK2_Click TxtLookup.SetFocus End Sub

Private Sub MshSearch_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then CmdLovOK2_Click TxtLookup.SetFocus End If If KeyAscii = 27 Then CmdLovCancel2_Click End If

If KeyAscii = 8 Then If TxtGrdSrch.Text <> "" Then TxtGrdSrch.Text = Left$(TxtGrdSrch.Text, (Len(TxtGrdSrch.Text) - 1)) ElseIf KeyAscii = 13 Then KeyAscii = 0 Else TxtGrdSrch.Text = TxtGrdSrch.Text + Chr$(KeyAscii) End If

End Sub

Private Sub TV_NodeClick(ByVal Node As MSComctlLib.Node) '====================Purchase Report Start========================== If Node = "Reports" Then VRun = "" TxtLookup = "" TxtLookupCode = "" TxtLookup1 = "" TxtLookupCode1 = "" TxtCode = "" TxtToCode = "" PicDateBw.Enabled = False PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = False PicLookup1.Enabled = False PicLookup.BackColor = vbWhite PicLookup1.BackColor = vbWhite PicLookup.BackColor = vbWhite PicDate.BackColor = vbWhite PicDateBw.BackColor = vbWhite

PicCode.BackColor = vbWhite

'----------------------------------------------------------'--------------Accounts Reports------------------ElseIf Node = "Accounts Status" Then VRun = "Accounts Status" ListLov.Clear Call AccountType

PicDateBw.Enabled = False PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = True PicLookup.BackColor = &HC0C0C0 PicDate.BackColor = vbWhite PicDateBw.BackColor = vbWhite PicCode.BackColor = vbWhite TxtLookup.SetFocus PicLookup1.Enabled = True PicLookup1.BackColor = &HC0C0C0

ElseIf Node = "Trial Balance" Then

VRun = "Trial Balance" PicDateBw.Enabled = False PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = False PicLookup.BackColor = vbWhite PicDate.BackColor = vbWhite PicDateBw.BackColor = vbWhite PicCode.BackColor = vbWhite PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite

ElseIf Node = "Receivable" Then VRun = "Receivable" ListLov.Clear Call AccountType

PicDateBw.Enabled = False PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = True PicLookup.BackColor = &HC0C0C0 PicDate.BackColor = vbWhite

PicDateBw.BackColor = vbWhite PicCode.BackColor = vbWhite PicLookup1.Enabled = True PicLookup1.BackColor = &HC0C0C0 TxtLookup.SetFocus

ElseIf Node = "Payable" Then VRun = "Payable" ListLov.Clear Call AccountType

PicDateBw.Enabled = False PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = True PicLookup.BackColor = &HC0C0C0 PicDate.BackColor = vbWhite PicDateBw.BackColor = vbWhite PicCode.BackColor = vbWhite PicLookup1.Enabled = True PicLookup1.BackColor = &HC0C0C0 TxtLookup.SetFocus

ElseIf Node = "Accounts Ledger" Then VRun = "Accounts Ledger" ListLov.Clear Call AccountType

PicDateBw.Enabled = True PicDateBw.BackColor = &HC0C0C0 PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = True PicLookup.BackColor = &HC0C0C0 PicLookup1.BackColor = vbWhite PicLookup1.Enabled = False PicDate.BackColor = vbWhite TxtFrom.SetFocus

ElseIf Node = "Income Statement" Then VRun = "Income Statement" PicDateBw.Enabled = True PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = False PicLookup.BackColor = vbWhite

PicDate.BackColor = vbWhite PicDateBw.BackColor = &HC0C0C0 PicCode.BackColor = vbWhite PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite TxtFrom.SetFocus

ElseIf Node = "Stock Status" Then VRun = "Stock Status"

PicDateBw.Enabled = False PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = False PicLookup.BackColor = vbWhite PicDate.BackColor = vbWhite PicDateBw.BackColor = vbWhite PicCode.BackColor = vbWhite PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite

ElseIf Node = "Reorder Status" Then

VRun = "Reorder Status"

PicDateBw.Enabled = False PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = False PicLookup.BackColor = vbWhite PicDate.BackColor = vbWhite PicDateBw.BackColor = vbWhite PicCode.BackColor = vbWhite PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite

ElseIf Node = "Products To Reorder" Then VRun = "Products To Reorder"

PicDateBw.Enabled = False PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = False PicLookup.BackColor = vbWhite PicDate.BackColor = vbWhite PicDateBw.BackColor = vbWhite

PicCode.BackColor = vbWhite PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite

ElseIf Node = "Daily Cash Book" Then VRun = "Daily Cash Book"

PicDateBw.Enabled = True PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = False PicLookup.BackColor = vbWhite PicDate.BackColor = vbWhite PicDateBw.BackColor = &HC0C0C0 PicCode.BackColor = vbWhite TxtFrom.SetFocus PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite

ElseIf Node = "Date Wise Purchase History" Then VRun = "Date Wise Purchase History"

PicDateBw.Enabled = True PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = False PicLookup.BackColor = vbWhite PicDate.BackColor = vbWhite PicDateBw.BackColor = &HC0C0C0 PicCode.BackColor = vbWhite TxtFrom.SetFocus PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite

ElseIf Node = "Supplier Wise Purchase History" Then VRun = "Supplier Wise Purchase History"

PicDateBw.Enabled = True PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = True PicLookup.BackColor = &HC0C0C0 PicDate.BackColor = vbWhite PicDateBw.BackColor = &HC0C0C0

PicCode.BackColor = vbWhite TxtFrom.SetFocus PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite

ElseIf Node = "Product Wise Purchase History" Then VRun = "Product Wise Purchase History"

PicDateBw.Enabled = True PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = True PicLookup.BackColor = &HC0C0C0 PicDate.BackColor = vbWhite PicDateBw.BackColor = &HC0C0C0 PicCode.BackColor = vbWhite TxtFrom.SetFocus PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite

ElseIf Node = "Product Wise Sale History" Then VRun = "Product Wise Sale History"

PicDateBw.Enabled = True PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = True PicLookup.BackColor = &HC0C0C0 PicDate.BackColor = vbWhite PicDateBw.BackColor = &HC0C0C0 PicCode.BackColor = vbWhite TxtFrom.SetFocus PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite

ElseIf Node = "Sales Invoice" Then VRun = "Sales Invoice"

PicDateBw.Enabled = False PicCode.Enabled = True PicDate.Enabled = False PicLookup.Enabled = False PicLookup.BackColor = vbWhite PicDate.BackColor = vbWhite

PicDateBw.BackColor = vbWhite PicCode.BackColor = &HC0C0C0 PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite TxtCode.SetFocus

ElseIf Node = "Date Wise Sale History" Then VRun = "Date Wise Sale History"

PicDateBw.Enabled = True PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = False PicLookup.BackColor = vbWhite PicDate.BackColor = vbWhite PicDateBw.BackColor = &HC0C0C0 PicCode.BackColor = vbWhite TxtFrom.SetFocus PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite

ElseIf Node = "Customer Wise Sale History" Then VRun = "Customer Wise Sale History"

PicDateBw.Enabled = True PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = True PicLookup.BackColor = &HC0C0C0 PicDate.BackColor = vbWhite PicDateBw.BackColor = &HC0C0C0 PicCode.BackColor = vbWhite TxtFrom.SetFocus PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite

ElseIf Node = "Vehicle Wise Sale History" Then VRun = "Vehicle Wise Sale History"

PicDateBw.Enabled = True PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = True PicLookup.BackColor = &HC0C0C0 PicDate.BackColor = vbWhite

PicDateBw.BackColor = &HC0C0C0 PicCode.BackColor = vbWhite TxtFrom.SetFocus PicLookup1.Enabled = False PicLookup1.BackColor = vbWhite

ElseIf Node = "Product Price List" Then VRun = "Product Price List"

PicDateBw.Enabled = False PicDateBw.BackColor = vbWhite PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = False PicLookup.BackColor = vbWhite PicLookup1.BackColor = vbWhite PicLookup1.Enabled = False PicDate.BackColor = vbWhite

ElseIf Node = "Stock Adjustment" Then VRun = "Stock Adjustment"

PicDateBw.Enabled = True PicDateBw.BackColor = &HC0C0C0 PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = True PicLookup.BackColor = &HC0C0C0 PicLookup1.BackColor = vbWhite PicLookup1.Enabled = False PicDate.BackColor = vbWhite TxtFrom.SetFocus

'RECEIPTS ElseIf Node = "Date Wise Receipts" Then VRun = "Date Wise Receipts"

PicDateBw.Enabled = True PicDateBw.BackColor = &HC0C0C0 PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = False PicLookup.BackColor = vbWhite PicLookup1.BackColor = vbWhite PicLookup1.Enabled = False

PicDate.BackColor = vbWhite TxtFrom.SetFocus

ElseIf Node = "Account Wise Receipts" Then VRun = "Account Wise Receipts"

PicDateBw.Enabled = True PicDateBw.BackColor = &HC0C0C0 PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = True PicLookup.BackColor = &HC0C0C0 PicLookup1.BackColor = vbWhite PicLookup1.Enabled = False PicDate.BackColor = vbWhite TxtFrom.SetFocus

'PAYMENTS ElseIf Node = "Date Wise Payments" Then VRun = "Date Wise Payments"

PicDateBw.Enabled = True PicDateBw.BackColor = &HC0C0C0

PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = False PicLookup.BackColor = vbWhite PicLookup1.BackColor = vbWhite PicLookup1.Enabled = False PicDate.BackColor = vbWhite TxtFrom.SetFocus

ElseIf Node = "Account Wise Payments" Then VRun = "Account Wise Payments"

PicDateBw.Enabled = True PicDateBw.BackColor = &HC0C0C0 PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = True PicLookup.BackColor = &HC0C0C0 PicLookup1.BackColor = vbWhite PicLookup1.Enabled = False PicDate.BackColor = vbWhite TxtFrom.SetFocus

'VEHICLES ElseIf Node = "Department Vehicles" Then VRun = "Department Vehicles"

PicDateBw.Enabled = False PicDateBw.BackColor = vbWhite PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = True PicLookup.BackColor = &HC0C0C0 PicLookup1.BackColor = vbWhite PicLookup1.Enabled = False PicDate.BackColor = vbWhite TxtLookup.SetFocus

'METER ElseIf Node = "Issues" Then VRun = "Issues"

PicDateBw.Enabled = True PicDateBw.BackColor = &HC0C0C0 PicCode.Enabled = False PicDate.Enabled = False

PicLookup.Enabled = True PicLookup.BackColor = &HC0C0C0 PicLookup1.BackColor = vbWhite PicLookup1.Enabled = False PicDate.BackColor = vbWhite TxtFrom.SetFocus

ElseIf Node = "Reading" Then VRun = "Reading"

PicDateBw.Enabled = True PicDateBw.BackColor = &HC0C0C0 PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = True PicLookup.BackColor = &HC0C0C0 PicLookup1.BackColor = vbWhite PicLookup1.Enabled = False PicDate.BackColor = vbWhite TxtFrom.SetFocus

ElseIf Node = "Meter Stock" Then VRun = "Meter Stock"

PicDateBw.Enabled = False PicDateBw.BackColor = vbWhite PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = False PicLookup.BackColor = vbWhite PicLookup1.BackColor = vbWhite PicLookup1.Enabled = False PicDate.BackColor = vbWhite

ElseIf Node = "Code Wise Remaining" Then VRun = "Code Wise Remaining"

PicDateBw.Enabled = False PicDateBw.BackColor = vbWhite PicCode.Enabled = False PicDate.Enabled = False PicLookup.Enabled = True PicLookup.BackColor = &HC0C0C0 PicLookup1.BackColor = vbWhite PicLookup1.Enabled = False

PicDate.BackColor = vbWhite TxtLookup.SetFocus

End If TxtLookup = "" TxtLookupCode = "" TxtLookup1 = "" TxtLookupCode1 = "" TxtCode = "" TxtToCode = "" End Sub

Private Sub TxtCode_GotFocus() ' SelectAll TxtLookup

End Sub

Private Sub TxtCode_KeyPress(KeyAscii As Integer) Cng KeyAscii End Sub

Private Sub TxtFrom_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then TxtTo.SetFocus End If

End Sub

Private Sub TxtGrdSrch_Change() Call SearchRecord End Sub

Private Sub TxtLookup_Change() If TxtLookup.Text = "" Then TxtLookupCode.Text = "" End If End Sub

Private Sub TxtLookup_GotFocus() '' SelectAll TxtLookup

End Sub Private Sub TxtLookup_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 32 And Shift = 2 Then

Select Case VRun Case "Accounts Status" ListLov.Clear ListLov.Visible = True ListLov.SetFocus Call AccountType

Case "Accounts Ledger" PicSrchGrid.Visible = True TxtGrdSrch.Text = "" ListLov.Clear Call AccountsData

Case "Account Wise Receipts" PicSrchGrid.Visible = True TxtGrdSrch.Text = "" ListLov.Clear Call AccountsData

Case "Account Wise Payments" PicSrchGrid.Visible = True TxtGrdSrch.Text = "" ListLov.Clear

Call AccountsData

Case "Department Vehicles" PicSrchGrid.Visible = True TxtGrdSrch.Text = "" ListLov.Clear Call AccountsData

Case "Receivable" ListLov.Clear ListLov.Visible = True Call AccountType

Case "Payable" ListLov.Clear ListLov.Visible = True Call AccountType

Case "Income Statement" ListLov.Visible = True Call MonthNames ListLov.SetFocus

Case "Supplier Wise Purchase History" PicSrchGrid.Visible = True TxtGrdSrch.Text = "" ListLov.Clear Call AccountsData

Case "Product Wise Purchase History" PicSrchGrid.Visible = True TxtGrdSrch.Text = "" ListLov.Clear Call AccountsData

Case "Product Wise Sale History" PicSrchGrid.Visible = True TxtGrdSrch.Text = "" ListLov.Clear Call AccountsData

Case "Customer Wise Sale History" PicSrchGrid.Visible = True TxtGrdSrch.Text = "" ListLov.Clear

Call AccountsData

End Select End If End Sub

''Public Sub StockStatus() '' '' '' '' '' '' '' Connect.Cn.Execute "delete from RepStockStat" DataEnvironment2.ProductsStatus Val(TxtLookupCode) For a = 1 To DataEnvironment2.rsProductsStatus.RecordCount If RsDTrans.State = 1 Then RsDTrans.Close RsDTrans.Open "Select sum(purchasedetail.qtys)from purchasedetail inner join

purchaseheader on purchasedetail.purcode=purchaseheader.purcode where productCode= " & Val(DataEnvironment2.rsProductsStatus("ProductCode")) & " and purchaseheader.purdate< '" & Format(TxtFrom.Value, "DD-MMM-YY") & " 00:00:00.000'", Connect.Cn, adOpenStatic, adLockReadOnly '' '' '' '' '' '' If IsNull(RsDTrans(0)) = False Then DrSum = RsDTrans(0) Else DrSum = 0 End If RsDTrans.Close

'' ''

If RsDTrans.State = 1 Then RsDTrans.Close RsDTrans.Open "Select sum(salesdetail.qty)from salesdetail inner join salesheader on

salesdetail.salcode=salesheader.salcode where productCode= " & Val(DataEnvironment2.rsProductsStatus("ProductCode")) & " and salesheader.saldate< '" & Format(TxtFrom.Value, "DD-MMM-YY") & " 00:00:00.000'", Connect.Cn, adOpenStatic, adLockReadOnly '' '' '' '' '' '' '' '' If IsNull(RsDTrans(0)) = False Then CrSum = RsDTrans(0) Else CrSum = 0 End If RsDTrans.Close OpBal = DrSum - CrSum RsDTrans.Open "Select sum(purchasedetail.qtys),sum(purchasedetail.bonus) from

purchasedetail inner join purchaseheader on purchasedetail.purcode=purchaseheader.purcode where purchasedetail.productCode= " & Val(DataEnvironment2.rsProductsStatus("ProductCode")) & " and purchaseheader.purdate between '" & Format(TxtFrom.Value, "DD-MMM-YY") & " 00:00:00.000'" & " And '" & Format(TxtTo.Value, "DD-MMM-YY") & " 00:00:00.000'", Connect.Cn, adOpenStatic, adLockReadOnly '' '' '' '' '' '' '' If IsNull(RsDTrans(0)) = False Then Rec = RsDTrans(0) TBonus = RsDTrans(1) Else Rec = 0 TBonus = 0 End If

'' ''

RsDTrans.Close RsDTrans.Open "Select sum(salesdetail.qty)from salesdetail inner join salesheader on

salesdetail.salcode=salesheader.salcode where salesdetail.productCode= " & Val(DataEnvironment2.rsProductsStatus("ProductCode")) & " and salesheader.saldate between '" & Format(TxtFrom.Value, "DD-MMM-YY") & " 00:00:00.000'" & " And '" & Format(TxtTo.Value, "DD-MMM-YY") & " 00:00:00.000'", Connect.Cn, adOpenStatic, adLockReadOnly '' '' '' '' '' '' '' '' If IsNull(RsDTrans(0)) = False Then TSale = RsDTrans(0) Else TSale = 0 End If RsDTrans.Close If RsDTrans.State = 1 Then RsDTrans.Close RsDTrans.Open "Select sum(salesdetail.qty)from salesdetail inner join salesheader on

salesdetail.salcode=salesheader.salcode where productCode= " & Val(DataEnvironment2.rsProductsStatus("ProductCode")) & " and salesheader.saldate= '" & Format(TxtTo.Value, "DD-MMM-YY") & " 00:00:00.000'", Connect.Cn, adOpenStatic, adLockReadOnly '' '' '' '' '' '' '' '' If IsNull(RsDTrans(0)) = False Then DSale = RsDTrans(0) Else DSale = 0 End If RsDTrans.Close '**************** insert into RepStockStat VSQL = "INSERT INTO RepStockStat VALUES ("

'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''' '' '' ''

VSQL = VSQL & a & ",'" & DataEnvironment2.rsProductsStatus("ProductName") VSQL = VSQL & "','" & DataEnvironment2.rsProductsStatus("Packing") VSQL = VSQL & "'," & DataEnvironment2.rsProductsStatus("PrincipalCode") VSQL = VSQL & "," & DataEnvironment2.rsProductsStatus("Rate") VSQL = VSQL & "," & OpBal VSQL = VSQL & "," & Rec VSQL = VSQL & "," & OpBal + Rec VSQL = VSQL & "," & DSale VSQL = VSQL & "," & TSale VSQL = VSQL & "," & TSale * DataEnvironment2.rsProductsStatus("Rate") VSQL = VSQL & "," & DataEnvironment2.rsProductsStatus("Claim") VSQL = VSQL & "," & DataEnvironment2.rsProductsStatus("Bonus") VSQL = VSQL & "," & DataEnvironment2.rsProductsStatus("CurBal") VSQL = VSQL & "," & DataEnvironment2.rsProductsStatus("TotalAmount") VSQL = VSQL & ",'" & TxtTo.Value VSQL = VSQL & "'," & TBonus & ")" Cn.Execute VSQL MsgBox DataEnvironment2.rsProductsStatus(1) & ", " & OpBal DataEnvironment2.rsProductsStatus.MoveNext Next DataEnvironment2.rsProductsStatus.Close

''End Sub Private Sub TxtLookup_KeyPress(KeyAscii As Integer)

''

MMisFuncion.SpaceNotAllow KeyAscii, TxtLookup

End Sub

Private Sub TxtLookup_LostFocus() If TxtLookup.Text = "ALL" Then TxtLookup1.Text = "" End If End Sub

Private Sub TxtLookup1_Change() If TxtLookup1.Text = "" Then TxtLookupCode1.Text = "" End If

End Sub

Private Sub TxtLookup1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 32 And Shift = 2 Then Select Case VRun

Case "Accounts Status" PicSrchGrid.Visible = True Call AccountsData

MshSearch.SetFocus

End Select End If End Sub

Private Sub TxtLookup1_KeyPress(KeyAscii As Integer) If KeyAscii = 32 Then KeyAscii = 0 End If

End Sub

Private Sub TxtTo_KeyDown(KeyCode As Integer, Shift As Integer) On Error Resume Next If KeyCode = 13 Then TxtLookup.SetFocus On Error Resume Next

End If End Sub

Private Sub TxttoCode_GotFocus()

'

SelectAll TxtLookup

End Sub Public Sub BalanceRep() 'FAROOQ ''''''Deleting old records ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''''Opening Accounts Table ''''' ''''' ''''' ''''' ''''' ''''' ''''''Opening record set for Debit Transactions ''''' ''''' Set RsDrt = New ADODB.Recordset If RsDrt.State = 1 Then RsDrt.Close Set RsAcc = New ADODB.Recordset If RsAcc.State = 1 Then RsAcc.Close RsAcc.Open StrQry, Db, adOpenStatic, adLockPessimistic Dim Vc1 As Single For Vc1 = 1 To RsAcc.RecordCount RepBalances.Refresh Db.Execute "Delete from TblRep" Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Delete * from TblRep", Db, adOpenStatic, adLockOptimistic

'''''

RsDrt.Open "Select Sum(Amount) from DRTGLT where AccountCode = " &

RsAcc.Fields("Code"), Db, adOpenStatic, adLockPessimistic ''''' ''''' ''''' ''''' ''''' ''''' ''''''Opening record set for Credit Transactions ''''' ''''' ''''' Set RsCrt = New ADODB.Recordset If RsCrt.State = 1 Then RsCrt.Close RsCrt.Open "Select Sum(Amount) from CRTGLT where AccountCode = " & If IsNull(RsDrt(0)) Then DrBal = 0 Else DrBal = Val(RsDrt(0)) End If

RsAcc.Fields("Code"), Db, adOpenStatic, adLockPessimistic ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''''Generating Difference between Total Debit and Total Credit ''''' ''''' ''''' Dim VBal As Double VBal = Val(DrBal) - Val(CrBal) If IsNull(RsCrt(0)) Then CrBal = 0 Else CrBal = Val(RsCrt(0)) End If

''''''Inserting data into TblRep ''''' Db.Execute "INSERT INTO TblRep (Code, Descrip, TotalDr, TotalCr, Balance, DrCr) VALUES ("

& Val(RsAcc("Code")) & ", '" & RsAcc("Name") & "', " & Val(DrBal) & ", " & Val(CrBal) & ", " & Val(VBal) & ", '" & "-" & "' )" ''''' '''''''''Updating Record to know that is the balacne DR or CR '''''''' '''''''' '''''''' '''''''' '''''''' '''''''' '''''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' ''''' On Error Resume Next RsAcc.MoveNext Next DrBal = 0 CrBal = 0 VBal = 0 If Val(VBal) > 0 Then Db.Execute "UPDATE TblRep SET DrCr = '" & "Dr" & "' WHERE TotalDr > 0" ElseIf Val(VBal) < 0 Then Db.Execute "UPDATE TblRep SET DrCr = '" & "Cr" & "' WHERE TotalCr > 0" Else Db.Execute "UPDATE TblRep SET DrCr = '" & "--" & "' WHERE BALANCE = 0" End If

''''' ''''' ''''' ''''' ''''' ''''''' ''''' '''''

If DeRep.rsBalances.State = 1 Then DeRep.rsBalances.Close

DeRep.Balances

DeRep.rsBalances.Requery

On Error Resume Next

End Sub Public Sub AccountType() Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "SELECT DISTINCT AcType FROM Accounts Where AcType not in ('Product')", Con, adOpenStatic, adLockReadOnly For a = 1 To RsLov.RecordCount ListLov.AddItem RsLov(0) RsLov.MoveNext Next ListLov.AddItem "ALL" End Sub

''Public Sub TBal()

'''Deleting old records '' '' '''Opening Accounts Table '' '' '' '' '' '' '' '''Opening record set for Debit Transactions '' '' '' Set RsDrt = New ADODB.Recordset If RsDrt.State = 1 Then RsDrt.Close RsDrt.Open "Select Sum(Amount) from DRt where AccountCode = " & Dim Vc1 As Single For Vc1 = 1 To RsAcc.RecordCount Set RsAcc = New ADODB.Recordset If RsAcc.State = 1 Then RsAcc.Close RsAcc.Open "Select Code,Remarks from Accounts", Cn, adOpenStatic, adLockPessimistic Cn.Execute "Delete from TblTrial"

RsAcc.Fields("Code"), Cn, adOpenStatic, adLockPessimistic '' '' '' '' '' '' '''Opening record set for Credit Transactions '' Set RsCrt = New ADODB.Recordset If IsNull(RsDrt(0)) Then DrBal = 0 Else DrBal = RsDrt(0) End If

'' ''

If RsCrt.State = 1 Then RsCrt.Close RsCrt.Open "Select Sum(Amount) from CRt where AccountCode = " &

RsAcc.Fields("Code"), Cn, adOpenStatic, adLockPessimistic '' '' '' '' '' '' '' '''Generating Difference between Total Debit and Total Credit for each account '' '' '' '' Cn.Execute "INSERT INTO TblTrial (Code, Descrip, Debit, Credit,Id) VALUES (" & Dim VBal As Double VBal = Val(DrBal) - Val(CrBal) If IsNull(RsCrt(0)) Then CrBal = 0 Else CrBal = RsCrt(0) End If

Val(RsAcc("Code")) & ", '" & RsAcc("Remarks") & "',0,0, " & Val(Vc1) & ")" '' '''Updating Record to know that is the balacne DR or CR '' '' '' '' & "" '' End If If Val(VBal) > 0 Then Cn.Execute "UPDATE TblTrial SET Debit = " & Val(VBal) & " where Id = " & Val(Vc1) & "" ElseIf Val(VBal) < 0 Then Cn.Execute "UPDATE TblTrial SET Credit = " & Abs(Val(VBal)) & " where Id = " & Val(Vc1)

'' '' '' '' '' '''Getting the difference between Total Debit and Total Credit '' '' '' Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Select sum(Debit),sum(Credit) from TblTrial", Cn, adOpenStatic, VBal = 0 RsAcc.MoveNext Next

adLockReadOnly '' '' '' VBal = Val(RsLov(0)) - Val(RsLov(1)) If Val(VBal) > 0 Then RepTrial.Sections("Section5").Controls("LblDif").Caption = "Dr. Diff: " &

Format(Val(VBal), "##,#.00") '' '' ElseIf Val(VBal) < 0 Then RepTrial.Sections("Section5").Controls("LblDif").Caption = "Cr. Diff: " &

Format(Val(VBal), "##,#.00") '' '' '' '' '''Showing Report '' '' If De1.rsRepTrial.State = 1 Then De1.rsRepTrial.Close RepTrial.Refresh Else RepTrial.Sections("Section5").Controls("LblDif").Caption = Format(0, "##,#.00") End If

'' ''

Load RepTrial RepTrial.Show 1

''End Sub

Public Sub AccountsData()

Select Case VRun

Case "Accounts Status" SetSearchGrid FillGridAccounts MshSearch.Col = 0 MshSearch.Row = 1 MshSearch.SetFocus

Case "Accounts Ledger" SetSearchGrid FillGridAccounts MshSearch.Col = 0 MshSearch.Row = 1 MshSearch.SetFocus

Case "Account Wise Receipts"

SetSearchGrid FillGridAccounts MshSearch.Col = 0 MshSearch.Row = 1 MshSearch.SetFocus

Case "Account Wise Payments" SetSearchGrid FillGridAccounts MshSearch.Col = 0 MshSearch.Row = 1 MshSearch.SetFocus

Case "Supplier Wise Purchase History" SetSearchGrid FillGridAccounts MshSearch.Col = 0 MshSearch.Row = 1 MshSearch.SetFocus

Case "Product Wise Purchase History" SetSearchGrid FillGridAccounts

MshSearch.Col = 0 MshSearch.Row = 1 MshSearch.SetFocus

Case "Customer Wise Sale History" SetSearchGrid FillGridAccounts MshSearch.Col = 0 MshSearch.Row = 1 MshSearch.SetFocus

Case "Product Wise Sale History" SetSearchGrid FillGridAccounts MshSearch.Col = 0 MshSearch.Row = 1 MshSearch.SetFocus

Case "Month Wise Account Status" Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "SELECT Code,Name FROM Accounts ORDER BY Remarks", Con, adOpenStatic, adLockReadOnly

Set MshSearch.DataSource = RsLov MshSearch.ColWidth(0) = 1000 MshSearch.ColWidth(1) = 4000 MshSearch.SetFocus

Case "Receivable" Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Select Code,Name from Accounts Where AccType = '" & ListLov & "' order By Remarks", Con, adOpenStatic, adLockReadOnly Set MshSearch.DataSource = RsLov PicSrchGrid.Visible = True MshSearch.ColWidth(0) = 1000 MshSearch.ColWidth(1) = 4000 MshSearch.SetFocus

Case "Payable" Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Select Code,Name from Accounts Where AccType = '" & ListLov & "' order By Remarks", Con, adOpenStatic, adLockReadOnly Set MshSearch.DataSource = RsLov PicSrchGrid.Visible = True MshSearch.ColWidth(0) = 1000

MshSearch.ColWidth(1) = 4000 MshSearch.SetFocus

End Select End Sub

Public Sub AccLedger() Dim DtFrom As Date Dim DtTo As Date Dim mBalance As Single Dim DrOpBal As Single Dim CrOpBal As Single Dim DrCr As String Dim RunningBal As Double

DtFrom = TxtFrom.Value DtTo = TxtTo.Value

mDateQry = " BETWEEN #" & DtFrom & "# And #" & DtTo & "#"

'Delete Data from RepAcLedger Con.Execute "Delete * from RepAcLedger"

'Getting Opening Balance for the selected Account Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(DrAmount),Sum(CrAmount) from ViewAccountLedger where TransDate < #" & DtFrom & "# and AcID = " & Val(TxtLookupCode) & "", Con, adOpenStatic, adLockOptimistic 'If result is NULL If IsNull(RS(0)) Or IsNull(RS(1)) Then mBalance = 0 Else mBalance = Val(RS(0)) - Val(RS(1)) End If

'Finding DR/CR/Nill balance If Val(mBalance) > 0 Then DrOpBal = Val(mBalance) CrOpBal = 0 DrCr = "DR" ElseIf Val(mBalance) < 0 Then CrOpBal = Abs(Val(mBalance)) DrOpBal = 0 DrCr = "CR" Else

DrOpBal = 0 CrOpBal = 0 DrCr = "NILL" End If

'Saving Opening Balance in REPACLEDGER Con.Execute "Insert into RepAcLedger Values( " & Val(TxtLookupCode) & ", '" & Format(DtFrom - 1, "dd/mm/yyyy") & "', '" & "Last Balance (C/F)" & "', " & Val(DrOpBal) & ", " & Val(CrOpBal) & ", " & Abs(Val(mBalance)) & ", '" & DrCr & "') "

'Fetching Data into RepAcLedger Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select * from ViewAccountLedger where AcId = " & Val(TxtLookupCode) & " and TransDate " & mDateQry, Con, adOpenStatic, adLockOptimistic RS.Requery

While Not RS.EOF = True RunningBal = Val(mBalance) + Val(RS(4)) - Val(RS(5)) mBalance = RunningBal

'Finding DR/CR/Nill balance If Val(RunningBal) > 0 Then DrCr = "DR"

ElseIf Val(RunningBal) < 0 Then DrCr = "CR" Else DrCr = "NILL" End If

' DR CR balance

AcID drcr

Date

Desc

Con.Execute "Insert into RepAcLedger Values( " & Val(RS(0)) & ", '" & Format(RS(2), "dd/mm/yyyy") & "', '" & RS(3) & "', " & Val(RS(4)) & ", " & Val(RS(5)) & ", " & Val(RunningBal) & ", '" & DrCr & "') " RS.MoveNext Wend

daraRepAcLedger.Show vbModal

End Sub

Public Sub MonthNames() 'List of Months for LOV ListLov.Clear

ListLov.AddItem "January" ListLov.AddItem "February"

ListLov.AddItem "March" ListLov.AddItem "April" ListLov.AddItem "May" ListLov.AddItem "June" ListLov.AddItem "July" ListLov.AddItem "August" ListLov.AddItem "September" ListLov.AddItem "October" ListLov.AddItem "November" ListLov.AddItem "December" End Sub

Public Sub MonthDates() 'Days of Monthts for Calcutaing COG If TxtLookup.Text = "January" Then DtFrom = "01-Jan-" & TxtLookup1.Text DtTo = "31-Jan-" & TxtLookup1.Text

ElseIf TxtLookup.Text = "February" Then DtFrom = "01-Feb-" & TxtLookup1.Text DtTo = "28-Feb-" & TxtLookup1.Text

ElseIf TxtLookup.Text = "March" Then

DtFrom = "01-Mar-" & TxtLookup1.Text DtTo = "31-Mar-" & TxtLookup1.Text

ElseIf TxtLookup.Text = "April" Then DtFrom = "01-Apr-" & TxtLookup1.Text DtTo = "30-Apr-" & TxtLookup1.Text

ElseIf TxtLookup.Text = "May" Then DtFrom = "01-May-" & TxtLookup1.Text DtTo = "31-May-" & TxtLookup1.Text

ElseIf TxtLookup.Text = "June" Then DtFrom = "01-Jun-" & TxtLookup1.Text DtTo = "30-Jun-" & TxtLookup1.Text

ElseIf TxtLookup.Text = "July" Then DtFrom = "01-Jul-" & TxtLookup1.Text DtTo = "31-Jul-" & TxtLookup1.Text

ElseIf TxtLookup.Text = "August" Then DtFrom = "01-Aug-" & TxtLookup1.Text DtTo = "31-Aug-" & TxtLookup1.Text

ElseIf TxtLookup.Text = "September" Then DtFrom = "01-Sep-" & TxtLookup1.Text DtTo = "30-Sep-" & TxtLookup1.Text

ElseIf TxtLookup.Text = "October" Then DtFrom = "01-Oct-" & TxtLookup1.Text DtTo = "31-Oct-" & TxtLookup1.Text

ElseIf TxtLookup.Text = "November" Then DtFrom = "01-Nov-" & TxtLookup1.Text DtTo = "30-Nov-" & TxtLookup1.Text

ElseIf TxtLookup.Text = "December" Then DtFrom = "01-Dec-" & TxtLookup1.Text DtTo = "31-Dec-" & TxtLookup1.Text

End If

End Sub

''Public Sub IncomeStatement() '' TxtFrom.Value = DtFrom

'' '' '' '' ''

TxtTo.Value = DtTo

MDateQry = " BETWEEN '" & TxtFrom.Value & "' And '" & TxtTo.Value & "'"

'''Sales during the given period '' '' '' '' '' Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "SELECT SUM(SaleDetail.TotalAmount) FROM Sale INNER JOIN SaleDetail ON Dim mTotalSales As Double

Sale.Code = SaleDetail.Code INNER JOIN Product ON SaleDetail.ProductCode = Product.Code WHERE Product.Type IN ('Billets/Ingots') and Sale.TDate" & MDateQry, Cn, adOpenStatic, adLockReadOnly '' '' '' '' '' '' '' RepIncomeStatement.Sections("Section2").Controls("LblTotalSale").Caption = If IsNull(RsLov(0)) Then mTotalSales = 0 Else mTotalSales = Val(RsLov(0)) End If

Val(mTotalSales) '' '''Sales Return during the period '' Dim mSaleRet As Double

'' '' '' '' Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "SELECT SUM(SaleDetailR.TotalAmount)FROM SaleR INNER JOIN SaleDetailR

ON SaleR.Code = SaleDetailR.Code INNER JOIN Product ON SaleDetailR.ProductCode = Product.Code WHERE Product.Type IN ('Billets/Ingots') and SaleR.TDate" & MDateQry, Cn, adOpenStatic, adLockReadOnly '' '' '' '' '' '' '' '' '''Sales Discounts during the period '' '' '' '' '' Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "SELECT SUM(Drt.Amount) FROM GLT INNER JOIN DRT ON GLT.Code = Dim mSaleDiscount As Double RepIncomeStatement.Sections("Section2").Controls("LblSaleRet").Caption = Val(mSaleRet) If IsNull(RsLov(0)) Then mSaleRet = 0 Else mSaleRet = Val(RsLov(0)) End If

DRT.Code INNER JOIN Accounts ON DRT.AccountCode = Accounts.Code WHERE (Accounts.AccType IN ('Discount Allowed')) and Glt.Tdate" & MDateQry, Cn, adOpenStatic, adLockReadOnly

''

If IsNull(RsLov(0)) Then

'' '' '' '' '' ''

mSaleDiscount = 0 Else mSaleDiscount = Val(RsLov(0)) End If

RepIncomeStatement.Sections("Section2").Controls("LblDiscount").Caption =

Val(mSaleDiscount) '' '''Calculating NetSales '' '' '' '' '' '''Gross Profit '' '' '' Dim mGrossProfit As Double mGrossProfit = Val(mNetSale) - Val(mCOG) RepIncomeStatement.Sections("Section2").Controls("LblGross").Caption = mNetSale = Val(mTotalSales) - Val(mSaleRet) + Val(mSaleDiscount) RepIncomeStatement.Sections("Section2").Controls("LblNetSale").Caption = Val(mNetSale) Dim mNetSale As Double

Val(mGrossProfit) '' '' '''Operating Expense Report ''

''

StrQry = "SELECT Code, Remarks FROM Accounts WHERE AccType IN ('Opeating Expense')

AND AccType NOT LIKE '%Tax%'" '' '''========================Copying Data to TblRep=========================== '' '''Deleting old records '' '' '' '''Opening Accounts Table '' '' '' '' '' '' '''Opening record set for Debit Transactions '' '' '' Set RsDrt = New ADODB.Recordset If RsDrt.State = 1 Then RsDrt.Close RsDrt.Open "SELECT SUM(DRT.Amount) FROM GLT INNER JOIN DRT ON GLT.Code Set RsAcc = New ADODB.Recordset If RsAcc.State = 1 Then RsAcc.Close RsAcc.Open StrQry, Cn, adOpenStatic, adLockPessimistic Dim Vc1 As Single For Vc1 = 1 To RsAcc.RecordCount Cn.Execute "Delete from TblRep" RepBalances.Refresh

= DRT.Code where DRT.AccountCode = " & RsAcc.Fields("Code") & " and GLT.Tdate" & MDateQry, Cn, adOpenStatic, adLockPessimistic '' '' If IsNull(RsDrt(0)) Then DrBal = 0

'' '' '' ''

Else DrBal = Val(RsDrt(0)) End If

'''Opening record set for Credit Transactions '' '' '' Set RsCrt = New ADODB.Recordset If RsCrt.State = 1 Then RsCrt.Close RsCrt.Open "SELECT SUM(CRT.Amount) FROM GLT INNER JOIN CRT ON GLT.Code

= CRT.Code where CRT.AccountCode = " & RsAcc.Fields("Code") & " and GLT.TDate" & MDateQry, Cn, adOpenStatic, adLockPessimistic '' '' '' '' '' '' '' '''Generating Difference between Total Debit and Total Credit '' '' '' '''Inserting data into TblRep '' Cn.Execute "INSERT INTO TblRep (Code, Descrip,TotalDr, TotalCr, Balance, DrCr) VALUES (" & Dim VBal As Double VBal = Val(DrBal) - Val(CrBal) If IsNull(RsCrt(0)) Then CrBal = 0 Else CrBal = Val(RsCrt(0)) End If

Val(RsAcc("Code")) & ", '" & RsAcc("Remarks") & "', " & Val(DrBal) & ", " & Val(CrBal) & ", " & Abs(Val(VBal)) & ", '" & "-" & "' )"

'' '''Updating Record to know that is the balacne DR or CR '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Select Sum(Balance) from TblRep", Cn, adOpenStatic, adLockReadOnly Dim mTotalOperating As Double RsAcc.MoveNext Next DrBal = 0 CrBal = 0 VBal = 0 If Val(VBal) > 0 Then Cn.Execute "UPDATE TblRep SET DrCr = '" & "Dr" & "' WHERE TotalDr > 0" ElseIf Val(VBal) < 0 Then Cn.Execute "UPDATE TblRep SET DrCr = '" & "Cr" & "' WHERE TotalCr > 0" Else Cn.Execute "UPDATE TblRep SET DrCr = '" & "--" & "' WHERE BALANCE = 0" End If

'' '' '' '' '' '' '' ''

If IsNull(RsLov(0)) Then mTotalOperating = 0 Else mTotalOperating = Val(RsLov(0)) End If

If De1.rsBalances.State = 1 Then De1.rsBalances.Requery

'''========================END Copying Data to TblRep=========================== '' '' RepIncomeStatement.Sections("Section5").Controls("LblTotalOperating").Caption =

Val(mTotalOperating) '''Net Income '' '' '' Dim mNetIncome As Double mNetIncome = Val(mGrossProfit) - Val(mTotalOperating) RepIncomeStatement.Sections("Section5").Controls("LblNetIncome").Caption =

Val(mNetIncome) '' '''Other Income '' '' '' '' Dim mOtherIncome As Double Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "SELECT SUM(CRT.Amount) FROM GLT INNER JOIN CRT ON GLT.Code =

CRT.Code INNER JOIN Accounts ON CRT.AccountCode = Accounts.Code WHERE

Accounts.AccType = 'Other Income' and GLT.Tdate" & MDateQry, Cn, adOpenStatic, adLockReadOnly '' '' '' '' '' '' '' RepIncomeStatement.Sections("Section5").Controls("LblOtherIncome").Caption = If IsNull(RsLov(0)) Then mOtherIncome = 0 Else mOtherIncome = Val(RsLov(0)) End If

Val(mOtherIncome) '''Net Income before tax '' '' '' Dim NetBeforeTax As Double NetBeforeTax = Val(mNetIncome) + Val(mOtherIncome) RepIncomeStatement.Sections("Section5").Controls("LblIncomeBeforeTax").Caption =

Val(NetBeforeTax) '' '''Finding Taxes Amount '' '' '' '' Dim mTaxes As Double Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "SELECT SUM(DRT.Amount) FROM GLT INNER JOIN DRT ON GLT.Code =

DRT.Code INNER JOIN Accounts ON DRT.AccountCode = Accounts.Code WHERE Accounts.AccType like '%Tax%' and GLT.Tdate" & MDateQry, Cn, adOpenStatic, adLockReadOnly '' '' If IsNull(RsLov(0)) Then mTaxes = 0

'' '' '' '' '' ''

Else mTaxes = Val(RsLov(0)) End If

RepIncomeStatement.Sections("Section5").Controls("LblTaxes").Caption = Val(mTaxes)

'''Net Income After Taxes '' '' '' '' NetAfterTax = Val(NetBeforeTax) - Val(mTaxes) RepIncomeStatement.Sections("Section5").Controls("LblIncomeAfterTax").Caption = Dim NetAfterTax As Double

Val(NetAfterTax) '' ''End Sub

''Public Sub BalanceSheet() '''Deleting Old Records '' '' '''Categorized Trial Balance '' '' '' Set RsAcc = New ADODB.Recordset If RsAcc.State = 1 Then RsAcc.Close RsAcc.Open "Select MainHead,Code,Remarks from Accounts Where MainHead in (1,2,3)", Cn.Execute "Delete from TblTrialCat"

Cn, adOpenStatic, adLockReadOnly

'' '' '' '' ''

Dim Vc1 As Single For Vc1 = 1 To RsAcc.RecordCount Set RsAcType = New ADODB.Recordset If RsAcType.State = 1 Then RsAcType.Close RsAcType.Open "Select Code from AccountTypes where Code = " &

Val(RsAcc("MainHead")) & "", Cn, adOpenStatic, adLockReadOnly '' '''Opening record set for Debit Transactions '' '' '' Set RsDrt = New ADODB.Recordset If RsDrt.State = 1 Then RsDrt.Close RsDrt.Open "Select Sum(Amount) from DRt where AccountCode = " &

RsAcc("Code"), Cn, adOpenStatic, adLockPessimistic '' '' '' '' '' '' '''Opening record set for Credit Transactions '' '' '' Set RsCrt = New ADODB.Recordset If RsCrt.State = 1 Then RsCrt.Close RsCrt.Open "Select Sum(Amount) from CRt where AccountCode = " & If IsNull(RsDrt(0)) Then DrBal = 0 Else DrBal = RsDrt(0) End If

RsAcc("Code"), Cn, adOpenStatic, adLockPessimistic '' If IsNull(RsCrt(0)) Then

'' '' '' '' '' ''

CrBal = 0 Else CrBal = RsCrt(0) End If

'''Generating Difference between Total Debit and Total Credit for each account '' '' '' '''Inserting Values into TblTrialCat '' Cn.Execute "INSERT INTO TblTrialCat (MainHead,Code, Descrip, Debit, Credit,Id) VALUES (" Dim VBal As Double VBal = Val(DrBal) - Val(CrBal)

& Val(RsAcType("Code")) & ", " & Val(RsAcc("Code")) & ", '" & RsAcc("Remarks") & "',0,0, " & Val(Vc1) & ")" '' '''Updating Record to know that is the balacne DR or CR '' '' "" '' '' ElseIf Val(VBal) < 0 Then Cn.Execute "UPDATE TblTrialCat SET Credit = " & Abs(Val(VBal)) & " where Id = " & If Val(VBal) > 0 Then Cn.Execute "UPDATE TblTrialCat SET Debit = " & Val(VBal) & " where Id = " & Val(Vc1) &

Val(Vc1) & "" '' '' '' VBal = 0 End If

'' '' ''

RsAcc.MoveNext Next

'''Showing Report '' '' '' '' '' ''End Sub Public Sub ExactRecords() Dim ExactRowCount As Integer If De1.rsTrialCatMain.State = 1 Then De1.rsTrialCatMain.Close RepTrialCat.Refresh Load RepTrialCat RepTrialCat.Show 1

If PicSrchGrid.Visible = True Then

MshSearch.Rows = 2 MshSearch.Row = 1

ExactRowCount = 0

If TxtGrdSrch.Text = "" Then SQLQry = "Select Code, Name, AccType from Accounts where Disable = 0" Else

SQLQry = "Select Code, Name, AccType from Accounts Where Disable = 0 And Name Like '" & TxtGrdSrch.Text & "%'" End If

Set RsSrch = New ADODB.Recordset If RsSrch.State = 1 Then RsSrch.Close RsSrch.Open SQLQry, dB, adOpenStatic, adLockReadOnly

If RsSrch.RecordCount <= 0 Then MshSearch.Rows = 1 Exit Sub End If

For ExactRowCount = 1 To RsSrch.RecordCount

If ExactRowCount >= MshSearch.Rows - 1 Then MshSearch.Rows = MshSearch.Rows + 1 MshSearch.Row = MshSearch.Row + 1 End If

MshSearch.TextMatrix(ExactRowCount, 0) = RsSrch(1) MshSearch.TextMatrix(ExactRowCount, 1) = RsSrch(0) MshSearch.TextMatrix(ExactRowCount, 2) = RsSrch(2)

RsSrch.MoveNext Next

MshSearch.Col = 0 MshSearch.Row = 1 MshSearch.SetFocus

MshSearch.ColAlignment(1) = 3 End If End Sub

Public Sub ProductStock() Dim mProdId As Integer

Dim mProdName As String Dim mOpQty Dim mPurQty Dim mSalQty As Single As Single As Single

Dim mReOrderQty As Single Dim mCounter As Integer

Dim AvblStock As Single

Con.Execute "Delete from RepStockStatus"

'=====================Checking Available Stock=======================

Set RsMisc = New ADODB.Recordset If RsMisc.State = 1 Then RsMisc.Close RsMisc.Open "Select AcId,AcTitle,ReOrderPoint from Accounts where AcType = 'Product'", Con, adOpenStatic, adLockOptimistic

For mCounter = 1 To RsMisc.RecordCount

mProdId = Val(RsMisc(0)) mProdName = RsMisc(1) mReOrderQty = Val(RsMisc(2)) 'Opening Stock Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open "Select * from Product_Openings where ProdId = " & Val(mProdId) & "", Con, adOpenStatic, adLockOptimistic If RS.RecordCount <= 0 Then GoTo CheckPurchase

Else mOpQty = Val(RS(1)) End If RS.Close Set RS = Nothing

CheckPurchase: 'Purchases Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(Qty) from Purchase_Detail where ProdId = " & Val(mProdId) & "", Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then mPurQty = 0 GoTo CheckSales Else mPurQty = Val(RS(0)) End If RS.Close Set RS = Nothing

CheckSales: 'Sales Set RS = New ADODB.Recordset

If RS.State = 1 Then RS.Close RS.Open "Select Sum(Qty) from Sale_Detail where ProdId = " & Val(mProdId) & "", Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then mSalQty = 0 GoTo MyStock Else mSalQty = Val(RS(0)) End If

MyStock: 'Available Stock AvblStock = Val(mOpQty) + Val(mPurQty) - Val(mSalQty)

'Fetching Data into RepStockStatus Con.Execute "Insert Into RepStockStatus Values(" & Val(mProdId) & ", '" & mProdName & "', " & Val(AvblStock) & ", " & Val(mReOrderQty) & ")"

RsMisc.MoveNext Next

dataRepStockStatus.Show vbModal

End Sub

Public Sub PurchaseHistoryByDate() dataRepPurchaseByDate.Show vbModal ''SELECT Purchase_Main.PurId, Purchase_Main.PurDate, Accounts.AcId, Accounts.AcTitle, Purchase_Main.TotalAmount FROM (Purchase_Main INNER JOIN Purchase_Detail ON Purchase_Main.PurId = Purchase_Detail.PurId) INNER JOIN Accounts ON Purchase_Detail.AcId = Accounts.AcId;

End Sub

Public Sub PurchaseHistoryBySupplier() dataRepPurchaseBySupplier.Show vbModal End Sub

Public Sub DateWiseSaleHistory() dataRepSaleByDate.Show vbModal End Sub

Public Sub CustomerWiseSaleHistory() dataRepSaleByCustomer.Show vbModal End Sub

Public Sub ProductPriceList() dataRepPriceList.Show vbModal End Sub

Public Sub StockAdjustment() If DeRep.rsStockAdjustment.State = 1 Then DeRep.rsStockAdjustment.Close

WaitMode

DeRep.StockAdjustment TxtLookup.Text, TxtFrom.Value, TxtTo.Value

RepStockAdjustment.Sections("Section4").Controls("LblDate").Caption = "From: " & TxtFrom.Value & " " & "To: " & TxtTo.Value

RepStockAdjustment.Sections("Section4").Controls("LblAdjType").Caption = UCase(TxtLookup.Text)

Load RepStockAdjustment RepStockAdjustment.Refresh

RepStockAdjustment.Show 1 End Sub Public Sub VehData() Dim TotVeh As Integer

Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Select VehNo from VehicleReg", dB, adOpenStatic, adLockOptimistic If RsLov.RecordCount <= 0 Then Exit Sub End If

For TotVeh = 1 To RsLov.RecordCount ListLov.AddItem RsLov(0)

RsLov.MoveNext Next

End Sub

Public Sub VehicleWiseSaleHistory()

If DeRep.rsInvoicePrint.State = 1 Then DeRep.rsInvoicePrint.Close DeRep.InvoicePrint TxtLookup.Text, TxtFrom.Value, TxtTo.Value

RepInvoicePrint.Sections("ReportHeader").Controls("LblDate").Caption = "From: " & TxtFrom.Value & " " & "To: " & TxtTo.Value

RepInvoicePrint.Sections("ReportHeader").Controls("LblVeh").Caption = UCase(TxtLookup.Text) RepInvoicePrint.Sections("ReportHeader").Controls("LblMs").Caption = DeptName

Load RepInvoicePrint RepInvoicePrint.Refresh

RepInvoicePrint.Show 1 End Sub

Public Sub DeptData() 'Getting Dept Code for the selected Veh Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Select DeptCode From VehicleReg Where VehNo = '" & TxtLookup.Text & "'", dB, adOpenStatic, adLockOptimistic

'Getting Dept Name for the Selected Veh Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Name from Customer Where Code = " & Val(RsLov(0)) & "", dB, adOpenStatic, adLockOptimistic DeptName = RS(0) End Sub

Public Sub MeterStock() Dim Vc1 As Integer Dim mOpStock Dim mIssue Dim mAvbl As Single As Single As Single As Single

Dim mConsume Dim mDiff

As Single

dB.Execute "Delete from TblMeterStock"

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Code from MeterInfo", dB, adOpenStatic, adLockOptimistic

If RS.EOF = True Then MsgBox "No data found", vbInformation, "Message" Exit Sub End If

For Vc1 = 1 To RS.RecordCount

'Op Stock Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Select OpStock from MeterInfo Where Code = " & Val(Vc1) & "", dB, adOpenForwardOnly, adLockReadOnly If IsNull(RsLov(0)) Then mOpStock = 0 Else mOpStock = Val(RsLov(0)) End If

'Issue Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Select Sum(Qty) from MeterIssue Where MeterCode = " & Val(Vc1) & "", dB, adOpenForwardOnly, adLockReadOnly If IsNull(RsLov(0)) Then mIssue = 0 Else mIssue = Val(RsLov(0)) End If

mAvbl = Val(mOpStock) + Val(mIssue)

'Consumption Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Select Sum(ClosingReading)-Sum(OpReading)+Sum(TestQty) from MeterReading Where MeterCode = " & Val(Vc1) & "", dB, adOpenForwardOnly, adLockReadOnly If IsNull(RsLov(0)) Then mConsume = 0 Else mConsume = Val(RsLov(0)) End If

mDiff = Val(mAvbl) - Val(mConsume)

dB.Execute "INSERT INTO TblMeterStock(MeterCode,OpStock,Issue,Avbl,Consume,Diff) VALUES(" & Val(Vc1) & ", " & Val(mOpStock) & ", " & Val(mIssue) & ", " & Val(mAvbl) & ", " & Val(mConsume) & ", " & Val(mDiff) & " )"

RS.MoveNext Next End Sub

Private Sub TxtToCode_KeyPress(KeyAscii As Integer) On Error Resume Next

Cng KeyAscii On Error Resume Next End Sub

Public Sub Pause(ByVal Delay As Single) Dim X As Single X = Timer + Delay Do While X > Timer DoEvents Loop End Sub ' Add a delay to the current time ' and waits for the current time ' to catch up.

Public Sub CashBookData() Dim CashAccountCode Dim DrCash Dim CrCash Dim LastCash Dim CrSale Dim CashSale Dim Receipts Dim CrPurchase Dim CashPurchase Dim Payments As Integer

As Single As Single As Single As Single As Single As Single As Single As Single As Single

Dim Parties Dim CreditTotal Dim DebitTotal

As Single As Single As Single

'=============== Getting Last Day Cash (before the given date)

Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Select Code from Accounts Where AccType In ('Cash')", dB, adOpenStatic, adLockOptimistic

If RsLov.EOF = True Then MsgBox "Cash Account not found", vbInformation, "Message" Exit Sub Else CashAccountCode = Val(RsLov(0)) End If

Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Select Sum(Amount) from DrtGlt Where AccountCode = " & Val(CashAccountCode) & " And Tdate < #" & TxtFrom.Value & "#", dB, adOpenStatic, adLockOptimistic If IsNull(RsLov(0)) Then

DrCash = 0 Else DrCash = Val(RsLov(0)) End If

Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RS.Close RsLov.Open "Select Sum(Amount) from CrtGlt Where AccountCode = " & Val(CashAccountCode) & " And Tdate < #" & TxtFrom.Value & "#", dB, adOpenStatic, adLockOptimistic

If IsNull(RsLov(0)) Then CrCash = 0 Else CrCash = Val(RsLov(0)) End If

LastCash = Val(DrCash) - Val(CrCash)

'=============== Getting Today's Credit Sale Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close

RsLov.Open "Select Sum(TotalAmount) from Sale Where SaleType = '" & "Credit" & "' And Tdate = #" & TxtFrom.Value & "#", dB, adOpenStatic, adLockOptimistic

If IsNull(RsLov(0)) Then CrSale = 0 Else CrSale = Val(RsLov(0)) End If

'=============== Getting Today's Cash Sale Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Select Sum(TotalAmount) from Sale Where SaleType = '" & "Cash" & "' And Tdate = #" & TxtFrom.Value & "#", dB, adOpenStatic, adLockOptimistic

If IsNull(RsLov(0)) Then CashSale = 0 Else CashSale = Val(RsLov(0)) End If

'=============== Getting Today's Receipts Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close

RsLov.Open "Select Sum(Amount) from DrtGlt Where AccountCode = " & Val(CashAccountCode) & " And Tdate = #" & TxtFrom.Value & "# And TType Not In ('SAL')", dB, adOpenStatic, adLockOptimistic If IsNull(RsLov(0)) Then Receipts = 0 Else Receipts = Val(RsLov(0)) End If

'--------------------- DEBIT SIDE

'=============== Getting Today's Credit Purchase Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Select Sum(TotalAmount) from Purchase Where PurchaseType = '" & "Credit" & "' And Tdate = #" & TxtFrom.Value & "#", dB, adOpenStatic, adLockOptimistic

If IsNull(RsLov(0)) Then CrPurchase = 0 Else CrPurchase = Val(RsLov(0)) End If

'=============== Getting Today's Cash Purchase

Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Select Sum(TotalAmount) from Purchase Where PurchaseType = '" & "Cash" & "' And Tdate = #" & TxtFrom.Value & "#", dB, adOpenStatic, adLockOptimistic

If IsNull(RsLov(0)) Then CashPurchase = 0 Else CashPurchase = Val(RsLov(0)) End If

'=============== Getting Today's Payments Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Select Sum(Amount) from CrtGlt Where AccountCode = " & Val(CashAccountCode) & " And Tdate = #" & TxtFrom.Value & "# And TType Not In ('PUR')", dB, adOpenStatic, adLockOptimistic If IsNull(RsLov(0)) Then Payments = 0 Else Payments = Val(RsLov(0)) End If

'=============== Getting Today's Credit Sale (To balance on both sides with the caption name {Parties})

Set RsLov = New ADODB.Recordset If RsLov.State = 1 Then RsLov.Close RsLov.Open "Select Sum(TotalAmount) from Sale Where SaleType = '" & "Credit" & "' And Tdate = #" & TxtFrom.Value & "#", dB, adOpenStatic, adLockOptimistic

If IsNull(RsLov(0)) Then Parties = 0 Else Parties = Val(RsLov(0)) End If

RepCashBook.Sections("Section4").Controls("LblDate").Caption = Format(TxtFrom, "dd/mm/yyyy")

'Showing Totals In the Report 'CREDIT SIDE RepCashBook.Sections("Section2").Controls("LblLastCash").Caption = Val(LastCash) RepCashBook.Sections("Section2").Controls("LblCreditSale").Caption = Val(CrSale) RepCashBook.Sections("Section2").Controls("LblCashSale").Caption = Val(CashSale) RepCashBook.Sections("Section2").Controls("LblCashReceipts").Caption = Val(Receipts)

'DEBIT SIDE RepCashBook.Sections("Section2").Controls("LblCreditPurchase").Caption = Val(CrPurchase) RepCashBook.Sections("Section2").Controls("LblCashPurchase").Caption = Val(CashPurchase)

RepCashBook.Sections("Section2").Controls("LblAllPayment").Caption = Val(Payments) RepCashBook.Sections("Section2").Controls("LblParties").Caption = Val(Parties)

'BALANCING CREDIT SIDE TOTAL FOR CREDIT PURCHASE RepCashBook.Sections("Section2").Controls("LblCreditParties").Caption = Val(CrPurchase)

'CREDIT SIDE TOTAL CreditTotal = Val(LastCash) + Val(CrSale) + Val(CashSale) + Val(Receipts) + Val(CrPurchase) RepCashBook.Sections("Section2").Controls("LblCreditTotal").Caption = Val(CreditTotal)

'DEBIT SIDE TOTAL DebitTotal = Val(CrPurchase) + Val(CashPurchase) + Val(Payments) + Val(Parties) RepCashBook.Sections("Section2").Controls("LblDebitTotal").Caption = Val(DebitTotal)

'BALANCE TOTAL RepCashBook.Sections("Section2").Controls("LblTotal").Caption = Val(CreditTotal) Val(DebitTotal)

RepCashBook.Show 1

End Sub

Public Sub SetSearchGrid() 'Setting of Search Grid With MshSearch .ColWidth(1) = 2500 .ColWidth(2) = 1500

.TextMatrix(0, 0) = "ID" .TextMatrix(0, 1) = "Account Title" .TextMatrix(0, 2) = "Account Type"

.RowHeight(0) = 400

.ColAlignmentFixed(0) = 4 .ColAlignmentFixed(1) = 4 .ColAlignmentFixed(2) = 4

End With

End Sub

Public Sub FillGridAccounts()

'Filling all Accounts Data in Search grid Select Case VRun Case "Accounts Status" SQLQry = "Select AcId, AcTitle, AcType from ViewHeadWise where AcType = '" & TxtLookup.Text & "'"

Case "Accounts Ledger" SQLQry = "Select AcId, AcTitle, AcType from ViewHeadWise where AcType NOT in ('Product')"

Case "Supplier Wise Purchase History" SQLQry = "Select AcId, AcTitle, AcType from ViewHeadWise where AcType in ('Customer','Supplier')"

Case "Product Wise Purchase History" SQLQry = "Select AcId, AcTitle, AcType from ViewHeadWise where AcType in ('Product')"

Case "Customer Wise Sale History" SQLQry = "Select AcId, AcTitle, AcType from ViewHeadWise where AcType in ('Customer','Supplier')"

Case "Product Wise Sale History" SQLQry = "Select AcId, AcTitle, AcType from ViewHeadWise where AcType in ('Product')"

End Select

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open SQLQry, Con, adOpenStatic, adLockReadOnly If RS.RecordCount <= 0 Then MsgBox "No data found", vbInformation, "Message" Exit Sub End If Set MshSearch.DataSource = RS End Sub

Public Sub SearchRecord() 'Filling the Search grid with Critarial Data

Dim SearchedRowCount As Integer

If PicSrchGrid.Visible = True Then

MshSearch.Rows = 2 MshSearch.Row = 0

SearchedRowCount = 0

SQLQry = "Select AcId, AcTitle, AcType from ViewHeadWise where AcTitle Like '" & TxtGrdSrch.Text & "%'"

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open SQLQry, Con, adOpenStatic, adLockReadOnly

If RS.RecordCount <= 0 Then MshSearch.Clear

With MshSearch .TextMatrix(0, 0) = "ID" .TextMatrix(0, 1) = "Account Title" .TextMatrix(0, 2) = "Account Type" End With

MshSearch.Rows = 2 Exit Sub End If

For SearchedRowCount = 1 To RS.RecordCount

If SearchedRowCount >= MshSearch.Rows - 1 Then MshSearch.Rows = MshSearch.Rows + 1 MshSearch.Row = MshSearch.Row + 1 End If

MshSearch.TextMatrix(SearchedRowCount, 0) = RS(0) MshSearch.TextMatrix(SearchedRowCount, 1) = RS(1) MshSearch.TextMatrix(SearchedRowCount, 2) = RS(2)

RS.MoveNext Next

MshSearch.Col = 0 MshSearch.Row = 0 MshSearch.ColAlignment(0) = 3 End If

End Sub

Public Sub ReOrderStatus()

dataRepReOrderPoint.Show vbModal End Sub

Public Sub PurchaseHistoryByProduct() dataRepPurchaseByProduct.Show vbModal End Sub

Public Sub SaleHistoryByProduct() dataRepSaleByProduct.Show vbModal End Sub

Public Sub ProductsToReorder() dataRepProductToReorder.Show vbModal End Sub Public Sub TrialBalanceData() Dim AcId As Single Dim AcTitle As String Dim SumofDR As Single Dim SumofCr As Single Dim Balance As Single Dim DrBal As Single Dim CrBal As Single

Con.Execute "Delete * from RepTrialBalance"

'Copying data from ViewTrialBalance to RepTrialBalance Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select * from ViewTrialBalance", Con, adOpenStatic, adLockOptimistic While Not RS.EOF = True AcId = Val(RS(0)) AcTitle = RS(1) SumofDR = Val(RS(2)) SumofCr = Val(RS(3)) Balance = Val(RS(2)) - Val(RS(3))

If Balance > 0 Then DrBal = Abs(Balance) CrBal = 0 ElseIf Balance < 0 Then CrBal = Abs(Balance) DrBal = 0 Else DrBal = 0 CrBal = 0 End If

Con.Execute "Insert into RepTrialBalance(Id,Title,Dr,Cr) Values (" & Val(AcId) & ", '" & AcTitle & "', " & Val(DrBal) & ", " & Val(CrBal) & ")" RS.MoveNext

Wend

'Getting Total of both (Debit / Credit Side) Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(Dr),Sum(Cr) from RepTrialBalance", Con, adOpenStatic, adLockOptimistic

On Error Resume Next

TrialDr = Val(RS(0)) TrialCr = Val(RS(1))

'=============================================REPORT======== =======================================

Set RS = New ADODB.Recordset

If RS.State = 1 Then RS.Close

RS.Open "Select * from RepTrialBalance", Con, adOpenStatic, adLockOptimistic

With DataRepTrialBalance Set .DataSource = RS .DataMember = RS.DataMember

.Sections("Section1").Controls("Text1").DataField = "Id" .Sections("Section1").Controls("Text2").DataField = "Title" .Sections("Section1").Controls("Text3").DataField = "DR" .Sections("Section1").Controls("Text4").DataField = "CR" End With

End Sub

Public Sub IncomeStatData() Dim NetSale Dim COG Dim ProfitB4OtherIncome Dim OtherIncome As Single As Single As Single As Single

Dim Expense Dim NetProfit

As Single As Single

mDateQry = " BETWEEN #" & FrmRep.TxtFrom.Value & "# And #" & FrmRep.TxtTo.Value & "#"

' NET SALES OF THE DEFINED PERIOD Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(TotalAmount) from Sale_Main where SaleDate" & mDateQry, Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then NetSale = 0 Else NetSale = Val(RS(0)) End If

Con.Execute "Update RepIncomeStat Set Amount = " & Val(NetSale) & " where Id =1"

' COST OF GOODS SOLD Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open "Select Sum(Qty*PurAvg) from ProfitLoss where SaleDate" & mDateQry, Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then COG = 0 Else COG = Val(RS(0)) End If

Con.Execute "Update RepIncomeStat Set Amount = " & Val(COG) & " where Id =2"

' GROSS PROFIT BEFORE OTHER INCOME ProfitB4OtherIncome = Val(NetSale) - Val(COG)

Con.Execute "Update RepIncomeStat Set Amount = " & Val(ProfitB4OtherIncome) & " where Id =3"

' GET OTHER INCOME Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(OtherIncome) from ViewOtherIncome where TransDate " & mDateQry, Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then

OtherIncome = 0 Else OtherIncome = Val(RS(0)) End If

Con.Execute "Update RepIncomeStat Set Amount = " & Val(OtherIncome) & " where Id =4"

' GET GROSS PROFIT Gross = Val(ProfitB4OtherIncome) + Val(OtherIncome)

Con.Execute "Update RepIncomeStat Set Amount = " & Val(Gross) & " where Id =5"

' GET EXPENSE Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(TotalExp) from ViewExpense where TransDate " & mDateQry, Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then Expense = 0 Else Expense = Val(RS(0)) End If

Con.Execute "Update RepIncomeStat Set Amount = " & Val(Expense) & " where Id =6"

' NET PROFIT NetProfit = Val(Gross) - Val(Expense) Con.Execute "Update RepIncomeStat Set Amount = " & Val(NetProfit) & " where Id =7"

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select * from RepIncomeStat", Con, adOpenStatic, adLockReadOnly

With dataRepIncomeStat

Set .DataSource = RS .DataMember = RS.DataMember

.Sections("Section2").Controls("lblNetSale").Caption = Val(NetSale) .Sections("Section2").Controls("lblCOG").Caption = Val(COG) .Sections("Section2").Controls("lblGross").Caption = Val(ProfitB4OtherIncome) .Sections("Section2").Controls("lblOtherIncome").Caption = Val(OtherIncome) .Sections("Section2").Controls("lblExpense").Caption = Val(Expense) .Sections("Section2").Controls("lblNetProfit").Caption = Val(NetProfit)

.Sections("Section4").Controls("lblPeriod").Caption = "From " & FrmRep.TxtFrom.Value & " To " & FrmRep.TxtTo.Value

.Show vbModal

End With

End Sub

MODULES
1. modConnection.bas

18

Public Con As New ADODB.Connection Public RS As New ADODB.Recordset Public RsNAV As New ADODB.Recordset Public InsertRecord As New ADODB.Recordset Public UpdateRecord As New ADODB.Recordset Public RsMisc As New ADODB.Recordset

Public Sub dbConnection() Set Con = New ADODB.Connection Con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database\IMSDB.mdb;Persist Security Info=False" Con.Open End Sub

Public Sub Main() Call dbConnection frmLogin.Show '' '' Load frmStart frmStart.Show

End Sub

2. modMisc.bas
Public ctl As Control

Public RsMax As New ADODB.Recordset Public MaxNmbr As Integer Public mHeadId As Integer Public TrialDr As Double Public TrialCr As Double Public TransactionType As String Public TransactionRef As String Public StrQry As String 'Variable Reporting

'Declaring SLEEP API for using as wait between work Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

'Switching On / Off buttons according to the mode Public Function Modes(pNew As Boolean, pOther As Boolean, Frm As Object) 'If new record then If pNew = True Then Frm.lbl(0).Enabled = False Frm.lbl(3).Enabled = False Frm.lbl(4).Enabled = False Frm.lbl(5).Enabled = False

'If Not new record then ElseIf pOther = True Then Frm.lbl(0).Enabled = True

Frm.lbl(3).Enabled = True Frm.lbl(4).Enabled = True Frm.lbl(5).Enabled = True End If End Function

'On GotFocus Highlight the Text Public Function High(txt As TextBox) txt.SelStart = 0 txt.SelLength = Len(txt) End Function

'Set focus to the next control usong Enter Public Function Cng(KeyAscii As Integer) If KeyAscii = 13 Then SendKeys vbTab KeyAscii = 0 End If

End Function

'Clear all text Boxes and Combo Boxes Public Function Clear(Frm As Form)

For Each ctl In Frm.Controls

If TypeOf ctl Is TextBox Then ctl.Text = "" ElseIf TypeOf ctl Is ComboBox Then ctl.ListIndex = -1 End If

Next

End Function

'Only numbers in textbox Public Function ONU(KeyAscii As Integer, txt As TextBox) If KeyAscii > 47 And KeyAscii < 58 Or KeyAscii = 8 Or KeyAscii = 46 Then

If KeyAscii = 46 Then

If InStr(txt.Text, ".") Then KeyAscii = 0 Exit Function

Else txt.Text = txt.Text End If Else End If Else KeyAscii = 0 End If End Function

'Getting Maximum number for Code field Public Function MaxNumber(FieldName As String, TableName As String) Set RsMax = New ADODB.Recordset If RsMax.State = 1 Then RsMax.Close RsMax.Open "SELECT Max(" & FieldName & ") + 1 from " & TableName & " where MaxCode =1", Con, adOpenDynamic, adLockOptimistic

If IsNull(RsMax(0)) Then MaxNumber = 1 Else MaxNumber = RsMax(0) End If

MaxNmbr = Val(MaxNumber)

End Function

'Updating Maximum Number Public Function UpdateMaxNumber(FieldName As String, TBox As Integer) Con.Execute "Update Max_Codes Set " & FieldName & " = " & Val(TBox) & "" End Function Public Sub ChangeFocusOnEnter(KeyAscii As Integer, Frm As Object) If KeyAscii = vbKeyReturn Then SendKeys vbTab End If End Sub

Public Function MouseOver(mLabel As Label) mLabel.ForeColor = vbYellow mLabel.Font.Underline = True End Function

3. modNavigation.bas
'Locking the Navigation Button on New Record Public Function LockNav(Frm As Object) Frm.lblnav(0).Enabled = False Frm.lblnav(1).Enabled = False

Frm.lblnav(2).Enabled = False Frm.lblnav(3).Enabled = False End Function

'UnLocking the Navigation Button on Cancel Public Function UnLockNav(Frm As Object) Frm.lblnav(0).Enabled = True Frm.lblnav(1).Enabled = True Frm.lblnav(2).Enabled = True Frm.lblnav(3).Enabled = True End Function

4. modWriteInGrid.bas

Public Function EditGrid(Msh As MSHFlexGrid, KeyAscii As Integer)

'==================================== Editing Grid Code For Transaction ====================================

'If First Row selected then Select Case Msh.Row Case 0 KeyAscii = 0

Exit Function End Select

'Block Every Key Except Enter in Column 1 (Account Name)

Select Case Msh.Col

Case 1

'If ENTER is pressed on Account Name Column then move to next column If KeyAscii = 13 Then SendKeys "{right}" Exit Function End If

KeyAscii = 0 Exit Function End Select

'---------------------------------------------------------

Select Case KeyAscii

Case 8: 'IF KEY IS BACKSPACE THEN If Msh.Text <> "" Then Msh.Text = Left$(Msh.Text, (Len(Msh.Text) - 1))

Case 13: 'IF KEY IS ENTER THEN

Select Case Msh.Col

Case Is < 4 '----------Move Curssor to Right Side untill col >= 3-----Msh.SetFocus SendKeys "{right}"

Case 4 Msh.SetFocus If (Msh.Row + 1) = Msh.Rows Then ''-------- Null Value Chk in last col---------------

'If values are missing in Debit and Credit Side If Len(Msh.TextMatrix(Msh.Row, 1)) = 0 Or Msh.TextMatrix(Msh.Row, 1) = "" Then MsgBox "Select Account Name", vbInformation, "Message" Msh.Col = 1 Exit Function End If

'If values are missing in Debit and Credit Side If Val(Msh.TextMatrix(Msh.Row, 3)) = 0 And Val(Msh.TextMatrix(Msh.Row, 4)) = 0 Then MsgBox "Enter Debit / Credit Amount", vbInformation, "Message" Msh.Col = 3 Exit Function End If

'If values are in both Debit and Credit Side If Val(Msh.TextMatrix(Msh.Row, 3)) > 0 And Val(Msh.TextMatrix(Msh.Row, 4)) > 0 Then MsgBox "Enter Only Debit OR Credit Amount", vbInformation, "Message" Msh.Col = 3 Exit Function End If

''-------------New Row Create---------Msh.Rows = Msh.Rows + 1 Msh.Col = 1 ''-------------------------------------

'''

''-------------Adding Amount to Debit / credit Textbox----------

'''

frmTransaction.txtCredit = Val(frmTransaction.txtCredit) +

Val(Msh.TextMatrix(Msh.Row, 4)) ''' frmTransaction.txtDebit = Val(frmTransaction.txtDebit) +

Val(Msh.TextMatrix(Msh.Row, 3)) ''' ''' ''-------------------------------------

End If

SendKeys "{home}" + "{down}" '' + "{right}"

End Select

Case Else 'KeyAscii Select ''-------write any code for Any Validation------------Select Case Msh.Col Case 3, 4 ''-------Allow Number Validation------------ONUGrid KeyAscii, Msh End Select ''-------------Write Data in Cells---------Msh.Text = Msh.Text + Chr$(KeyAscii) ''-------------------------------------

End Select 'KeyAscii Select End Function 'Only numbers in Grid Public Function ONUGrid(KeyAscii As Integer, txt As MSHFlexGrid) If KeyAscii > 47 And KeyAscii < 58 Or KeyAscii = 8 Or KeyAscii = 46 Then

If KeyAscii = 46 Then

If InStr(txt.Text, ".") Then KeyAscii = 0 Exit Function Else txt.Text = txt.Text End If Else End If Else KeyAscii = 0 End If End Function

Public Function SetPSGRID(Msh As MSHFlexGrid)

'Purchase / Sale Grid

'Column Setting With Msh .Rows = 2 .Cols = 7

.ColWidth(0) = 400 .ColWidth(1) = 5200 .ColWidth(2) = 1000 .ColWidth(3) = 1000 .ColWidth(4) = 1500 .ColWidth(5) = 0 .ColWidth(6) = 0 'Product description 'Qty 'Rate 'Amount 'Product Code 'Avg Cost

'Column Captions

.TextMatrix(0, 1) = "Product Description" .TextMatrix(0, 2) = "Quantity" .TextMatrix(0, 3) = "Price" .TextMatrix(0, 4) = "Amount"

End With End Function

Public Function EditGridPS(Msh As MSHFlexGrid, KeyAscii As Integer) ' Purchase / Sale Grid Edit

'==================================== Editing Grid Code For Purchase / Sale ====================================

'If First Row selected then Select Case Msh.Row Case 0 KeyAscii = 0 Exit Function End Select

'Block Every Key Except Enter in Column 1 (Product Name)

Select Case Msh.Col

Case 1

'If ENTER is pressed on Product Name Column then move to next column If KeyAscii = 13 Then SendKeys "{right}"

Exit Function End If

KeyAscii = 0 Exit Function End Select

'---------------------------------------------------------

Select Case KeyAscii

Case 8: 'IF KEY IS BACKSPACE THEN If Msh.Text <> "" Then Msh.Text = Left$(Msh.Text, (Len(Msh.Text) - 1))

Case 13: 'IF KEY IS ENTER THEN

Select Case Msh.Col

Case Is < 3 '----------Move Curssor to Right Side untill col >= 3-----Msh.SetFocus SendKeys "{right}"

Case 3 Msh.SetFocus If (Msh.Row + 1) = Msh.Rows Then ''-------- Null Value Chk in last col---------------

'If Product Name is missing If Len(Msh.TextMatrix(Msh.Row, 1)) = 0 Or Msh.TextMatrix(Msh.Row, 1) = "" Then MsgBox "Select Product Name", vbInformation, "Message" Msh.Col = 1 Exit Function End If

'If values are missing of Qty or Price If Val(Msh.TextMatrix(Msh.Row, 2)) = 0 Or Val(Msh.TextMatrix(Msh.Row, 3)) = 0 Then MsgBox "Enter Quantity / Price", vbInformation, "Message" Msh.Col = 2 Exit Function End If

'Total of Row i.e Qty * Price Msh.TextMatrix(Msh.Row, 4) = Val(Msh.TextMatrix(Msh.Row, 2)) * Val(Msh.TextMatrix(Msh.Row, 3))

''-------------New Row Create---------Msh.Rows = Msh.Rows + 1 Msh.Col = 1 ''-------------------------------------

End If

SendKeys "{home}" + "{down}" '' + "{right}"

End Select

Case Else 'KeyAscii Select ''-------write any code for Any Validation------------Select Case Msh.Col Case 2, 3, 4 ''-------Allow Number Validation------------ONUGrid KeyAscii, Msh End Select ''-------------Write Data in Cells---------Msh.Text = Msh.Text + Chr$(KeyAscii) ''------------------------------------End Select 'KeyAscii Select

End Function

Public Function EditGridAcOp(Msh As MSHFlexGrid, KeyAscii As Integer) 'For Account Opening

'==================================== Editing Grid Code For A/c Opening ====================================

'If First Row selected then Select Case Msh.Row Case 0 KeyAscii = 0 Exit Function End Select

'Block Every Key Except Enter in Column 1 (Account Name)

Select Case Msh.Col

Case 1

'If ENTER is pressed on Account Name Column then move to next column If KeyAscii = 13 Then SendKeys "{right}" Exit Function

End If

KeyAscii = 0 Exit Function End Select

'---------------------------------------------------------

Select Case KeyAscii

Case 8: 'IF KEY IS BACKSPACE THEN If Msh.Text <> "" Then Msh.Text = Left$(Msh.Text, (Len(Msh.Text) - 1))

Case 13: 'IF KEY IS ENTER THEN

Select Case Msh.Col

Case Is < 5 '----------Move Curssor to Right Side untill col >= 3-----Msh.SetFocus SendKeys "{right}"

Case 5

Msh.SetFocus If (Msh.Row + 1) = Msh.Rows Then ''-------- Null Value Chk in last col---------------

'If values are missing in Debit and Credit Side If Len(Msh.TextMatrix(Msh.Row, 1)) = 0 Or Msh.TextMatrix(Msh.Row, 1) = "" Then MsgBox "Select Account Name", vbInformation, "Message" Msh.Col = 1 Exit Function End If

'If values are missing in Debit and Credit Side If Val(Msh.TextMatrix(Msh.Row, 4)) = 0 And Val(Msh.TextMatrix(Msh.Row, 5)) = 0 Then MsgBox "Enter Debit / Credit Amount", vbInformation, "Message" Msh.Col = 4 Exit Function End If

'If values are in both Debit and Credit Side If Val(Msh.TextMatrix(Msh.Row, 4)) > 0 And Val(Msh.TextMatrix(Msh.Row, 5)) > 0 Then MsgBox "Enter Only Debit OR Credit Amount", vbInformation, "Message"

Msh.Col = 3 Exit Function End If

''-------------New Row Create---------Msh.Rows = Msh.Rows + 1 Msh.Col = 1 ''-------------------------------------

End If

SendKeys "{home}" + "{down}" '' + "{right}"

End Select

Case Else 'KeyAscii Select ''-------write any code for Any Validation------------Select Case Msh.Col Case 3, 4, 5 ''-------Allow Number Validation------------ONUGrid KeyAscii, Msh End Select ''-------------Write Data in Cells----------

Msh.Text = Msh.Text + Chr$(KeyAscii) ''------------------------------------End Select 'KeyAscii Select End Function

5. modWriteOnPictureBox.bas
Public Sub PrintToCenter(Msg As String, PicBox As PictureBox, FormTop As Boolean)

If FormTop = False Then With PicBox .AutoRedraw = -1 .Font = "Courier New" .FontSize = 8 .FontBold = False .ForeColor = vbBlack

'Its mean menu

HalfWidth = .TextWidth(Msg) / 2

' Calculate one-half width.

HalfHeight = .TextHeight(Msg) / 2 ' Calculate one-half height. .CurrentX = .ScaleWidth / 2 - HalfWidth ' Set X. .CurrentY = .ScaleHeight / 2 - HalfHeight ' Set Y. End With

Else

'its mean Form Title Bar

With PicBox .AutoRedraw = -1 .Font = "Courier New" .FontSize = 14 .FontBold = True .ForeColor = vbWhite

HalfWidth = .TextWidth(Msg) / 2

' Calculate one-half width.

HalfHeight = .TextHeight(Msg) / 2 ' Calculate one-half height. .CurrentX = .ScaleWidth / 2 - HalfWidth ' Set X. .CurrentY = .ScaleHeight / 2 - HalfHeight ' Set Y. End With End If

PicBox.Print Msg ' Print message.

End Sub

REPORTS
1. daraRepAcLedger.Dsr

19

This report is to display the account ledger. Coding:


Private Sub DataReport_Initialize() If Con.State = 1 Then Con.Close End If

modConnection.dbConnection

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select * from RepAcLedger", Con, adOpenStatic, adLockOptimistic RS.Requery

With Me Set .DataSource = RS .DataMember = RS.DataMember

'PAGE HEADER .Sections("Section2").Controls("lblAcId").Caption = Val(FrmRep.TxtLookupCode) .Sections("Section2").Controls("lblAcTitle").Caption = " " & FrmRep.TxtLookup.Text .Sections("Section2").Controls("lblDateFrom").Caption = FrmRep.TxtFrom.Value

.Sections("Section2").Controls("lblDateTo").Caption = FrmRep.TxtTo.Value 'DETAIL SECTION .Sections("Section1").Controls("txtdate").DataField = "tdate" .Sections("Section1").Controls("txtDescript").DataField = "Descript" .Sections("Section1").Controls("txtDebit").DataField = "Dr" .Sections("Section1").Controls("txtCredit").DataField = "Cr" .Sections("Section1").Controls("txtBalance").DataField = "Balance" .Sections("Section1").Controls("txtDrCr").DataField = "DrCr"

.Refresh End With End Sub

2. dataRepAccountStatus.Dsr
This report is to display the account status. Coding:
Dim DrAmt As Single Dim CRAmt As Single Dim Balance As Single

Private Sub DataReport_Initialize() With Me

.Sections("Section4").Controls("lblTitle").Caption = UCase(FrmRep.TxtLookup.Text) & " ACCOUNTS STATUS" .Sections("Section4").Controls("lblDate").Caption = Format(Date, "dd/mm/yyyy") End With

If Not FrmRep.TxtLookup.Text = "ALL" Then Me.Sections("Section5").Controls("lblNote").Visible = False Else Me.Sections("Section5").Controls("lblNote").Visible = True End If

'Creating Temp Table for Account Status Report

' Drop the Temp Accounts Status table if it already exists. On Error Resume Next Con.Execute "DROP TABLE RepAccountStatus" On Error Resume Next

' Create the table. Con.Execute _ "CREATE TABLE RepAccountStatus(" & _ "AcId INTEGER NOT NULL," & _

"AcTitle VARCHAR(40) NOT NULL," & _

"AcType

VARCHAR(25) NOT NULL," & _

"DR SINGLE NOT NULL," & _ "CR SINGLE NOT NULL)"

' Fetching Data into RepAccountStatus Table Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open StrQry, Con, adOpenStatic, adLockOptimistic

While Not RS.EOF = True If Val(RS(3)) > 0 Then CRAmt = 0 DrAmt = Val(RS(3)) ElseIf Val(RS(3)) < 0 Then DrAmt = 0 CRAmt = Val(RS(3)) Else DrAmt = 0 CRAmt = 0 End If

Con.Execute "Insert into RepAccountStatus Values( " & Val(RS(0)) & ", '" & RS(1) & "', '" & RS(2) & "', " & Val(DrAmt) & ", " & Abs(Val(CRAmt)) & ")"

RS.MoveNext Wend

'Getting data from Table Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select * from RepAccountStatus", Con, adOpenStatic, adLockOptimistic

'Report With dataRepAccountStatus Set .DataSource = RS .DataMember = RS.DataMember

.Sections("Section1").Controls("txtId").DataField = "AcId" .Sections("Section1").Controls("txtTitle").DataField = "AcTitle" .Sections("Section1").Controls("txtType").DataField = "AcType" .Sections("Section1").Controls("txtDr").DataField = "DR" .Sections("Section1").Controls("txtCr").DataField = "CR"

End With

End Sub

Private Sub DataReport_Terminate() ' Drop the Temp Accounts Status table on exit. RS.Close Set RS = Nothing Con.Execute "DROP TABLE RepAccountStatus"

End Sub

3. dataRepIncomeStat.Dsr
This report is to display the income statement. Coding:
Private Sub DataReport_Error(ByVal JobType As MSDataReportLib.AsyncTypeConstants, ByVal Cookie As Long, ByVal ErrObj As MSDataReportLib.RptError, ShowError As Boolean)

End Sub

4. dataRepPriceList.Dsr
This report is to display the price list. Coding:
Private Sub DataReport_Initialize()

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select AcId, AcTitle, SalePrice from Accounts where Actype = 'Product'", Con, adOpenStatic, adLockOptimistic If RS.RecordCount <= 0 Then Exit Sub End If

With Me Set .DataSource = RS .DataMember = RS.DataMember

.Sections("Section4").Controls("lblDate").Caption = Format(Date, "dd/mm/yyyy")

.Sections("Section1").Controls("txtId").DataField = "AcId" .Sections("Section1").Controls("TxtName").DataField = "AcTitle"

.Sections("Section1").Controls("txtPrice").DataField = "SalePrice" End With

End Sub

5. dataRepProductToReorder.Dsr
This report is to display the list of products with their reoder status. Coding:
Private Sub DataReport_Initialize() Dim mProdId As Integer

Dim mProdName As String Dim mOpQty Dim mPurQty Dim mSalQty As Single As Single As Single

Dim mReOrderQty As Single Dim mCounter As Integer

Dim AvblStock As Single

Con.Execute "Delete from RepProductsToReorder"

'=====================Checking Available Stock=======================

Set RsMisc = New ADODB.Recordset If RsMisc.State = 1 Then RsMisc.Close RsMisc.Open "Select AcId,AcTitle,ReOrderPoint from Accounts where AcType = 'Product'", Con, adOpenStatic, adLockOptimistic

For mCounter = 1 To RsMisc.RecordCount

mProdId = Val(RsMisc(0)) mProdName = RsMisc(1) mReOrderQty = Val(RsMisc(2)) 'Opening Stock Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open "Select * from Product_Openings where ProdId = " & Val(mProdId) & "", Con, adOpenStatic, adLockOptimistic If RS.RecordCount <= 0 Then GoTo CheckPurchase Else mOpQty = Val(RS(1))

End If RS.Close Set RS = Nothing

CheckPurchase: 'Purchases Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(Qty) from Purchase_Detail where ProdId = " & Val(mProdId) & "", Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then mPurQty = 0 GoTo CheckSales Else mPurQty = Val(RS(0)) End If RS.Close Set RS = Nothing

CheckSales: 'Sales Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open "Select Sum(Qty) from Sale_Detail where ProdId = " & Val(mProdId) & "", Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then mSalQty = 0 GoTo MyStock Else mSalQty = Val(RS(0)) End If

MyStock: 'Available Stock AvblStock = Val(mOpQty) + Val(mPurQty) - Val(mSalQty)

If AvblStock < mReOrderQty Then 'Fetching Data into RepStockStatus Con.Execute "Insert Into RepProductsToReorder Values(" & Val(mProdId) & ", '" & mProdName & "', " & Val(AvblStock) & ", " & Val(mReOrderQty) & ")" End If

RsMisc.MoveNext

Next

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select * from RepProductsToReorder", Con, adOpenStatic, adLockPessimistic

With Me Set .DataSource = RS .DataMember = RS.DataMember

.Sections("Section1").Controls("txtId").DataField = "ProductID" .Sections("Section1").Controls("txtName").DataField = "ProductName" .Sections("Section1").Controls("txtStock").DataField = "AvblStock" .Sections("Section1").Controls("txtReorder").DataField = "ReOrderPoint"

End With

End Sub

6. dataRepPurchaseByDate.Dsr
This report is to display the purchase details ordered by date. Coding:
Dim mDateQry As String Dim mTotal As Single Private Sub DataReport_Initialize()

mDateQry = " BETWEEN #" & FrmRep.TxtFrom.Value & "# And #" & FrmRep.TxtTo.Value & "#"

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select * from ViewRepPurchase where PurDate " & mDateQry, Con, adOpenStatic, adLockOptimistic

With Me Set .DataSource = RS .DataMember = RS.DataMember

.Sections("Section4").Controls("lbldate").Caption = "From " & Format(FrmRep.TxtFrom.Value, "dd/mm/yyyy") & " To " & Format(FrmRep.TxtTo.Value, "dd/mm/yyyy")

.Sections("Section1").Controls("txtId").DataField = "PurId" .Sections("Section1").Controls("txtDate").DataField = "PurDate" .Sections("Section1").Controls("txtAcId").DataField = "AcId" .Sections("Section1").Controls("txtTitle").DataField = "AcTitle" .Sections("Section1").Controls("txtAmount").DataField = "TotalAmount" End With

Set RS = New ADODB.Recordset

If RS.State = 1 Then RS.Close RS.Open "Select Sum(TotalAmount) from ViewRepPurchase where PurDate " & mDateQry, Con, adOpenStatic, adLockOptimistic

If IsNull(RS(0)) Then Exit Sub End If

Me.Sections("Section5").Controls("lblTotal").Caption = Val(RS(0))

End Sub

7. dataRepPurchaseByProduct.Dsr
This report is to display the purchase details ordered by product. Coding:
Dim mDateQry As String Private Sub DataReport_Initialize()

mDateQry = " BETWEEN #" & FrmRep.TxtFrom.Value & "# And #" & FrmRep.TxtTo.Value & "#"

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select * from ViewPurchaseByProduct where ProdId = " & Val(FrmRep.TxtLookupCode) & " and PurDate " & mDateQry, Con, adOpenStatic, adLockOptimistic

With Me Set .DataSource = RS .DataMember = RS.DataMember

.Sections("Section2").Controls("lblProdId").Caption = Val(FrmRep.TxtLookupCode) .Sections("Section2").Controls("lblProdName").Caption = FrmRep.TxtLookup .Sections("Section2").Controls("lblDateFrom").Caption = Format(FrmRep.TxtFrom.Value, "dd/mm/yyyy") .Sections("Section2").Controls("lblDateTo").Caption = Format(FrmRep.TxtTo.Value, "dd/mm/yyyy") 'DETAIL .Sections("Section1").Controls("txtDate").DataField = "PurDate" .Sections("Section1").Controls("txtPurId").DataField = "PurId" .Sections("Section1").Controls("txtAcId").DataField = "AcId" .Sections("Section1").Controls("txtTitle").DataField = "AcTitle" .Sections("Section1").Controls("txtQty").DataField = "Qty" .Sections("Section1").Controls("txtPrice").DataField = "Price" .Sections("Section1").Controls("txtAmount").DataField = "Amount" End With

'Total Qty Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(Qty) from ViewPurchaseByProduct where ProdId = " & Val(FrmRep.TxtLookupCode) & " and PurDate " & mDateQry, Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then Exit Sub End If

Me.Sections("Section5").Controls("lblTotalQty").Caption = Val(RS(0))

'Avg Price Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select AVG(Price) from ViewPurchaseByProduct where ProdId = " & Val(FrmRep.TxtLookupCode) & " and PurDate " & mDateQry, Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then Exit Sub End If

Me.Sections("Section5").Controls("lblAvgPrice").Caption = Val(RS(0))

'Total Amount Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(Amount) from ViewPurchaseByProduct where ProdId = " & Val(FrmRep.TxtLookupCode) & " and PurDate " & mDateQry, Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then Exit Sub End If

Me.Sections("Section5").Controls("lblTotalAmount").Caption = Val(RS(0))

End Sub

8. dataRepPurchaseBySupplier.Dsr
This report is to display the purchase details ordered by supplier. Coding:
Dim mDateQry As String Dim mTotal As Single Private Sub DataReport_Initialize()

mDateQry = " BETWEEN #" & FrmRep.TxtFrom.Value & "# And #" & FrmRep.TxtTo.Value & "#"

Set RS = New ADODB.Recordset

If RS.State = 1 Then RS.Close RS.Open "Select * from ViewRepPurchase where AcId = " & Val(FrmRep.TxtLookupCode) & " and PurDate " & mDateQry, Con, adOpenStatic, adLockOptimistic

With Me Set .DataSource = RS .DataMember = RS.DataMember

.Sections("Section2").Controls("lblAcId").Caption = Val(FrmRep.TxtLookupCode) .Sections("Section2").Controls("lblAcTitle").Caption = FrmRep.TxtLookup .Sections("Section2").Controls("lblDateFrom").Caption = Format(FrmRep.TxtFrom.Value, "dd/mm/yyyy") .Sections("Section2").Controls("lblDateTo").Caption = Format(FrmRep.TxtTo.Value, "dd/mm/yyyy") 'DETAIL .Sections("Section1").Controls("txtId").DataField = "PurId" .Sections("Section1").Controls("txtDate").DataField = "PurDate" .Sections("Section1").Controls("txtAcId").DataField = "AcId" .Sections("Section1").Controls("txtTitle").DataField = "AcTitle" .Sections("Section1").Controls("txtAmount").DataField = "TotalAmount" End With

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open "Select Sum(TotalAmount) from ViewRepPurchase where AcId = " & Val(FrmRep.TxtLookupCode) & " and PurDate " & mDateQry, Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then Exit Sub End If Me.Sections("Section5").Controls("lblTotal").Caption = Val(RS(0))

End Sub

9. dataRepReorderPoint.Dsr
This report is to display the reorder point. Coding:
Private Sub DataReport_Initialize() Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select AcId, AcTitle, ReOrderPoint from Accounts where Actype = 'Product'", Con, adOpenStatic, adLockOptimistic If RS.RecordCount <= 0 Then Exit Sub End If

With Me

Set .DataSource = RS .DataMember = RS.DataMember

.Sections("Section1").Controls("txtId").DataField = "AcId" .Sections("Section1").Controls("TxtName").DataField = "AcTitle" .Sections("Section1").Controls("txtReOrder").DataField = "ReOrderPoint" End With

End Sub

10. dataRepSaleByCustomer.Dsr
This report is to display the sales details ordered by customer. Coding:
Dim mDateQry As String Dim mTotal As Single Private Sub DataReport_Initialize()

mDateQry = " BETWEEN #" & FrmRep.TxtFrom.Value & "# And #" & FrmRep.TxtTo.Value & "#"

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open "Select * from ViewRepSale where AcId = " & Val(FrmRep.TxtLookupCode) & " and SaleDate " & mDateQry, Con, adOpenStatic, adLockOptimistic

With Me Set .DataSource = RS .DataMember = RS.DataMember

.Sections("Section2").Controls("lblAcId").Caption = Val(FrmRep.TxtLookupCode) .Sections("Section2").Controls("lblAcTitle").Caption = FrmRep.TxtLookup .Sections("Section2").Controls("lblDateFrom").Caption = Format(FrmRep.TxtFrom.Value, "dd/mm/yyyy") .Sections("Section2").Controls("lblDateTo").Caption = Format(FrmRep.TxtTo.Value, "dd/mm/yyyy")

.Sections("Section1").Controls("txtId").DataField = "SaleId" .Sections("Section1").Controls("txtDate").DataField = "SaleDate" .Sections("Section1").Controls("txtAcId").DataField = "AcId" .Sections("Section1").Controls("txtTitle").DataField = "AcTitle" .Sections("Section1").Controls("txtAmount").DataField = "TotalAmount" End With

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open "Select Sum(TotalAmount) from ViewRepSale where AcId = " & Val(FrmRep.TxtLookupCode) & " and SaleDate " & mDateQry, Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then Exit Sub End If

Me.Sections("Section5").Controls("lblTotal").Caption = Val(RS(0))

End Sub

11. dataRepSaleByDate.Dsr
This report is to display the sales details ordered by date. Coding:
Dim mDateQry As String Dim mTotal As Single Private Sub DataReport_Initialize()

mDateQry = " BETWEEN #" & FrmRep.TxtFrom.Value & "# And #" & FrmRep.TxtTo.Value & "#"

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close

RS.Open "Select * from ViewRepSale where SaleDate " & mDateQry, Con, adOpenStatic, adLockOptimistic

With Me Set .DataSource = RS .DataMember = RS.DataMember

.Sections("Section4").Controls("lbldate").Caption = "From " & Format(FrmRep.TxtFrom.Value, "dd/mm/yyyy") & " To " & Format(FrmRep.TxtTo.Value, "dd/mm/yyyy")

.Sections("Section1").Controls("txtId").DataField = "SaleId" .Sections("Section1").Controls("txtDate").DataField = "SaleDate" .Sections("Section1").Controls("txtAcId").DataField = "AcId" .Sections("Section1").Controls("txtTitle").DataField = "AcTitle" .Sections("Section1").Controls("txtAmount").DataField = "TotalAmount" End With

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(TotalAmount) from ViewRepSale where SaleDate " & mDateQry, Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then Exit Sub End If

Me.Sections("Section5").Controls("lblTotal").Caption = Val(RS(0))

End Sub

12. dataRepSaleByProduct.Dsr
This report is to display the sales details by product. Coding:
Dim mDateQry As String Private Sub DataReport_Initialize()

mDateQry = " BETWEEN #" & FrmRep.TxtFrom.Value & "# And #" & FrmRep.TxtTo.Value & "#"

Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select * from ViewSaleByProduct where ProdId = " & Val(FrmRep.TxtLookupCode) & " and SaleDate " & mDateQry, Con, adOpenStatic, adLockOptimistic

With Me Set .DataSource = RS .DataMember = RS.DataMember

.Sections("Section2").Controls("lblProdId").Caption = Val(FrmRep.TxtLookupCode) .Sections("Section2").Controls("lblProdName").Caption = FrmRep.TxtLookup .Sections("Section2").Controls("lblDateFrom").Caption = Format(FrmRep.TxtFrom.Value, "dd/mm/yyyy") .Sections("Section2").Controls("lblDateTo").Caption = Format(FrmRep.TxtTo.Value, "dd/mm/yyyy") 'DETAIL .Sections("Section1").Controls("txtDate").DataField = "SaleDate" .Sections("Section1").Controls("txtSaleId").DataField = "SaleId" .Sections("Section1").Controls("txtAcId").DataField = "AcId" .Sections("Section1").Controls("txtTitle").DataField = "AcTitle" .Sections("Section1").Controls("txtQty").DataField = "Qty" .Sections("Section1").Controls("txtPrice").DataField = "Price" .Sections("Section1").Controls("txtAmount").DataField = "Amount" End With

'Total Qty Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(Qty) from ViewSaleByProduct where ProdId = " & Val(FrmRep.TxtLookupCode) & " and SaleDate " & mDateQry, Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then Exit Sub End If

Me.Sections("Section5").Controls("lblTotalQty").Caption = Val(RS(0))

'Avg Price Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select AVG(Price) from ViewSaleByProduct where ProdId = " & Val(FrmRep.TxtLookupCode) & " and SaleDate " & mDateQry, Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then Exit Sub End If

Me.Sections("Section5").Controls("lblAvgPrice").Caption = Val(RS(0))

'Total Amount Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select Sum(Amount) from ViewSaleByProduct where ProdId = " & Val(FrmRep.TxtLookupCode) & " and SaleDate " & mDateQry, Con, adOpenStatic, adLockOptimistic If IsNull(RS(0)) Then Exit Sub End If

Me.Sections("Section5").Controls("lblTotalAmount").Caption = Val(RS(0))

End Sub

13. dataRepStockStatus.Dsr
This report is to display the status of the stock. Coding:
Private Sub DataReport_Initialize() Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select * from RepStockStatus", Con, adOpenStatic, adLockOptimistic

With Me Set .DataSource = RS .DataMember = RS.DataMember

.Sections("Section1").Controls("txtId").DataField = "ProductID" .Sections("Section1").Controls("txtName").DataField = "ProductName" .Sections("Section1").Controls("txtStock").DataField = "QtyInStock" .Sections("Section1").Controls("txtReOrder").DataField = "ReOrderPoint"

End With End Sub

14. dataTrial Balance.Dsr


This report is to display the trial balance. Coding:
Private Sub DataReport_Initialize() Me.Sections("Section4").Controls("LblDate").Caption = "As of " & Format(Date, "dd/mm/yyyy")

'Refreshing RepTrialBalance Table Set RS = New ADODB.Recordset If RS.State = 1 Then RS.Close RS.Open "Select * from RepTrialBalance", Con, adOpenStatic, adLockOptimistic RS.Requery Me.Sections("Section5").Controls("LblTotalDr").Caption = Val(TrialDr) Me.Sections("Section5").Controls("LblTotalCr").Caption = Val(TrialCr)

End Sub

USER INTERFACE

20

1. Login Screen

2. Main Menu

3. Account Creation

4. Purchase Entry

5. Sales Entry

6. Transactions Entry

7. Report Generation Menu

8. Reports

Вам также может понравиться