UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 12:52:50";
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 13:05:33";
UPDATE programsettings SET companyname = 'GT4', address = 'المنصورة', specializtion = 'jh', phone = '01002019235', faxnumber = '0502232923', email = 'mrabozied@gt4it.com', website = 'www.gt4host.com', logo = '471502e62c0be89a8d90663028144a83.jpg', roundnumbers = '0', saveprinting = '1', deptprinting = '0', printingpapersize = '0', userid = '1', showPreviousPrice = '0', parcode = '0', priceing = '0', lastprice = '0', searchvalue = '1', updateproductprice = '0', allowfinsldelete = '0', updateclientprice = '0', `partition` = '0', taxcard = '332', commercialregistration = '3213123312', costcenter = '1', clinic = '1', workshop = '1', transport = '1', manufacturing = '0', masterCopy = '0' , dailyentrydate = '2020-04-18' ,updatefiledate = '2023-11-24',workerbetweenstores = '1',workshoptimeout = '24',drivertimeout = '3',currancy = 'جنيه',serial='9c2d4cf4cf5d4e24d5070164705832c3a5d1287f641a2960e48e04ae57a2ad0a5441322ca7cf34efd63003fdb348adbd0b61197c7c87d8dd5bc298c352482bc6',allowdateedit = '0', clientcode = '1' ,clientserial = '1',timezone = 'Africa/Cairo' , expiredate ='1' , production ='1' , description='1' , service ='1' , date='1' , limitamount = '0' , measuringunit = '1' , print_amount = '0' , billid = '0' , precentages = '1' , realprice = '1' ,delegate_seller = '0' , storeserial = '1' ,clientfieldrequired ='0' , clientcodname='0' , colortype = '0' , nakdyOnly = '0' , nakdyKashf = '0' , discount_pres_direct = '0' , general_discount = '0' , sells_return = '0' ,scunitname ='0',vatValue = '0.00',syncstructure = '1',showPrevPrices = '0',isOpticProg='1',reportsPlusHours = '2' , showM5zon = '1',restaurantStoreId = '1',restuarantPrintTimeout = '8',sumSameProductForStore = '0', editAllPrice = '1', isCafe = '0' ,isRestaurent = '0' ,productDays = '0',thereIsRestTax = '0',restTaxVal = '0',restPrintLang = '0',taxNameFlag = '0',parcodeDigits = '5' ,specializedParcodeDigits = '7', clientDefaultDebtLimit = '10000' , clientDefaultDebtLimitControl = '0',usedParcode = '0' ,productbycodeimage = '' ,commentClient='تعليق على العميل ',Inventoryevaluation='first',Profitevaluation='first' , delivery='-2',premiums = '0',operationnumEdit = '0',noOfDecimalPlaces = '2',unReviewBills = '0', unReviewBillsPass = '123',billReviewNote = '',tamweenBakery = '0',three_months = '0',six_months = '0',twelve_months = '0',eighteen_months = '0',twentyfour_months = '0',thirty_months = '0',sixthirty_months = '0',fortytwo_months = '0',fortyeight_months = '0',mandobCollectionRatio='0',takeAwayClient = '0',restaurantServiceOn = ',-2,-1,1,',earlyrepayment = '0',visaPay = '0',headerPrint='',headerPrintSand='',printSand='0',makeDailyEntry='0',clientShowTawla='0',billRest='1',suppIsClientToo='0',isCarBill='0',expensesproduct='1',projectshownew='1',showparcode='0',changeBuyPriceChangeSellInBuyBillCtrl = '0',changeBuyPriceChangeSellInProductCtrl = '0',inventoryvaluation = '1',showBillCollectionSearch='0' WHERE programsettingsid = '1';
UPDATE programsettings SET companyname = 'GT4', address = 'المنصورة', specializtion = 'jh', phone = '01002019235', faxnumber = '0502232923', email = 'mrabozied@gt4it.com', website = 'www.gt4host.com', logo = '471502e62c0be89a8d90663028144a83.jpg', roundnumbers = '0', saveprinting = '1', deptprinting = '0', printingpapersize = '0', userid = '1', showPreviousPrice = '0', parcode = '0', priceing = '0', lastprice = '0', searchvalue = '1', updateproductprice = '0', allowfinsldelete = '0', updateclientprice = '0', `partition` = '0', taxcard = '332', commercialregistration = '3213123312', costcenter = '1', clinic = '1', workshop = '1', transport = '1', manufacturing = '0', masterCopy = '0' , dailyentrydate = '2020-04-18' ,updatefiledate = '2023-11-24',workerbetweenstores = '1',workshoptimeout = '24',drivertimeout = '3',currancy = 'جنيه',serial='9c2d4cf4cf5d4e24d5070164705832c3a5d1287f641a2960e48e04ae57a2ad0a5441322ca7cf34efd63003fdb348adbd0b61197c7c87d8dd5bc298c352482bc6',allowdateedit = '0', clientcode = '1' ,clientserial = '1',timezone = 'Africa/Cairo' , expiredate ='1' , production ='1' , description='1' , service ='1' , date='1' , limitamount = '0' , measuringunit = '1' , print_amount = '0' , billid = '0' , precentages = '1' , realprice = '1' ,delegate_seller = '0' , storeserial = '1' ,clientfieldrequired ='0' , clientcodname='0' , colortype = '0' , nakdyOnly = '0' , nakdyKashf = '0' , discount_pres_direct = '0' , general_discount = '0' , sells_return = '0' ,scunitname ='0',vatValue = '0.00',syncstructure = '1',showPrevPrices = '0',isOpticProg='1',reportsPlusHours = '2' , showM5zon = '1',restaurantStoreId = '1',restuarantPrintTimeout = '8',sumSameProductForStore = '0', editAllPrice = '1', isCafe = '0' ,isRestaurent = '0' ,productDays = '0',thereIsRestTax = '0',restTaxVal = '0',restPrintLang = '0',taxNameFlag = '0',parcodeDigits = '5' ,specializedParcodeDigits = '7', clientDefaultDebtLimit = '10000' , clientDefaultDebtLimitControl = '0',usedParcode = '0' ,productbycodeimage = '' ,commentClient='تعليق على العميل ',Inventoryevaluation='first',Profitevaluation='first' , delivery='-2',premiums = '0',operationnumEdit = '0',noOfDecimalPlaces = '2',unReviewBills = '0', unReviewBillsPass = '123',billReviewNote = '',tamweenBakery = '0',three_months = '0',six_months = '0',twelve_months = '0',eighteen_months = '0',twentyfour_months = '0',thirty_months = '0',sixthirty_months = '0',fortytwo_months = '0',fortyeight_months = '0',mandobCollectionRatio='0',takeAwayClient = '0',restaurantServiceOn = ',-2,-1,1,',earlyrepayment = '0',visaPay = '0',headerPrint='',headerPrintSand='',printSand='0',makeDailyEntry='0',clientShowTawla='0',billRest='1',suppIsClientToo='0',isCarBill='0',expensesproduct='1',projectshownew='1',showparcode='0',changeBuyPriceChangeSellInBuyBillCtrl = '0',changeBuyPriceChangeSellInProductCtrl = '0',inventoryvaluation = '1',showBillCollectionSearch='0' WHERE programsettingsid = '1';
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 13:05:34";
DROP PROCEDURE IF EXISTS clientInUse;;

