New Branch Queries
1. allow the admin and superadmin to access the sub branch system
set @new_branchid = [wid of new branch];
Delete from ´userbranch´
where branchid = @new_branchid
and userid in (100000001,1);
Insert into ´userbranch´
(userid, branchid)
values
(100000001, @new_branchid),
(1, @new_branchid);
2. Add new branch to the database then use this query to sync the new branch to other existing branches
set @new_branchid = [wid of new branch];
set @branch_to_copy_price_from = [existing branch wid to copy the price from];
INSERT INTO ´sync´ (´tablename´, ´wid´, ´branchid´)
SELECT
'branch', @new_branchid, ´wid´
FROM ´branch´
WHERE ´wid´ > 10
AND ´wid´ <> @new_branchid;
3. Insert new branchprice of new branch
set @new_branchid = [wid of new branch];
set @branch_to_copy_price_from = [existing branch wid to copy the price from];
DELETE FROM ´branchprice´
WHERE ´branchid´ = @new_branchid;
INSERT INTO ´branchprice´
(
´branchid´,
´productid´,
´purchaseprice´,
´sellingprice´,
´wholesaleprice´,
´maxquantity´,
´minquantity´,
´packagepurchaseprice´,
´packagesellingprice´,
´packagewholesaleprice´,
´packageqty´,
´ispackage´
)
SELECT
@new_branchid,
´productid´,
´purchaseprice´,
´sellingprice´,
´wholesaleprice´,
´maxquantity´,
´minquantity´,
´packagepurchaseprice´,
´packagesellingprice´,
´packagewholesaleprice´,
´packageqty´,
´ispackage´
FROM ´branchprice´
WHERE ´branchid´ = @branch_to_copy_price_from ;
4. sync new branchprice to other branches (if branches are > 20, ask if this should be executed)
set @new_branchid = [wid of new branch];
DELETE FROM ´sync´
WHERE ´tablename´ = 'product';
INSERT INTO ´sync´ (´tablename´, ´wid´, ´branchid´)
SELECT
'product', P.´wid´, B.´wid´
FROM ´product´ AS P, ´branch´ AS B
WHERE B.´wid´ > 10
AND P.wid > 10
AND B.´wid´ <> @new_branchid;