Separate Bill Receipts

0

I am in a situation where I need your help, I have a sales system made in Javafx (well it is more like a CRM), the fact is that in one of the modules is a billing or sales system, what happens is that for legal issues I have to correct or redo some entities of the database. I detail it:

Table goes out (Sale): - sale_id - sale_date - sale_state - customer_id - employee_id - sale_document (Invoice - Receipt) - sale_subtotal - sale_discount - sale_total

Product_sale table - sale_id - product_sale_id - product_sale_name - product_sale_unit - product_sale_price - product_sale_discount - product_sale_tax - product_sale_total

The fact is that due to legal issues in my country the invoices must be correlated by serial number and date, and it is recommended that the receipts follow the same rule (Although it is not mandatory, I want to respect it, to avoid problems with customers) . Well, the fact is that I used as invoice number the number of sales ie id_sale, and this generated me jumps in the series.

How could you solve this problem, that is, have the invoice numbers of the receipts independent, adding a field or creating another entity?

    
asked by Maurikius 05.11.2016 в 22:35
source

1 answer

0

what you must do is add a field, numerical, not consecutive, and generate your the consecutive one when saving a sale. For this you must use LIMIT, here I leave you information about this. Also here is an example:

SELECT nFactura
FROM t_sales
LIMIT 1
ORDER BY nFactura DESC

This will select the last number, so then what you should do is save that value in a variable, add one and save that value in the next sale.

    
answered by 07.11.2016 / 22:57
source