CREATE PROCEDURE clientInUse(IN id INT,OUT debtis VARCHAR(256),OUT nameis VARCHAR(256))
BEGIN
DECLARE in_use_flag INT DEFAULT 1;
SELECT inUse FROM client WHERE clientid = id INTO in_use_flag;

    IF in_use_flag = 0 THEN
        update client set inUse=1 where clientid = id;
        SELECT clientdebt,clientname INTO debtis,nameis FROM client WHERE clientid = id ;
    ELSE
        SELECT "in_use","in_use" INTO debtis,nameis;
    END IF;

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 13:05:38";
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 13:05:38";
DROP PROCEDURE IF EXISTS clientInUse;;

CREATE PROCEDURE clientInUse(IN id INT,OUT debtis VARCHAR(256),OUT nameis VARCHAR(256))
BEGIN
DECLARE in_use_flag INT DEFAULT 1;
SELECT inUse FROM client WHERE clientid = id INTO in_use_flag;

    IF in_use_flag = 0 THEN
        update client set inUse=1 where clientid = id;
        SELECT clientdebt,clientname INTO debtis,nameis FROM client WHERE clientid = id ;
    ELSE
        SELECT "in_use","in_use" INTO debtis,nameis;
    END IF;

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 13:06:13";
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 13:06:13";
DROP PROCEDURE IF EXISTS clientInUse;;

CREATE PROCEDURE clientInUse(IN id INT,OUT debtis VARCHAR(256),OUT nameis VARCHAR(256))
BEGIN
DECLARE in_use_flag INT DEFAULT 1;
SELECT inUse FROM client WHERE clientid = id INTO in_use_flag;

    IF in_use_flag = 0 THEN
        update client set inUse=1 where clientid = id;
        SELECT clientdebt,clientname INTO debtis,nameis FROM client WHERE clientid = id ;
    ELSE
        SELECT "in_use","in_use" INTO debtis,nameis;
    END IF;

