Fixed Final Invoice Number with the new logic

Function affected - generate_final_inv_number
This commit is contained in:
Gopi Katwala 2020-08-08 14:13:08 -04:00
parent 8ed15ce2a7
commit f623a8aaec
2 changed files with 115 additions and 114 deletions

View File

@ -50,7 +50,7 @@ if contactCount > 0 then
SELECT max(contact_id)+1 into new_contact_id FROM customer_contact where customer_id = customer_id_in; SELECT max(contact_id)+1 into new_contact_id FROM customer_contact where customer_id = customer_id_in;
else else
SET new_contact_id = 1; SET new_contact_id = 1;
end if; END IF;
INSERT INTO astute.customer_contact INSERT INTO astute.customer_contact
(customer_id, contact_id, name, title, work_phone, work_phone_ext, mobile, fax, email, address) (customer_id, contact_id, name, title, work_phone, work_phone_ext, mobile, fax, email, address)
VALUES (customer_id_in, new_contact_id, name, title, work_phone, work_phone_ext, mobile, fax, email, address); VALUES (customer_id_in, new_contact_id, name, title, work_phone, work_phone_ext, mobile, fax, email, address);
@ -60,7 +60,7 @@ END;
-- Dumping structure for function astute.create_customer_fun -- Dumping structure for function astute.create_customer_fun
DELIMITER //
CREATE FUNCTION astute.`create_customer_fun`(customerid varchar(20), customerName varchar(100), billToDept varchar(100), add1In varchar(100), add2In varchar(100), cityIn varchar(50), stateIn varchar(20), zipIn int(5), zipLast4In int(4), emailIn varchar(50), phoneIn varchar(20), extIn int(6), faxIn varchar(20)) RETURNS varchar(20) CHARSET utf8 CREATE FUNCTION astute.`create_customer_fun`(customerid varchar(20), customerName varchar(100), billToDept varchar(100), add1In varchar(100), add2In varchar(100), cityIn varchar(50), stateIn varchar(20), zipIn int(5), zipLast4In int(4), emailIn varchar(50), phoneIn varchar(20), extIn int(6), faxIn varchar(20)) RETURNS varchar(20) CHARSET utf8
BEGIN BEGIN
DECLARE last_inserted_id varchar(20); DECLARE last_inserted_id varchar(20);
@ -72,16 +72,16 @@ END;
-- Dumping structure for procedure astute.create_invoice -- Dumping structure for procedure astute.create_invoice
DELIMITER //
CREATE DEFINER=`root`@`localhost` PROCEDURE `create_invoice`(invNo varchar(20),invDate date,PONo varchar(20),paymentStatus int,billAmt double,specialNotes varchar(500), certClause Varchar(500), invoiceStatus int) CREATE DEFINER=`root`@`localhost` PROCEDURE `create_invoice`(invNo varchar(20),invDate date,PONo varchar(20),paymentStatus int,billAmt double,specialNotes varchar(500), certClause Varchar(500), invoiceStatus int)
BEGIN BEGIN
INSERT INTO invoice (inv_no,inv_date,PO_num,pmt_status,bill_amt,special_notes,certification,inv_status) INSERT INTO invoice (inv_no,inv_date,PO_num,pmt_status,bill_amt,special_notes,certification,inv_status)
VALUES (invNo, invDate, PONo, 1, billAmt, specialNotes, certClause, invoiceStatus); VALUES (invNo, invDate, PONo, 1, billAmt, specialNotes, certClause, invoiceStatus);
END// END;
DELIMITER ;
-- Dumping structure for procedure astute.create_invoice_detail -- Dumping structure for procedure astute.create_invoice_detail
DELIMITER //
CREATE PROCEDURE astute.`create_invoice_detail`(invoiceNum varchar(20), lineItemNum int, POLineItemNum varchar(20), serviceTypeId int, description varchar(500), qty_in double, fee_in double, fee_type_id_in int) CREATE PROCEDURE astute.`create_invoice_detail`(invoiceNum varchar(20), lineItemNum int, POLineItemNum varchar(20), serviceTypeId int, description varchar(500), qty_in double, fee_in double, fee_type_id_in int)
BEGIN BEGIN
declare maxlineItemNo int; declare maxlineItemNo int;
@ -89,29 +89,29 @@ DECLARE detailCount int;
SELECT COUNT(line_item_num) INTO detailCount FROM invoice_detail where inv_num = invoiceNum; SELECT COUNT(line_item_num) INTO detailCount FROM invoice_detail where inv_num = invoiceNum;
if lineItemNum is null or lineItemNum = 0 then if lineItemNum is null or lineItemNum = 0 then
if detailCount > 0 then if detailCount > 0 then
select max(line_Item_Num)+1 into maxlineItemNo from invoice_detail where inv_num = invoiceNum; select max(line_Item_Num)+1 into maxlineItemNo from invoice_detail where inv_num = invoiceNum;
else else
set maxlineItemNo = 1; set maxlineItemNo = 1;
end if; END IF;
else else
set maxlineItemNo = lineItemNum; set maxlineItemNo = lineItemNum;
end if; END IF;
INSERT INTO INVOICE_DETAIL (inv_num, line_item_num, PO_line_item_num, service_type_id, description, qty, fee, fee_type_id) INSERT INTO INVOICE_DETAIL (inv_num, line_item_num, PO_line_item_num, service_type_id, description, qty, fee, fee_type_id)
VALUES (invoiceNum, maxlineItemNo, POLineItemNum, serviceTypeId, description, qty_in, fee_in, fee_type_id_in); VALUES (invoiceNum, maxlineItemNo, POLineItemNum, serviceTypeId, description, qty_in, fee_in, fee_type_id_in);
END; END;
-- Dumping structure for procedure astute.create_po -- Dumping structure for procedure astute.create_po
DELIMITER //
CREATE DEFINER=`root`@`localhost` PROCEDURE `create_po`(PONum varchar(40), contractNum varchar(20), PODate date, contractAmt double(10,2), customerid varchar(20), astute_project_num_in varchar(20), title_in varchar(200), notes_in varchar(200)) CREATE DEFINER=`root`@`localhost` PROCEDURE `create_po`(PONum varchar(40), contractNum varchar(20), PODate date, contractAmt double(10,2), customerid varchar(20), astute_project_num_in varchar(20), title_in varchar(200), notes_in varchar(200))
BEGIN BEGIN
DECLARE next_po_id int(11); DECLARE next_po_id int(11);
SELECT count(*) + 1 INTO next_po_id FROM PO WHERE customer_id = customerid; SELECT count(*) + 1 INTO next_po_id FROM PO WHERE customer_id = customerid;
INSERT INTO PO (po_id, PO_num, contract_num, PO_date, contract_amt, customer_id,astute_project_num, title, notes ) INSERT INTO PO (po_id, PO_num, contract_num, PO_date, contract_amt, customer_id,astute_project_num, title, notes )
VALUES (next_po_id, PONum, contractNum, PODate, contractAmt, customerId,astute_project_num_in, title_in, notes_in); VALUES (next_po_id, PONum, contractNum, PODate, contractAmt, customerId,astute_project_num_in, title_in, notes_in);
END// END;
DELIMITER ;
CREATE PROCEDURE astute.`create_po_detail`(PONum varchar(40), lineItemNo int, servicedesc varchar(500), feetypeid int(11), quantity double, fee_in double, servicetypeid int(1), remaining_qty double) CREATE PROCEDURE astute.`create_po_detail`(PONum varchar(40), lineItemNo int, servicedesc varchar(500), feetypeid int(11), quantity double, fee_in double, servicetypeid int(1), remaining_qty double)
BEGIN BEGIN
@ -123,12 +123,12 @@ SELECT COUNT(line_item_no) INTO podetailCount FROM po_detail where po_num = ponu
if lineItemNo is null or lineItemNo = 0 then if lineItemNo is null or lineItemNo = 0 then
if podetailCount > 0 then if podetailCount > 0 then
select max(line_item_no)+1 into maxlineItemNo from po_detail where po_num = ponum; select max(line_item_no)+1 into maxlineItemNo from po_detail where po_num = ponum;
else else
SET maxlineItemNo = 1; SET maxlineItemNo = 1;
end if; END IF;
else else
set maxlineItemNo = lineItemNo; set maxlineItemNo = lineItemNo;
end if; END IF;
INSERT INTO PO_DETAIL (PO_num,line_item_no,service_desc,fee_type_id,qty,fee,service_type_id, remaining_qty) INSERT INTO PO_DETAIL (PO_num,line_item_no,service_desc,fee_type_id,qty,fee,service_type_id, remaining_qty)
VALUES (POnum,maxlineItemNo,servicedesc,feetypeid,quantity,fee_in, servicetypeid, remaining_qty); VALUES (POnum,maxlineItemNo,servicedesc,feetypeid,quantity,fee_in, servicetypeid, remaining_qty);
END; END;
@ -181,93 +181,93 @@ INSERT INTO `customer_contact` (`customer_id`, `contact_id`, `name`, `title`, `w
/*!40000 ALTER TABLE `customer_contact` ENABLE KEYS */; /*!40000 ALTER TABLE `customer_contact` ENABLE KEYS */;
-- Dumping structure for function astute.delete_customer -- Dumping structure for function astute.delete_customer
DELIMITER //
CREATE DEFINER=`root`@`localhost` FUNCTION `delete_customer`(customer_id_in varchar(10)) RETURNS varchar(100) CHARSET utf8 CREATE DEFINER=`root`@`localhost` FUNCTION `delete_customer`(customer_id_in varchar(10)) RETURNS varchar(100) CHARSET utf8
BEGIN BEGIN
DECLARE po_count int; DECLARE po_count int;
SELECT count(*) SELECT count(*)
INTO po_count INTO po_count
FROM po FROM po
WHERE customer_id = customer_id_in; WHERE customer_id = customer_id_in;
IF po_count > 0 THEN IF po_count > 0 THEN
RETURN 'ERROR - Customer with Sales orders can not be deleted'; RETURN 'ERROR - Customer with Sales orders can not be deleted';
END IF; END IF;
delete from customer where customer_id = customer_id_in; delete from customer where customer_id = customer_id_in;
RETURN 'SUCCESS'; RETURN 'SUCCESS';
END// END;
DELIMITER ;
-- Dumping structure for function astute.delete_customer_contact -- Dumping structure for function astute.delete_customer_contact
DELIMITER //
CREATE DEFINER=`root`@`localhost` FUNCTION `delete_customer_contact`(customer_id_in varchar(20), contact_id_in int) RETURNS varchar(20) CHARSET utf8 CREATE DEFINER=`root`@`localhost` FUNCTION `delete_customer_contact`(customer_id_in varchar(20), contact_id_in int) RETURNS varchar(20) CHARSET utf8
BEGIN BEGIN
delete from customer_contact where customer_id = customer_id_in and contact_id = contact_id_in; delete from customer_contact where customer_id = customer_id_in and contact_id = contact_id_in;
RETURN 'Success'; RETURN 'Success';
END// END;
DELIMITER ;
-- Dumping structure for function astute.delete_invoice -- Dumping structure for function astute.delete_invoice
DELIMITER //
CREATE DEFINER=`root`@`localhost` FUNCTION `delete_invoice`(inv_no_in varchar(20)) RETURNS varchar(40) CHARSET utf8 CREATE DEFINER=`root`@`localhost` FUNCTION `delete_invoice`(inv_no_in varchar(20)) RETURNS varchar(40) CHARSET utf8
BEGIN BEGIN
DECLARE inv_status_in int; DECLARE inv_status_in int;
SELECT inv_status SELECT inv_status
INTO inv_status_in INTO inv_status_in
FROM invoice FROM invoice
WHERE inv_no = inv_no_in; WHERE inv_no = inv_no_in;
IF inv_status_in <> 1 THEN IF inv_status_in <> 1 THEN
RETURN 'ERROR - ONLY DRAFT INVOICE CAN BE DELETED'; RETURN 'ERROR - ONLY DRAFT INVOICE CAN BE DELETED';
END IF; END IF;
UPDATE INVOICE_DETAIL SET QTY = 0 WHERE inv_num = inv_no_in; UPDATE INVOICE_DETAIL SET QTY = 0 WHERE inv_num = inv_no_in;
CALL update_all_remaining_quantities(inv_no_in); CALL update_all_remaining_quantities(inv_no_in);
DELETE FROM INVOICE WHERE inv_no = inv_no_in; DELETE FROM INVOICE WHERE inv_no = inv_no_in;
RETURN 'SUCCESS'; RETURN 'SUCCESS';
END// END;
DELIMITER ;
-- Dumping structure for function astute.duplicate_invoice -- Dumping structure for function astute.duplicate_invoice
DELIMITER //
CREATE DEFINER=`root`@`localhost` FUNCTION `duplicate_invoice`(inv_no_in varchar(20)) RETURNS varchar(20) CHARSET utf8 CREATE DEFINER=`root`@`localhost` FUNCTION `duplicate_invoice`(inv_no_in varchar(20)) RETURNS varchar(20) CHARSET utf8
BEGIN BEGIN
DECLARE generated_inv_number varchar(20); DECLARE generated_inv_number varchar(20);
DECLARE po_num_in varchar(20); DECLARE po_num_in varchar(20);
SELECT po_num SELECT po_num
INTO po_num_in INTO po_num_in
FROM invoice FROM invoice
WHERE inv_no = inv_no_in; WHERE inv_no = inv_no_in;
SELECT generate_inv_number(po_num_in) SELECT generate_inv_number(po_num_in)
INTO generated_inv_number; INTO generated_inv_number;
INSERT INTO invoice INSERT INTO invoice
(inv_no,inv_date,PO_num,change_order_num,bill_amt,special_notes,certification,inv_status,pmt_status) (inv_no,inv_date,PO_num,change_order_num,bill_amt,special_notes,certification,inv_status,pmt_status)
(SELECT generated_inv_number, CURDATE(), PO_num, change_order_num, bill_amt, special_notes, certification, inv_status, pmt_status (SELECT generated_inv_number, CURDATE(), PO_num, change_order_num, bill_amt, special_notes, certification, inv_status, pmt_status
FROM invoice FROM invoice
WHERE inv_no = inv_no_in); WHERE inv_no = inv_no_in);
INSERT INTO invoice_detail INSERT INTO invoice_detail
(inv_num,line_item_num,PO_line_item_num,service_type_id,description,qty,fee,fee_type_id) (inv_num,line_item_num,PO_line_item_num,service_type_id,description,qty,fee,fee_type_id)
(SELECT generated_inv_number, line_item_num, PO_line_item_num, service_type_id, description, 0, fee, fee_type_id (SELECT generated_inv_number, line_item_num, PO_line_item_num, service_type_id, description, 0, fee, fee_type_id
FROM invoice_detail FROM invoice_detail
WHERE inv_num = inv_no_in); WHERE inv_num = inv_no_in);
return generated_inv_number; return generated_inv_number;
END// END;
DELIMITER ;
-- Dumping structure for table astute.fee_type -- Dumping structure for table astute.fee_type
CREATE TABLE IF NOT EXISTS `fee_type` ( CREATE TABLE IF NOT EXISTS `fee_type` (
@ -284,40 +284,41 @@ INSERT INTO `fee_type` (`fee_type_id`, `fee_type_desc`) VALUES
/*!40000 ALTER TABLE `fee_type` ENABLE KEYS */; /*!40000 ALTER TABLE `fee_type` ENABLE KEYS */;
-- Dumping structure for function astute.generate_final_inv_number -- Dumping structure for function astute.generate_final_inv_number
DELIMITER //
CREATE DEFINER=`root`@`localhost` FUNCTION `generate_final_inv_number`(po_num_in varchar(20)) RETURNS varchar(40) CHARSET utf8 CREATE FUNCTION astute.`generate_final_inv_number`(po_num_in varchar(20)) RETURNS varchar(20) CHARSET utf8
BEGIN BEGIN
DECLARE customer_id_in varchar(10);
DECLARE customer_code varchar(4); DECLARE _astute_project_num varchar(4);
DECLARE po_count int; DECLARE _customer_id varchar(10);
DECLARE inv_count int; DECLARE inv_serial_no varchar(40);
DECLARE inv_number varchar(40); DECLARE inv_number varchar(20);
SELECT customer_id SELECT substr(astute_project_num,1,4)
INTO customer_id_in INTO _astute_project_num
FROM po FROM po
WHERE po.po_num = po_num_in; WHERE po.po_num = po_num_in;
SELECT substr(customer_id_in, 1, 3) INTO customer_code; SELECT customer_id
INTO _customer_id
SELECT po_id
INTO po_count
FROM po FROM po
WHERE PO_num = po_num_in; WHERE po.po_num = po_num_in;
SELECT inv_seq+1 SELECT inv_seq+1
INTO inv_count INTO inv_serial_no
FROM po FROM po
WHERE po.PO_num = po_num_in; WHERE po.PO_num = po_num_in;
SELECT concat(customer_code, '-',LPAD(po_count, 2, '0'), '_', date_format(now(),'%m%d'),'_',inv_count) INTO inv_number; SELECT concat(_astute_project_num, '-',_customer_id, '_', date_format(now(),'%y%m'),'-',inv_serial_no) INTO inv_number;
RETURN inv_number; RETURN inv_number;
END// -- SELECT concat(customer_code, '-',LPAD(po_count, 2, '0'), '_', date_format(now(),'%m%d'),'_',inv_count) INTO inv_number;
DELIMITER ; -- RETURN inv_number;
END;
-- Dumping structure for function astute.generate_inv_number -- Dumping structure for function astute.generate_inv_number
DELIMITER //
CREATE DEFINER=`root`@`localhost` FUNCTION `generate_inv_number`(po_num_in varchar(20)) RETURNS varchar(40) CHARSET utf8 CREATE DEFINER=`root`@`localhost` FUNCTION `generate_inv_number`(po_num_in varchar(20)) RETURNS varchar(40) CHARSET utf8
BEGIN BEGIN
DECLARE customer_id_in varchar(20); DECLARE customer_id_in varchar(20);
@ -325,17 +326,17 @@ BEGIN
DECLARE po_count int; DECLARE po_count int;
DECLARE inv_count int; DECLARE inv_count int;
DECLARE inv_number varchar(40); DECLARE inv_number varchar(40);
SELECT customer_id SELECT customer_id
INTO customer_id_in INTO customer_id_in
FROM po FROM po
WHERE po.po_num = po_num_in; WHERE po.po_num = po_num_in;
SELECT substr(customer.customer_id, 1, 3) SELECT substr(customer.customer_id, 1, 3)
INTO customer_code INTO customer_code
FROM customer FROM customer
WHERE customer_id = customer_id_in; WHERE customer_id = customer_id_in;
SELECT po_id SELECT po_id
INTO po_count INTO po_count
FROM po FROM po
@ -344,26 +345,26 @@ BEGIN
SELECT inv_seq + 1 SELECT inv_seq + 1
INTO inv_count INTO inv_count
FROM PO FROM PO
WHERE PO.PO_num = po_num_in; WHERE PO.PO_num = po_num_in;
SELECT concat(customer_code, '-',LPAD(po_count, 2, '0'), '_DRAFT_',FLOOR(RAND()*(999))) INTO inv_number; SELECT concat(customer_code, '-',LPAD(po_count, 2, '0'), '_DRAFT_',FLOOR(RAND()*(999))) INTO inv_number;
RETURN inv_number; RETURN inv_number;
END// END;
DELIMITER ;
-- Dumping structure for function astute.get_customer_from_po -- Dumping structure for function astute.get_customer_from_po
DELIMITER //
CREATE DEFINER=`root`@`localhost` FUNCTION `get_customer_from_po`(ponum varchar(20)) RETURNS varchar(20) CHARSET utf8 CREATE DEFINER=`root`@`localhost` FUNCTION `get_customer_from_po`(ponum varchar(20)) RETURNS varchar(20) CHARSET utf8
BEGIN BEGIN
declare customer_id_out varchar(20); declare customer_id_out varchar(20);
SELECT customer_id INTO customer_id_out FROM po WHERE po_num = ponum; SELECT customer_id INTO customer_id_out FROM po WHERE po_num = ponum;
return customer_id_out; return customer_id_out;
END// END;
DELIMITER ;
-- Dumping structure for function astute.get_outstanding_inv_balance -- Dumping structure for function astute.get_outstanding_inv_balance
DELIMITER //
CREATE FUNCTION astute.`get_outstanding_inv_balance`(invno varchar(20)) RETURNS double(10,2) CREATE FUNCTION astute.`get_outstanding_inv_balance`(invno varchar(20)) RETURNS double(10,2)
BEGIN BEGIN
declare outstanding_amt double(10,2); declare outstanding_amt double(10,2);
@ -372,28 +373,28 @@ BEGIN
where invoice.inv_no = invno; where invoice.inv_no = invno;
return outstanding_amt; return outstanding_amt;
END// END;
DELIMITER ;
-- Dumping structure for function astute.get_payment_status_name -- Dumping structure for function astute.get_payment_status_name
DELIMITER //
CREATE DEFINER=`root`@`localhost` FUNCTION `get_payment_status_name`(pmt_status int) RETURNS varchar(20) CHARSET utf8 CREATE DEFINER=`root`@`localhost` FUNCTION `get_payment_status_name`(pmt_status int) RETURNS varchar(20) CHARSET utf8
BEGIN BEGIN
declare payment_status_name VARCHAR(20); declare payment_status_name VARCHAR(20);
SELECT payment_status_desc INTO payment_status_name FROM payment_status WHERE payment_status_id = pmt_status; SELECT payment_status_desc INTO payment_status_name FROM payment_status WHERE payment_status_id = pmt_status;
return payment_status_name; return payment_status_name;
END// END;
DELIMITER ;
-- Dumping structure for function astute.get_payment_type -- Dumping structure for function astute.get_payment_type
DELIMITER //
CREATE DEFINER=`root`@`localhost` FUNCTION `get_payment_type`(pmt_type int) RETURNS varchar(20) CHARSET utf8 CREATE DEFINER=`root`@`localhost` FUNCTION `get_payment_type`(pmt_type int) RETURNS varchar(20) CHARSET utf8
BEGIN BEGIN
declare payment_type VARCHAR(20); declare payment_type VARCHAR(20);
SELECT payment_type_name INTO payment_type FROM payment_type WHERE payment_type_id = pmt_type; SELECT payment_type_name INTO payment_type FROM payment_type WHERE payment_type_id = pmt_type;
return payment_type; return payment_type;
END// END;
DELIMITER ;
CREATE FUNCTION astute.`submit_invoice_fun`(invNo varchar(20)) RETURNS varchar(20) CHARSET utf8 CREATE FUNCTION astute.`submit_invoice_fun`(invNo varchar(20)) RETURNS varchar(20) CHARSET utf8
BEGIN BEGIN
@ -409,7 +410,7 @@ END;
-- Dumping structure for function astute.get_previously_billed_amt -- Dumping structure for function astute.get_previously_billed_amt
DELIMITER //
CREATE FUNCTION astute.`get_previously_billed_amt`(po_no varchar(20), inv_no_in varchar(20)) RETURNS double(10,2) CREATE FUNCTION astute.`get_previously_billed_amt`(po_no varchar(20), inv_no_in varchar(20)) RETURNS double(10,2)
BEGIN BEGIN
declare billed_amt double(10,2); declare billed_amt double(10,2);
@ -419,7 +420,7 @@ BEGIN
return billed_amt; return billed_amt;
END; END;
DELIMITER ;
-- Dumping structure for table astute.invoice -- Dumping structure for table astute.invoice
CREATE TABLE `invoice` ( CREATE TABLE `invoice` (
@ -467,7 +468,7 @@ CREATE TABLE IF NOT EXISTS `invoice_detail` (
CREATE DEFINER=`root`@`localhost` TRIGGER `astute`.`after_invoice_detail_delete` AFTER DELETE ON astute.invoice_detail FOR EACH ROW CREATE DEFINER=`root`@`localhost` TRIGGER `astute`.`after_invoice_detail_delete` AFTER DELETE ON astute.invoice_detail FOR EACH ROW
BEGIN BEGIN
UPDATE invoice UPDATE invoice
SET bill_amt = (SELECT SUM(QTY*FEE) FROM invoice_detail WHERE invoice_detail.inv_num = OLD.inv_num) SET bill_amt = (SELECT SUM(QTY*FEE) FROM invoice_detail WHERE invoice_detail.inv_num = OLD.inv_num)
WHERE inv_no = OLD.inv_num; WHERE inv_no = OLD.inv_num;
END; END;
@ -484,7 +485,7 @@ BEGIN
SET bill_amt = (SELECT SUM(QTY*FEE) FROM invoice_detail WHERE invoice_detail.inv_num = OLD.inv_num) SET bill_amt = (SELECT SUM(QTY*FEE) FROM invoice_detail WHERE invoice_detail.inv_num = OLD.inv_num)
WHERE inv_no = OLD.inv_num; WHERE inv_no = OLD.inv_num;
END; END;
-- Dumping data for table astute.invoice_detail: ~14 rows (approximately) -- Dumping data for table astute.invoice_detail: ~14 rows (approximately)
/*!40000 ALTER TABLE `invoice_detail` DISABLE KEYS */; /*!40000 ALTER TABLE `invoice_detail` DISABLE KEYS */;
INSERT INTO `invoice_detail` (`inv_num`, `line_item_num`, `PO_line_item_num`, `service_type_id`, `description`, `qty`, `fee`, `fee_type_id`) VALUES INSERT INTO `invoice_detail` (`inv_num`, `line_item_num`, `PO_line_item_num`, `service_type_id`, `description`, `qty`, `fee`, `fee_type_id`) VALUES
@ -557,14 +558,14 @@ INSERT INTO `invoice_status` (`inv_status_id`, `inv_status_desc`) VALUES
/*!40000 ALTER TABLE `invoice_status` ENABLE KEYS */; /*!40000 ALTER TABLE `invoice_status` ENABLE KEYS */;
-- Dumping structure for function astute.isAnyInvInDraft -- Dumping structure for function astute.isAnyInvInDraft
DELIMITER //
CREATE DEFINER=`root`@`localhost` FUNCTION `isAnyInvInDraft`(PO_num_in varchar(20)) RETURNS int(11) CREATE DEFINER=`root`@`localhost` FUNCTION `isAnyInvInDraft`(PO_num_in varchar(20)) RETURNS int(11)
BEGIN BEGIN
declare isInvInDraft int; declare isInvInDraft int;
SELECT count(*) into isInvInDraft from invoice where po_num = PO_num_in and inv_status = 1; SELECT count(*) into isInvInDraft from invoice where po_num = PO_num_in and inv_status = 1;
return isInvInDraft; return isInvInDraft;
END// END;
DELIMITER ;
-- Dumping structure for table astute.payment_status -- Dumping structure for table astute.payment_status
CREATE TABLE IF NOT EXISTS `payment_status` ( CREATE TABLE IF NOT EXISTS `payment_status` (
@ -734,7 +735,7 @@ INSERT INTO `session` (`session_id`, `user_id`, `session_start_date`, `session_e
/*!40000 ALTER TABLE `session` ENABLE KEYS */; /*!40000 ALTER TABLE `session` ENABLE KEYS */;
-- Dumping structure for procedure astute.submit_invoice -- Dumping structure for procedure astute.submit_invoice
DELIMITER //
CREATE DEFINER=`root`@`localhost` PROCEDURE `submit_invoice`(invNo varchar(20)) CREATE DEFINER=`root`@`localhost` PROCEDURE `submit_invoice`(invNo varchar(20))
BEGIN BEGIN
DECLARE po_no varchar(20); DECLARE po_no varchar(20);
@ -743,8 +744,8 @@ SELECT PO_NUM INTO po_no FROM INVOICE WHERE INV_NO = invNo;
UPDATE INVOICE SET INV_NO = generate_final_inv_number(po_no), INV_STATUS = 2 WHERE INV_NO = invNo; UPDATE INVOICE SET INV_NO = generate_final_inv_number(po_no), INV_STATUS = 2 WHERE INV_NO = invNo;
UPDATE PO SET INV_SEQ = INV_SEQ + 1 WHERE PO_NUM = po_no; UPDATE PO SET INV_SEQ = INV_SEQ + 1 WHERE PO_NUM = po_no;
Commit; Commit;
END// END;
DELIMITER ;
CREATE FUNCTION astute.`get_remaining_qty_fun`(po_no_in varchar(40), inv_num_in varchar(40), item_no_in int) RETURNS double CREATE FUNCTION astute.`get_remaining_qty_fun`(po_no_in varchar(40), inv_num_in varchar(40), item_no_in int) RETURNS double
BEGIN BEGIN
@ -752,23 +753,23 @@ DECLARE rem_qty double;
DECLARE po_no varchar(40); DECLARE po_no varchar(40);
if inv_num_in <> null or inv_num_in <> '' THEN if inv_num_in <> null or inv_num_in <> '' THEN
SELECT po_num INTO po_no FROM invoice where inv_no = inv_num_in; SELECT po_num INTO po_no FROM invoice where inv_no = inv_num_in;
else else
set po_no = po_no_in; set po_no = po_no_in;
end if; END IF;
select po_detail.qty - ifnull(sum(invoice_detail.qty),0) into rem_qty from invoice_detail, invoice, po_detail select po_detail.qty - ifnull(sum(invoice_detail.qty),0) into rem_qty from invoice_detail, invoice, po_detail
where invoice_detail.inv_num in (select inv_no from invoice where invoice.PO_num = po_no) where invoice_detail.inv_num in (select inv_no from invoice where invoice.PO_num = po_no)
and invoice_detail.po_line_item_num = item_no_in and invoice_detail.po_line_item_num = item_no_in
and po_detail.PO_num = po_no and po_detail.PO_num = po_no
and invoice.PO_num = po_detail.PO_num and invoice.PO_num = po_detail.PO_num
and invoice.inv_no = invoice_detail.inv_num and invoice.inv_no = invoice_detail.inv_num
and (invoice.inv_status = 2) and (invoice.inv_status = 2)
and invoice_detail.po_line_item_num = po_detail.line_item_no; and invoice_detail.po_line_item_num = po_detail.line_item_no;
return rem_qty; return rem_qty;
END; END;
-- Dumping structure for procedure astute.update_all_remaining_quantities -- Dumping structure for procedure astute.update_all_remaining_quantities
DELIMITER //
DROP PROCEDURE IF EXISTS astute.update_all_remaining_quantities; DROP PROCEDURE IF EXISTS astute.update_all_remaining_quantities;
CREATE PROCEDURE astute.`update_all_remaining_quantities`(invNo varchar(20)) CREATE PROCEDURE astute.`update_all_remaining_quantities`(invNo varchar(20))
BEGIN BEGIN
@ -779,7 +780,7 @@ SELECT PO_NUM INTO po_num_in FROM invoice where inv_no = invNo;
UPDATE PO_DETAIL SET remaining_qty = get_remaining_qty_fun(po_num_in,'',line_item_no); UPDATE PO_DETAIL SET remaining_qty = get_remaining_qty_fun(po_num_in,'',line_item_no);
END; END;
DELIMITER ;
CREATE FUNCTION astute.`get_draft_remaining_qty_fun`(inv_num_in varchar(40), item_no_in int) RETURNS double CREATE FUNCTION astute.`get_draft_remaining_qty_fun`(inv_num_in varchar(40), item_no_in int) RETURNS double
BEGIN BEGIN
@ -796,7 +797,7 @@ return submitted_qty-draft_qty;
END; END;
-- Dumping structure for function astute.update_remaining_qty_fun -- Dumping structure for function astute.update_remaining_qty_fun
DELIMITER //
CREATE FUNCTION astute.`update_remaining_qty_fun`(po_no_in varchar(40), inv_num_in varchar(40), item_no_in int) RETURNS double CREATE FUNCTION astute.`update_remaining_qty_fun`(po_no_in varchar(40), inv_num_in varchar(40), item_no_in int) RETURNS double
BEGIN BEGIN
DECLARE rem_qty double; DECLARE rem_qty double;
@ -805,7 +806,7 @@ if inv_num_in <> null or inv_num_in <> '' THEN
SELECT po_num INTO po_no FROM invoice where inv_no = inv_num_in; SELECT po_num INTO po_no FROM invoice where inv_no = inv_num_in;
else else
set po_no = po_no_in; set po_no = po_no_in;
end if; END IF;
select po_detail.qty - ifnull(sum(invoice_detail.qty),0) into rem_qty from invoice_detail, invoice, po_detail select po_detail.qty - ifnull(sum(invoice_detail.qty),0) into rem_qty from invoice_detail, invoice, po_detail
where invoice_detail.inv_num in (select inv_no from invoice where invoice.PO_num = po_no) where invoice_detail.inv_num in (select inv_no from invoice where invoice.PO_num = po_no)
@ -819,7 +820,7 @@ and invoice_detail.po_line_item_num = po_detail.line_item_no;
update po_detail set remaining_qty = rem_qty where PO_num = po_no and line_item_no = item_no_in; update po_detail set remaining_qty = rem_qty where PO_num = po_no and line_item_no = item_no_in;
return rem_qty; return rem_qty;
END; END;
DELIMITER ;
CREATE FUNCTION astute.`is_po_fulfilled`(po_no varchar(20)) RETURNS int(1) CREATE FUNCTION astute.`is_po_fulfilled`(po_no varchar(20)) RETURNS int(1)
BEGIN BEGIN
@ -829,7 +830,7 @@ BEGIN
return 0; return 0;
else else
return 1; return 1;
end if; END IF;
END; END;
-- Dumping structure for table astute.user -- Dumping structure for table astute.user
@ -859,5 +860,5 @@ INSERT INTO `user` (`user_id`, `username`, `password`, `first_name`, `middle_nam
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
-- create and GRANT ALL PRIVILEGES ON *.* TO 'astute_user'@'localhost' IDENTIFIED BY 'password'; -- create and GRANT ALL PRIVILEGES ON *.* TO 'astute_user'@'localhost' IDENTIFIED BY 'password';
CREATE USER 'astute_user'@'localhost' IDENTIFIED BY 'password'; -- CREATE USER 'astute_user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'astute_user'@'localhost'; GRANT ALL PRIVILEGES ON * . * TO 'astute_user'@'localhost';

View File

@ -56,7 +56,7 @@ public class POService extends Service{
} }
public void deletePO(String PONum) throws AstuteException { public void deletePO(String PONum) throws AstuteException {
getDao().finalizePO(PONum); getDao().deletePO(PONum);
} }
public void deletePODetail(String PONum, int lineItemNo) throws AstuteException { public void deletePODetail(String PONum, int lineItemNo) throws AstuteException {