diff --git a/ALL SCHEMA/ALTER TABLE.txt b/ALL SCHEMA/ALTER TABLE.txt new file mode 100644 index 0000000..5ee562f --- /dev/null +++ b/ALL SCHEMA/ALTER TABLE.txt @@ -0,0 +1,14 @@ +use powerpos +go + +alter table beg_inventory drop column beq_qty +go + +alter table beg_inventory add beg_qty decimal(18,2) +go + +alter table delivery drop column dr_type +go + +alter table delivery add dr_type varchar(50) default 'RECEIVING' +go \ No newline at end of file diff --git a/ALL SCHEMA/sp_beg_inventory_date.sql b/ALL SCHEMA/sp_beg_inventory_date.sql new file mode 100644 index 0000000..247caa0 Binary files /dev/null and b/ALL SCHEMA/sp_beg_inventory_date.sql differ diff --git a/ALL SCHEMA/sp_insert_begbal_todate.sql b/ALL SCHEMA/sp_insert_begbal_todate.sql new file mode 100644 index 0000000..2bf1f64 --- /dev/null +++ b/ALL SCHEMA/sp_insert_begbal_todate.sql @@ -0,0 +1,91 @@ +USE POWERPOS +GO + +/****** Object: StoredProcedure [dbo].[sp_insert_begbal_todate] Script Date: 01/21/2026 9:56:36 PM ******/ +SET ANSI_NULLS ON +GO + +SET QUOTED_IDENTIFIER ON +GO + +-- ============================================= +-- Author: +-- Create date: +-- Description: +-- ============================================= +DROP PROCEDURE sp_insert_begbal_todate +go + + +--exec sp_insert_begbal_todate '1/4/2026','PASIG001','PASIG001' +CREATE PROCEDURE [dbo].[sp_insert_begbal_todate] + -- Add the parameters for the stored procedure here + @dDate datetime, + @cStoreid varchar(50), + @cMachine varchar(50) +AS +BEGIN + + --PASIG001 + --PASIG001 + + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + -- Insert statements for procedure here + + exec sp_update_stock_inventory + exec sp_update_stock_inventory_carcass + + --insert parent items to beg_inventory + delete from beg_inventory + where trans_date = @ddate + + + --trans_type = 1 - for items in items table + --trans_type = 2 - for items(carcass) in delivery table + + insert into beg_inventory( + trans_date, + itemcode, + itemname, + beg_qty, --ending_balance + machine_id, + store_id, + trans_type, + ref_no) + select + @ddate, + a.itemcode, + a.itemname, + isnull(a.end_qty,0), + @cMachine, + @cStoreid, + 1, + '' + from items a + where isnull(is_parent,0) =0 + and isnull(end_qty,0) >0 and end_qty != isnull((select beg_qty from beg_inventory z where z.store_id = @cStoreid and z.itemcode = a.itemcode and z.posted = 0 and z.trans_date = @dDate),0) + + --union all + --select + --@ddate, + --a.itemcode, + --a.itemname, + --a.end_qty, + --@cMachine, + --@cStoreid, + --2, + --ref_no + --from delivery a + --where a.is_parent =1 + --and dr_type = 'RECEIVING' + + + + + +END +GO + diff --git a/ALL SCHEMA/sp_update_stock_inventory.sql b/ALL SCHEMA/sp_update_stock_inventory.sql new file mode 100644 index 0000000..3f8abe7 Binary files /dev/null and b/ALL SCHEMA/sp_update_stock_inventory.sql differ diff --git a/ALL SCHEMA/sp_update_stock_inventory_carcass.sql b/ALL SCHEMA/sp_update_stock_inventory_carcass.sql new file mode 100644 index 0000000..603d933 --- /dev/null +++ b/ALL SCHEMA/sp_update_stock_inventory_carcass.sql @@ -0,0 +1,48 @@ +USE POWERPOS +GO + +/****** Object: StoredProcedure [dbo].[sp_update_stock_inventory_carcass] Script Date: 01/22/2026 8:55:38 AM ******/ +SET ANSI_NULLS ON +GO + +SET QUOTED_IDENTIFIER ON +GO + +DROP PROCEDURE sp_update_stock_inventory_carcass +GO + + +CREATE PROCEDURE [dbo].[sp_update_stock_inventory_carcass] +as +BEGIN + + SET NOCOUNT ON; + +--reset balances +update delivery +set qty_in =0,qty_out=0,end_qty=0 + + +update delivery set qty_out = (select isnull(sum(a.qty),0) from cuts_history a + where a.parent_code= delivery.itemcode +and a.source_batch = delivery.ref_no) +--from delivery, cuts_history +--where delivery.itemcode = cuts_history.parent_code +--and delivery.ref_no = cuts_history.parent_batch + + + +update delivery +set end_qty = isnull(qty,0) - isnull(qty_out,0) + + + + + + +END + + +GO + +