END

;
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 13:06:44";
UPDATE user SET loginip = "196.152.137.211", lastactivetime = "2023-11-24 16:36:44", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2023-11-24 16:36:44', '1', '', '196.152.137.211', '', 'MOBILE');
UPDATE programsettings SET companyname = 'GT4', address = 'المنصورة', specializtion = 'jh', phone = '01002019235', faxnumber = '0502232923', email = 'mrabozied@gt4it.com', website = 'www.gt4host.com', logo = '471502e62c0be89a8d90663028144a83.jpg', roundnumbers = '0', saveprinting = '1', deptprinting = '0', printingpapersize = '0', userid = '1', showPreviousPrice = '0', parcode = '0', priceing = '0', lastprice = '0', searchvalue = '1', updateproductprice = '0', allowfinsldelete = '0', updateclientprice = '0', `partition` = '0', taxcard = '332', commercialregistration = '3213123312', costcenter = '1', clinic = '1', workshop = '1', transport = '1', manufacturing = '0', masterCopy = '0' , dailyentrydate = '2020-04-18' ,updatefiledate = '2023-11-24',workerbetweenstores = '1',workshoptimeout = '24',drivertimeout = '3',currancy = 'جنيه',serial='9c2d4cf4cf5d4e24d5070164705832c3a5d1287f641a2960e48e04ae57a2ad0a5441322ca7cf34efd63003fdb348adbd0b61197c7c87d8dd5bc298c352482bc6',allowdateedit = '0', clientcode = '1' ,clientserial = '1',timezone = 'Africa/Cairo' , expiredate ='1' , production ='1' , description='1' , service ='1' , date='1' , limitamount = '0' , measuringunit = '1' , print_amount = '0' , billid = '0' , precentages = '1' , realprice = '1' ,delegate_seller = '0' , storeserial = '1' ,clientfieldrequired ='0' , clientcodname='0' , colortype = '0' , nakdyOnly = '0' , nakdyKashf = '0' , discount_pres_direct = '0' , general_discount = '0' , sells_return = '0' ,scunitname ='0',vatValue = '0.00',syncstructure = '1',showPrevPrices = '0',isOpticProg='1',reportsPlusHours = '2' , showM5zon = '1',restaurantStoreId = '1',restuarantPrintTimeout = '8',sumSameProductForStore = '0', editAllPrice = '1', isCafe = '0' ,isRestaurent = '0' ,productDays = '0',thereIsRestTax = '0',restTaxVal = '0',restPrintLang = '0',taxNameFlag = '0',parcodeDigits = '5' ,specializedParcodeDigits = '7', clientDefaultDebtLimit = '10000' , clientDefaultDebtLimitControl = '0',usedParcode = '0' ,productbycodeimage = '' ,commentClient='تعليق على العميل ',Inventoryevaluation='first',Profitevaluation='first' , delivery='-2',premiums = '0',operationnumEdit = '0',noOfDecimalPlaces = '2',unReviewBills = '0', unReviewBillsPass = '123',billReviewNote = '',tamweenBakery = '0',three_months = '0',six_months = '0',twelve_months = '0',eighteen_months = '0',twentyfour_months = '0',thirty_months = '0',sixthirty_months = '0',fortytwo_months = '0',fortyeight_months = '0',mandobCollectionRatio='0',takeAwayClient = '0',restaurantServiceOn = ',-2,-1,1,',earlyrepayment = '0',visaPay = '0',headerPrint='',headerPrintSand='',printSand='0',makeDailyEntry='0',clientShowTawla='0',billRest='1',suppIsClientToo='0',isCarBill='0',expensesproduct='1',projectshownew='1',showparcode='0',changeBuyPriceChangeSellInBuyBillCtrl = '0',changeBuyPriceChangeSellInProductCtrl = '0',inventoryvaluation = '1',showBillCollectionSearch='0' WHERE programsettingsid = '1';
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 13:06:50";
DROP PROCEDURE IF EXISTS clientInUse;;

CREATE PROCEDURE clientInUse(IN id INT,OUT debtis VARCHAR(256),OUT nameis VARCHAR(256))
BEGIN
DECLARE in_use_flag INT DEFAULT 1;
SELECT inUse FROM client WHERE clientid = id INTO in_use_flag;

    IF in_use_flag = 0 THEN
        update client set inUse=1 where clientid = id;
        SELECT clientdebt,clientname INTO debtis,nameis FROM client WHERE clientid = id ;
    ELSE
        SELECT "in_use","in_use" INTO debtis,nameis;
    END IF;

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 13:06:54";
UPDATE user SET loginip = "196.152.137.211", lastactivetime = "2023-11-24 16:36:54", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-11-24 16:36:54', '1', 'addsellBill', '196.152.137.211', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:36:34";
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:37:00";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:07:00", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2023-11-24 22:07:00', '1', '', '196.159.228.173', '', 'MOBILE');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:37:00";
DROP PROCEDURE IF EXISTS clientInUse;;

