mirror of
https://github.com/dyiop/astute.git
synced 2025-04-05 13:00:16 -04:00
Fixed Final Invoice Number with the new logic
Function affected - generate_final_inv_number
This commit is contained in:
parent
8ed15ce2a7
commit
f623a8aaec
|
@ -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;
|
||||
else
|
||||
SET new_contact_id = 1;
|
||||
end if;
|
||||
END IF;
|
||||
INSERT INTO astute.customer_contact
|
||||
(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);
|
||||
|
@ -60,7 +60,7 @@ END;
|
|||
|
||||
|
||||
-- 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
|
||||
BEGIN
|
||||
DECLARE last_inserted_id varchar(20);
|
||||
|
@ -72,16 +72,16 @@ END;
|
|||
|
||||
|
||||
-- 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)
|
||||
BEGIN
|
||||
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);
|
||||
END//
|
||||
DELIMITER ;
|
||||
END;
|
||||
|
||||
|
||||
-- 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)
|
||||
BEGIN
|
||||
declare maxlineItemNo int;
|
||||
|
@ -93,25 +93,25 @@ if lineItemNum is null or lineItemNum = 0 then
|
|||
select max(line_Item_Num)+1 into maxlineItemNo from invoice_detail where inv_num = invoiceNum;
|
||||
else
|
||||
set maxlineItemNo = 1;
|
||||
end if;
|
||||
END IF;
|
||||
else
|
||||
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)
|
||||
VALUES (invoiceNum, maxlineItemNo, POLineItemNum, serviceTypeId, description, qty_in, fee_in, fee_type_id_in);
|
||||
END;
|
||||
|
||||
-- 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))
|
||||
BEGIN
|
||||
DECLARE next_po_id int(11);
|
||||
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 )
|
||||
VALUES (next_po_id, PONum, contractNum, PODate, contractAmt, customerId,astute_project_num_in, title_in, notes_in);
|
||||
END//
|
||||
DELIMITER ;
|
||||
END;
|
||||
|
||||
|
||||
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
|
||||
|
@ -125,10 +125,10 @@ if lineItemNo is null or lineItemNo = 0 then
|
|||
select max(line_item_no)+1 into maxlineItemNo from po_detail where po_num = ponum;
|
||||
else
|
||||
SET maxlineItemNo = 1;
|
||||
end if;
|
||||
END IF;
|
||||
else
|
||||
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)
|
||||
VALUES (POnum,maxlineItemNo,servicedesc,feetypeid,quantity,fee_in, servicetypeid, remaining_qty);
|
||||
END;
|
||||
|
@ -181,7 +181,7 @@ INSERT INTO `customer_contact` (`customer_id`, `contact_id`, `name`, `title`, `w
|
|||
/*!40000 ALTER TABLE `customer_contact` ENABLE KEYS */;
|
||||
|
||||
-- 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
|
||||
BEGIN
|
||||
|
||||
|
@ -200,20 +200,20 @@ BEGIN
|
|||
|
||||
RETURN 'SUCCESS';
|
||||
|
||||
END//
|
||||
DELIMITER ;
|
||||
END;
|
||||
|
||||
|
||||
-- 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
|
||||
BEGIN
|
||||
delete from customer_contact where customer_id = customer_id_in and contact_id = contact_id_in;
|
||||
RETURN 'Success';
|
||||
END//
|
||||
DELIMITER ;
|
||||
END;
|
||||
|
||||
|
||||
-- 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
|
||||
BEGIN
|
||||
|
||||
|
@ -234,11 +234,11 @@ BEGIN
|
|||
|
||||
RETURN 'SUCCESS';
|
||||
|
||||
END//
|
||||
DELIMITER ;
|
||||
END;
|
||||
|
||||
|
||||
-- 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
|
||||
BEGIN
|
||||
DECLARE generated_inv_number varchar(20);
|
||||
|
@ -266,8 +266,8 @@ BEGIN
|
|||
|
||||
return generated_inv_number;
|
||||
|
||||
END//
|
||||
DELIMITER ;
|
||||
END;
|
||||
|
||||
|
||||
-- Dumping structure for table astute.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 */;
|
||||
|
||||
-- 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
|
||||
BEGIN
|
||||
DECLARE customer_id_in varchar(10);
|
||||
DECLARE customer_code varchar(4);
|
||||
DECLARE po_count int;
|
||||
DECLARE inv_count int;
|
||||
DECLARE inv_number varchar(40);
|
||||
|
||||
SELECT customer_id
|
||||
INTO customer_id_in
|
||||
CREATE FUNCTION astute.`generate_final_inv_number`(po_num_in varchar(20)) RETURNS varchar(20) CHARSET utf8
|
||||
BEGIN
|
||||
|
||||
DECLARE _astute_project_num varchar(4);
|
||||
DECLARE _customer_id varchar(10);
|
||||
DECLARE inv_serial_no varchar(40);
|
||||
DECLARE inv_number varchar(20);
|
||||
|
||||
SELECT substr(astute_project_num,1,4)
|
||||
INTO _astute_project_num
|
||||
FROM po
|
||||
WHERE po.po_num = po_num_in;
|
||||
|
||||
SELECT substr(customer_id_in, 1, 3) INTO customer_code;
|
||||
|
||||
SELECT po_id
|
||||
INTO po_count
|
||||
SELECT customer_id
|
||||
INTO _customer_id
|
||||
FROM po
|
||||
WHERE PO_num = po_num_in;
|
||||
WHERE po.po_num = po_num_in;
|
||||
|
||||
SELECT inv_seq+1
|
||||
INTO inv_count
|
||||
INTO inv_serial_no
|
||||
FROM po
|
||||
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;
|
||||
|
||||
END//
|
||||
DELIMITER ;
|
||||
-- SELECT concat(customer_code, '-',LPAD(po_count, 2, '0'), '_', date_format(now(),'%m%d'),'_',inv_count) INTO inv_number;
|
||||
-- RETURN inv_number;
|
||||
|
||||
END;
|
||||
|
||||
|
||||
-- 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
|
||||
BEGIN
|
||||
DECLARE customer_id_in varchar(20);
|
||||
|
@ -349,21 +350,21 @@ BEGIN
|
|||
SELECT concat(customer_code, '-',LPAD(po_count, 2, '0'), '_DRAFT_',FLOOR(RAND()*(999))) INTO inv_number;
|
||||
RETURN inv_number;
|
||||
|
||||
END//
|
||||
DELIMITER ;
|
||||
END;
|
||||
|
||||
|
||||
-- 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
|
||||
BEGIN
|
||||
declare customer_id_out varchar(20);
|
||||
SELECT customer_id INTO customer_id_out FROM po WHERE po_num = ponum;
|
||||
return customer_id_out;
|
||||
END//
|
||||
DELIMITER ;
|
||||
END;
|
||||
|
||||
|
||||
-- Dumping structure for function astute.get_outstanding_inv_balance
|
||||
DELIMITER //
|
||||
|
||||
CREATE FUNCTION astute.`get_outstanding_inv_balance`(invno varchar(20)) RETURNS double(10,2)
|
||||
BEGIN
|
||||
declare outstanding_amt double(10,2);
|
||||
|
@ -372,28 +373,28 @@ BEGIN
|
|||
where invoice.inv_no = invno;
|
||||
|
||||
return outstanding_amt;
|
||||
END//
|
||||
DELIMITER ;
|
||||
END;
|
||||
|
||||
|
||||
-- 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
|
||||
BEGIN
|
||||
declare payment_status_name VARCHAR(20);
|
||||
SELECT payment_status_desc INTO payment_status_name FROM payment_status WHERE payment_status_id = pmt_status;
|
||||
return payment_status_name;
|
||||
END//
|
||||
DELIMITER ;
|
||||
END;
|
||||
|
||||
|
||||
-- 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
|
||||
BEGIN
|
||||
declare payment_type VARCHAR(20);
|
||||
SELECT payment_type_name INTO payment_type FROM payment_type WHERE payment_type_id = pmt_type;
|
||||
return payment_type;
|
||||
END//
|
||||
DELIMITER ;
|
||||
END;
|
||||
|
||||
|
||||
CREATE FUNCTION astute.`submit_invoice_fun`(invNo varchar(20)) RETURNS varchar(20) CHARSET utf8
|
||||
BEGIN
|
||||
|
@ -409,7 +410,7 @@ END;
|
|||
|
||||
|
||||
-- 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)
|
||||
BEGIN
|
||||
declare billed_amt double(10,2);
|
||||
|
@ -419,7 +420,7 @@ BEGIN
|
|||
return billed_amt;
|
||||
END;
|
||||
|
||||
DELIMITER ;
|
||||
|
||||
|
||||
-- Dumping structure for table astute.invoice
|
||||
CREATE TABLE `invoice` (
|
||||
|
@ -557,14 +558,14 @@ INSERT INTO `invoice_status` (`inv_status_id`, `inv_status_desc`) VALUES
|
|||
/*!40000 ALTER TABLE `invoice_status` ENABLE KEYS */;
|
||||
|
||||
-- Dumping structure for function astute.isAnyInvInDraft
|
||||
DELIMITER //
|
||||
|
||||
CREATE DEFINER=`root`@`localhost` FUNCTION `isAnyInvInDraft`(PO_num_in varchar(20)) RETURNS int(11)
|
||||
BEGIN
|
||||
declare isInvInDraft int;
|
||||
SELECT count(*) into isInvInDraft from invoice where po_num = PO_num_in and inv_status = 1;
|
||||
return isInvInDraft;
|
||||
END//
|
||||
DELIMITER ;
|
||||
END;
|
||||
|
||||
|
||||
-- Dumping structure for table astute.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 */;
|
||||
|
||||
-- Dumping structure for procedure astute.submit_invoice
|
||||
DELIMITER //
|
||||
|
||||
CREATE DEFINER=`root`@`localhost` PROCEDURE `submit_invoice`(invNo varchar(20))
|
||||
BEGIN
|
||||
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 PO SET INV_SEQ = INV_SEQ + 1 WHERE PO_NUM = po_no;
|
||||
Commit;
|
||||
END//
|
||||
DELIMITER ;
|
||||
END;
|
||||
|
||||
|
||||
CREATE FUNCTION astute.`get_remaining_qty_fun`(po_no_in varchar(40), inv_num_in varchar(40), item_no_in int) RETURNS double
|
||||
BEGIN
|
||||
|
@ -754,7 +755,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;
|
||||
else
|
||||
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
|
||||
where invoice_detail.inv_num in (select inv_no from invoice where invoice.PO_num = po_no)
|
||||
|
@ -768,7 +769,7 @@ and invoice_detail.po_line_item_num = po_detail.line_item_no;
|
|||
return rem_qty;
|
||||
END;
|
||||
-- Dumping structure for procedure astute.update_all_remaining_quantities
|
||||
DELIMITER //
|
||||
|
||||
DROP PROCEDURE IF EXISTS astute.update_all_remaining_quantities;
|
||||
CREATE PROCEDURE astute.`update_all_remaining_quantities`(invNo varchar(20))
|
||||
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);
|
||||
END;
|
||||
|
||||
DELIMITER ;
|
||||
|
||||
|
||||
CREATE FUNCTION astute.`get_draft_remaining_qty_fun`(inv_num_in varchar(40), item_no_in int) RETURNS double
|
||||
BEGIN
|
||||
|
@ -796,7 +797,7 @@ return submitted_qty-draft_qty;
|
|||
END;
|
||||
|
||||
-- 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
|
||||
BEGIN
|
||||
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;
|
||||
else
|
||||
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
|
||||
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;
|
||||
return rem_qty;
|
||||
END;
|
||||
DELIMITER ;
|
||||
|
||||
|
||||
CREATE FUNCTION astute.`is_po_fulfilled`(po_no varchar(20)) RETURNS int(1)
|
||||
BEGIN
|
||||
|
@ -829,7 +830,7 @@ BEGIN
|
|||
return 0;
|
||||
else
|
||||
return 1;
|
||||
end if;
|
||||
END IF;
|
||||
END;
|
||||
|
||||
-- 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 */;
|
||||
|
||||
-- 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';
|
||||
|
|
|
@ -56,7 +56,7 @@ public class POService extends Service{
|
|||
}
|
||||
|
||||
public void deletePO(String PONum) throws AstuteException {
|
||||
getDao().finalizePO(PONum);
|
||||
getDao().deletePO(PONum);
|
||||
}
|
||||
|
||||
public void deletePODetail(String PONum, int lineItemNo) throws AstuteException {
|
||||
|
|
Loading…
Reference in New Issue
Block a user