2

I am designing database for labor work invoice. In that I have following entities.

Labor_invoice_table(This is main table I have created)

  • Date
  • Invoice No. (PK)
  • Name of labor
  • Job Description
  • Amount per Job
  • Total Amount

Here I am confuse about Job Description and Amount per Job Invoice Line Item.On each Invoice I have multiple Jobs and for each Job its amount.

I search about it on google. Here also I found one useful detail link Found that I should create new Table

Labor_Job_Description

  • Invoice No.(FK parent Labor_invoice_table)
  • Job Description
  • Job Amount

So that multiple job can be stored in another Table.

Is it proper way? Or should I try something else?

Vijay Vankhede
  • 3,018
  • 1
  • 26
  • 46

2 Answers2

1

To generate a invoice you can use a query like

select ID,LabourName,InvoiceDate,Description,Amount From Invoice Inner join Invoice.ID = Labor_Job_Description.InvoiceID For total amount:

Select sum(amount) from Labor_Job_Description where Labor_Job_Description.InvoiceId= Insert will be something like this..

Insert into Invoice (InvoiceDate,LaborName) values (curdate(),'name');

set @invoiceID= LAST_INSERT_ID();

Insert into Labor_Job_Description (InvoiceNo,Description,Amount) values (@invoiceID,'desc', 10);

geniushkg
  • 706
  • 9
  • 21
0

You need relation for this.

May be you need many to many relation. Because each labor can have many job or each job can have many labor.

labor

  • id. (PK)
  • name_of_labor
  • Date

job

  • id(PK)
  • job_description
  • Job_amount

labor_job

  • labor_id.(FK parent invoice_table)
  • job_id.(FK parent labor_table)

Now you are ready for join query.

SELECT
 *
FROM
  labor_job AS lg
JOIN
   labor AS l ON lg.labor_id = l.id
JOIN
   job AS j ON lg.job = j.id
Imran
  • 3,031
  • 4
  • 25
  • 41