CREATE PROCEDURE clientInUse(IN id INT,OUT debtis VARCHAR(256),OUT nameis VARCHAR(256))
BEGIN
DECLARE in_use_flag INT DEFAULT 1;
SELECT inUse FROM client WHERE clientid = id INTO in_use_flag;

    IF in_use_flag = 0 THEN
        update client set inUse=1 where clientid = id;
        SELECT clientdebt,clientname INTO debtis,nameis FROM client WHERE clientid = id ;
    ELSE
        SELECT "in_use","in_use" INTO debtis,nameis;
    END IF;

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:37:33";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:07:33", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-11-24 22:07:33', '1', '', '196.159.228.173', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:41:23";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:11:24", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-11-24 22:11:24', '1', 'add', '196.159.228.173', '', 'MOBILE');
BEGIN;
INSERT INTO product (productName, productDescription, productCatId, productBuyPrice, productSellAllPrice, productSellUnitPrice, productSellHalfPrice, productDate, conditions, userId, limitamount, parcode,type, expireDate, dailyentryId,isService,isOptic,lastbuyprice,lastbuyprice_withDiscount,meanbuyprice,meanbuyprice_withDiscount , productbuypricereal , buypricereal_precentage , buytotal_precentage , buyhalf_precentage , buypart_precentage,logo,inMenu,obygyDetectionId,hasSizeAndColor,overAllAveragePrice,reviewType,online,updatebyuser,proExcelid,proExcelParcode,webApiId) VALUES ('1050اسيا','','1','340','50', '390','70', '2023-11-24', '0', '1', '0', '', '0', '0', '0', '0', '0', '340','340','340','340','340','0','-85.29','-79.41','14.71','.','0','0','0','0','0','','','0','0','0');
UPDATE product SET productName = '1050اسيا', productDescription = '', productCatId = '1', productBuyPrice = '340', productSellAllPrice = '50', productSellUnitPrice = '390', productSellHalfPrice = '70', productDate = '2023-11-24', conditions = '0', userId = '1', limitamount = '0', parcode = '01490',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '340',lastbuyprice_withDiscount = '340',meanbuyprice = '340',meanbuyprice_withDiscount = '340' , productbuypricereal = '340' , buypricereal_precentage = '0' , buytotal_precentage = '-85.29' , buyhalf_precentage = '-79.41' , buypart_precentage = '14.71',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1490';
INSERT INTO productunit (unitid, productid, productnumber, productunitdate, userid, conditions,proUnitParcode,proUnitSellAllPrice,proUnitSellHalfPrice,proUnitSellUnitPrice,proUnitBuyPrice) VALUES ('1', '1490', '1', '2023-11-24', '1', '0','0149001','50','70','390','340');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1490', '1', '13', '1', '2023-11-24');
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1490', '1', '13', '0', '1490', 'إضافة منتج', 'productController.php', '0', '13', '1', '2023-11-24','0','0');
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1490, 1,'2023-11-24 22:11:24',1)
                ON DUPLICATE KEY UPDATE productid = 1490, edited = 1, sysdate = '2023-11-24 22:11:24', userid = 1;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '4420', '4420', '2023-11-24', '1', '0', '0', '2023-11-24 22:11:24','إضافة منتج 1050اسيا الكمية 13','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8889', '19', '4420', '','0');
UPDATE accountstree SET name = 'البضاعة (بضاعة أول المدة)', customName = 'البضاعة (بضاعة أول المدة)', parent = '6', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '14847215.95', theOrder = '0', layingOrder = '121',reportid = '0' WHERE id = '19';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8889', '7', '4420', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '15605496.75', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
UPDATE product SET productName = '1050اسيا', productDescription = '', productCatId = '1', productBuyPrice = '340.00', productSellAllPrice = '50.00', productSellUnitPrice = '390.00', productSellHalfPrice = '70.00', productDate = '2023-11-24', conditions = '0', userId = '1', limitamount = '0', parcode = '01490',type ='0', expireDate = '0' , dailyentryId = '8889',isService = '0',isOptic = '0',lastbuyprice = '340',lastbuyprice_withDiscount = '340',meanbuyprice = '340',meanbuyprice_withDiscount = '340' , productbuypricereal = '340' , buypricereal_precentage = '0' , buytotal_precentage = '-85.29' , buyhalf_precentage = '-79.41' , buypart_precentage = '14.71',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1490';
INSERT INTO product (productName, productDescription, productCatId, productBuyPrice, productSellAllPrice, productSellUnitPrice, productSellHalfPrice, productDate, conditions, userId, limitamount, parcode,type, expireDate, dailyentryId,isService,isOptic,lastbuyprice,lastbuyprice_withDiscount,meanbuyprice,meanbuyprice_withDiscount , productbuypricereal , buypricereal_precentage , buytotal_precentage , buyhalf_precentage , buypart_precentage,logo,inMenu,obygyDetectionId,hasSizeAndColor,overAllAveragePrice,reviewType,online,updatebyuser,proExcelid,proExcelParcode,webApiId) VALUES ('1051اسيا','','1','340','350', '390','370', '2023-11-24', '0', '1', '0', '', '0', '0', '0', '0', '0', '340','340','340','340','340','0','2.94','8.82','14.71','.','0','0','0','0','0','','','0','0','0');
UPDATE product SET productName = '1051اسيا', productDescription = '', productCatId = '1', productBuyPrice = '340', productSellAllPrice = '350', productSellUnitPrice = '390', productSellHalfPrice = '370', productDate = '2023-11-24', conditions = '0', userId = '1', limitamount = '0', parcode = '01491',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '340',lastbuyprice_withDiscount = '340',meanbuyprice = '340',meanbuyprice_withDiscount = '340' , productbuypricereal = '340' , buypricereal_precentage = '0' , buytotal_precentage = '2.94' , buyhalf_precentage = '8.82' , buypart_precentage = '14.71',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1491';
INSERT INTO productunit (unitid, productid, productnumber, productunitdate, userid, conditions,proUnitParcode,proUnitSellAllPrice,proUnitSellHalfPrice,proUnitSellUnitPrice,proUnitBuyPrice) VALUES ('1', '1491', '1', '2023-11-24', '1', '0','0149101','350','370','390','340');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1491', '1', '15', '1', '2023-11-24');
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1491', '1', '15', '0', '1491', 'إضافة منتج', 'productController.php', '0', '15', '1', '2023-11-24','0','0');
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1491, 1,'2023-11-24 22:11:24',1)
                ON DUPLICATE KEY UPDATE productid = 1491, edited = 1, sysdate = '2023-11-24 22:11:24', userid = 1;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '5100', '5100', '2023-11-24', '1', '0', '0', '2023-11-24 22:11:24','إضافة منتج 1051اسيا الكمية 15','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8890', '19', '5100', '','0');
UPDATE accountstree SET name = 'البضاعة (بضاعة أول المدة)', customName = 'البضاعة (بضاعة أول المدة)', parent = '6', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '14852315.95', theOrder = '0', layingOrder = '121',reportid = '0' WHERE id = '19';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8890', '7', '5100', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '15610596.75', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
UPDATE product SET productName = '1051اسيا', productDescription = '', productCatId = '1', productBuyPrice = '340.00', productSellAllPrice = '350.00', productSellUnitPrice = '390.00', productSellHalfPrice = '370.00', productDate = '2023-11-24', conditions = '0', userId = '1', limitamount = '0', parcode = '01491',type ='0', expireDate = '0' , dailyentryId = '8890',isService = '0',isOptic = '0',lastbuyprice = '340',lastbuyprice_withDiscount = '340',meanbuyprice = '340',meanbuyprice_withDiscount = '340' , productbuypricereal = '340' , buypricereal_precentage = '0' , buytotal_precentage = '2.94' , buyhalf_precentage = '8.82' , buypart_precentage = '14.71',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1491';
INSERT INTO product (productName, productDescription, productCatId, productBuyPrice, productSellAllPrice, productSellUnitPrice, productSellHalfPrice, productDate, conditions, userId, limitamount, parcode,type, expireDate, dailyentryId,isService,isOptic,lastbuyprice,lastbuyprice_withDiscount,meanbuyprice,meanbuyprice_withDiscount , productbuypricereal , buypricereal_precentage , buytotal_precentage , buyhalf_precentage , buypart_precentage,logo,inMenu,obygyDetectionId,hasSizeAndColor,overAllAveragePrice,reviewType,online,updatebyuser,proExcelid,proExcelParcode,webApiId) VALUES ('ست الحبايب 461','','1','300','320', '360','340', '2023-11-24', '0', '1', '0', '', '0', '0', '0', '0', '0', '300','300','300','300','300','0','6.67','13.33','20','.','0','0','0','0','0','','','0','0','0');
UPDATE product SET productName = 'ست الحبايب 461', productDescription = '', productCatId = '1', productBuyPrice = '300', productSellAllPrice = '320', productSellUnitPrice = '360', productSellHalfPrice = '340', productDate = '2023-11-24', conditions = '0', userId = '1', limitamount = '0', parcode = '01492',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '300',lastbuyprice_withDiscount = '300',meanbuyprice = '300',meanbuyprice_withDiscount = '300' , productbuypricereal = '300' , buypricereal_precentage = '0' , buytotal_precentage = '6.67' , buyhalf_precentage = '13.33' , buypart_precentage = '20',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1492';
INSERT INTO productunit (unitid, productid, productnumber, productunitdate, userid, conditions,proUnitParcode,proUnitSellAllPrice,proUnitSellHalfPrice,proUnitSellUnitPrice,proUnitBuyPrice) VALUES ('1', '1492', '1', '2023-11-24', '1', '0','0149201','320','340','360','300');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1492', '1', '24', '1', '2023-11-24');
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1492', '1', '24', '0', '1492', 'إضافة منتج', 'productController.php', '0', '24', '1', '2023-11-24','0','0');
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1492, 1,'2023-11-24 22:11:24',1)
                ON DUPLICATE KEY UPDATE productid = 1492, edited = 1, sysdate = '2023-11-24 22:11:24', userid = 1;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '7200', '7200', '2023-11-24', '1', '0', '0', '2023-11-24 22:11:24','إضافة منتج ست الحبايب 461 الكمية 24','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8891', '19', '7200', '','0');
UPDATE accountstree SET name = 'البضاعة (بضاعة أول المدة)', customName = 'البضاعة (بضاعة أول المدة)', parent = '6', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '14859515.95', theOrder = '0', layingOrder = '121',reportid = '0' WHERE id = '19';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8891', '7', '7200', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '15617796.75', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
UPDATE product SET productName = 'ست الحبايب 461', productDescription = '', productCatId = '1', productBuyPrice = '300.00', productSellAllPrice = '320.00', productSellUnitPrice = '360.00', productSellHalfPrice = '340.00', productDate = '2023-11-24', conditions = '0', userId = '1', limitamount = '0', parcode = '01492',type ='0', expireDate = '0' , dailyentryId = '8891',isService = '0',isOptic = '0',lastbuyprice = '300',lastbuyprice_withDiscount = '300',meanbuyprice = '300',meanbuyprice_withDiscount = '300' , productbuypricereal = '300' , buypricereal_precentage = '0' , buytotal_precentage = '6.67' , buyhalf_precentage = '13.33' , buypart_precentage = '20',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1492';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:41:26";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:11:26", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-11-24 22:11:26', '1', '', '196.159.228.173', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:41:45";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:11:45", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-11-24 22:11:45', '1', 'show', '196.159.228.173', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:42:06";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:12:07", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-11-24 22:12:07', '1', 'show', '196.159.228.173', '', 'MOBILE');
UPDATE product SET productName = '1050اسيا', productDescription = '', productCatId = '1', productBuyPrice = '340.00', productSellAllPrice = '50.00', productSellUnitPrice = '390.00', productSellHalfPrice = '70.00', productDate = '2023-11-24', conditions = '0', userId = '1', limitamount = '0', parcode = '01490',type ='0', expireDate = '0' , dailyentryId = '8889',isService = '0',isOptic = '0',lastbuyprice = '340.00',lastbuyprice_withDiscount = '340',meanbuyprice = '340.00',meanbuyprice_withDiscount = '340' , productbuypricereal = '340.00' , buypricereal_precentage = '0.00' , buytotal_precentage = '-85.29' , buyhalf_precentage = '-79.41' , buypart_precentage = '14.71',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1490';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1490, 1,'2023-11-24 22:12:21',1)
                ON DUPLICATE KEY UPDATE productid = 1490, edited = 1, sysdate = '2023-11-24 22:12:21', userid = 1;
UPDATE product SET productName = '1050اسيا', productDescription = '', productCatId = '1', productBuyPrice = '340.00', productSellAllPrice = '350', productSellUnitPrice = '350', productSellHalfPrice = '350', productDate = '2023-11-24', conditions = '0', userId = '1', limitamount = '0', parcode = '01490',type ='0', expireDate = '0' , dailyentryId = '8889',isService = '0',isOptic = '0',lastbuyprice = '340.00',lastbuyprice_withDiscount = '340',meanbuyprice = '340.00',meanbuyprice_withDiscount = '340' , productbuypricereal = '340.00' , buypricereal_precentage = '0.00' , buytotal_precentage = '-85.29' , buyhalf_precentage = '-79.41' , buypart_precentage = '14.71',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1490';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1490, 1,'2023-11-24 22:12:56',1)
                ON DUPLICATE KEY UPDATE productid = 1490, edited = 1, sysdate = '2023-11-24 22:12:56', userid = 1;
UPDATE product SET productName = '1050اسيا', productDescription = '', productCatId = '1', productBuyPrice = '340.00', productSellAllPrice = '350.00', productSellUnitPrice = '350.00', productSellHalfPrice = '370', productDate = '2023-11-24', conditions = '0', userId = '1', limitamount = '0', parcode = '01490',type ='0', expireDate = '0' , dailyentryId = '8889',isService = '0',isOptic = '0',lastbuyprice = '340.00',lastbuyprice_withDiscount = '340',meanbuyprice = '340.00',meanbuyprice_withDiscount = '340' , productbuypricereal = '340.00' , buypricereal_precentage = '0.00' , buytotal_precentage = '-85.29' , buyhalf_precentage = '-79.41' , buypart_precentage = '14.71',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1490';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1490, 1,'2023-11-24 22:13:18',1)
                ON DUPLICATE KEY UPDATE productid = 1490, edited = 1, sysdate = '2023-11-24 22:13:18', userid = 1;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:43:55";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:13:55", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-11-24 22:13:55', '1', 'show', '196.159.228.173', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:44:02";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:14:02", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-11-24 22:14:02', '1', '', '196.159.228.173', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:44:07";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:14:07", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-11-24 22:14:07', '1', 'addsellBill', '196.159.228.173', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:46:02";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:16:02", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-11-24 22:16:02', '1', '', '196.159.228.173', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:46:12";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:16:12", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-11-24 22:16:12', '1', '', '196.159.228.173', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:47:25";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:17:25", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-11-24 22:17:25', '1', 'add', '196.159.228.173', '', 'MOBILE');
DROP PROCEDURE IF EXISTS insertUniqueOptNum;;

CREATE PROCEDURE insertUniqueOptNum(IN optnum INT,IN storeidfrom INT,IN storeidto INT,IN productid INT,IN transferproductamount DECIMAL(10,2),IN transferproductdate DATE,IN userid INT,IN conditions INT,IN `comment` TEXT,IN deloperationnum INT,IN sizeid INT,IN colorid INT,IN driverid INT,IN drivertimeout INT,IN driverdate datetime,IN delivererid INT,IN deliverdate datetime,OUT inserted_id INT,OUT optnum_used INT)
BEGIN
DECLARE n INT DEFAULT 0;
DECLARE id INT DEFAULT 0;
DECLARE lastopt INT DEFAULT 0;


DECLARE EXIT HANDLER FOR SQLEXCEPTION
    BEGIN
    ROLLBACK;
    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
     @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
    SET @full_error = CONCAT("ERROR ", @errno, " (", @sqlstate, "): ", @text);
    SELECT @full_error;
    ROLLBACK;
END;



START TRANSACTION;


SELECT COUNT(*) FROM storemovement WHERE `operationnum` = optnum INTO n;
SELECT DISTINCT operationnum FROM storemovement WHERE operationnum != 0  ORDER BY operationnum DESC limit 1 INTO lastopt;
set lastopt = lastopt+1;

	IF n > 0 THEN


      INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions,comment,operationnum ,deloperationnum,sizeid,colorid,driverid,drivertimeout,driverdate,delivererid,deliverdate)
                VALUES (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,comment ,
                lastopt,
                deloperationnum,sizeid,colorid,driverid,drivertimeout,driverdate,delivererid,deliverdate);
            SELECT LAST_INSERT_ID(),lastopt INTO inserted_id,optnum_used;
ELSE

    INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions,comment,operationnum ,deloperationnum,sizeid,colorid,driverid,drivertimeout,driverdate,delivererid,deliverdate)
                VALUES (storeidfrom, storeidto, productid,transferproductamount, transferproductdate, userid, conditions ,comment
                ,optnum
                ,deloperationnum,sizeid,colorid,driverid,drivertimeout,driverdate,delivererid,deliverdate);
            SELECT LAST_INSERT_ID(),optnum INTO inserted_id,optnum_used;
	END IF;

COMMIT WORK; -- it is mandatory dont wait comit in php.as if sp didnot found comit before reaching the end it will rollback giving no errors at all

End;
;;

;
BEGIN;
CALL insertUniqueOptNum(1721,1,7,502,60,'2023-11-24',1,0, '' ,0,0,0,0,0,'2023-11-24 22:17:26',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '-60', userid = '1', storedetaildate = '2023-11-24' WHERE storedetailid = '502';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-11-24', 1, 502, 0, 0
                    , 195.00, -60, 0, 0, 1, '2023-11-24 22:17:26')
                ON DUPLICATE KEY UPDATE buyprice = 195.00,
                        buyQuantity =buyQuantity+-60, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-11-24 22:17:26' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "60*2023-11-24*195.00," WHERE transferproductid = 7582;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('502', '1', '60', '1', '7582', 'تحويل منتجات من المخزن', 'storemovementController.php', '0.00', '-60', '1', '2023-11-24','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('502', '7', '60', '1', '2023-11-24');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-11-24', 7, 502, 0, 0
                    , 195.00, 60, 0, 0, 1, '2023-11-24 22:17:26')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+60, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-11-24 22:17:26' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('502', '7', '60', '0', '7582', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '60', '1', '2023-11-24','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '1492', '24', '2023-11-24', '1', '0','1721',null,null,'2023-11-24 22:17:26',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2023-11-24' WHERE storedetailid = '5464';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-11-24', 1, 1492, 0, 0
                    , 300.00, -24, 0, 0, 1, '2023-11-24 22:17:26')
                ON DUPLICATE KEY UPDATE buyprice = 300.00,
                        buyQuantity =buyQuantity+-24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-11-24 22:17:26' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "24*2023-11-24*300.00," WHERE transferproductid = 7583;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1492', '1', '24', '1', '7583', 'تحويل منتجات من المخزن', 'storemovementController.php', '24.00', '0', '1', '2023-11-24','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1492', '7', '24', '1', '2023-11-24');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-11-24', 7, 1492, 0, 0
                    , 300.00, 24, 0, 0, 1, '2023-11-24 22:17:26')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-11-24 22:17:26' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1492', '7', '24', '0', '7583', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '24', '1', '2023-11-24','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '1490', '13', '2023-11-24', '1', '0','1721',null,null,'2023-11-24 22:17:26',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2023-11-24' WHERE storedetailid = '5462';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-11-24', 1, 1490, 0, 0
                    , 340.00, -13, 0, 0, 1, '2023-11-24 22:17:26')
                ON DUPLICATE KEY UPDATE buyprice = 340.00,
                        buyQuantity =buyQuantity+-13, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-11-24 22:17:26' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "13*2023-11-24*340.00," WHERE transferproductid = 7584;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1490', '1', '13', '1', '7584', 'تحويل منتجات من المخزن', 'storemovementController.php', '13.00', '0', '1', '2023-11-24','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1490', '7', '13', '1', '2023-11-24');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-11-24', 7, 1490, 0, 0
                    , 340.00, 13, 0, 0, 1, '2023-11-24 22:17:26')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+13, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-11-24 22:17:26' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1490', '7', '13', '0', '7584', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '13', '1', '2023-11-24','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '1491', '15', '2023-11-24', '1', '0','1721',null,null,'2023-11-24 22:17:26',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2023-11-24' WHERE storedetailid = '5463';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-11-24', 1, 1491, 0, 0
                    , 340.00, -15, 0, 0, 1, '2023-11-24 22:17:26')
                ON DUPLICATE KEY UPDATE buyprice = 340.00,
                        buyQuantity =buyQuantity+-15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-11-24 22:17:26' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "15*2023-11-24*340.00," WHERE transferproductid = 7585;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1491', '1', '15', '1', '7585', 'تحويل منتجات من المخزن', 'storemovementController.php', '15.00', '0', '1', '2023-11-24','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1491', '7', '15', '1', '2023-11-24');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-11-24', 7, 1491, 0, 0
                    , 340.00, 15, 0, 0, 1, '2023-11-24 22:17:26')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-11-24 22:17:26' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1491', '7', '15', '0', '7585', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '15', '1', '2023-11-24','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:47:26";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:17:26", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-11-24 22:17:27', '1', 'sucess', '196.159.228.173', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:47:34";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:17:34", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-11-24 22:17:34', '1', 'show', '196.159.228.173', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:47:46";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:17:46", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-11-24 22:17:46', '1', 'show', '196.159.228.173', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:48:00";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:18:00", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-11-24 22:18:00', '1', 'show', '196.159.228.173', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-11-24 18:48:23";
UPDATE user SET loginip = "196.159.228.173", lastactivetime = "2023-11-24 22:18:23", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-11-24 22:18:23', '1', 'editorder', '196.159.228.173', '', 'MOBILE');
