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 < "2021-12-01 07:06:04";
UPDATE user SET loginip = "102.44.127.243", lastactivetime = "2021-12-01 10:36:04", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-01 10:36:04', '8', '', '102.44.127.243', '', 'DESKTOP');
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 = '1', 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 = '2021-12-01',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 < "2021-12-01 07:06:05";
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 < "2021-12-01 07:06:12";
UPDATE user SET loginip = "102.44.127.243", lastactivetime = "2021-12-01 10:36:12", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 10:36:12', '8', 'addsellBill', '102.44.127.243', '', 'DESKTOP');
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 < "2021-12-01 07:22:24";
UPDATE user SET loginip = "197.41.122.222", lastactivetime = "2021-12-01 10:52:24", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-01 10:52:24', '3', '', '197.41.122.222', '', 'DESKTOP');
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 < "2021-12-01 07:22:24";
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 < "2021-12-01 07:22:36";
UPDATE user SET loginip = "197.41.122.222", lastactivetime = "2021-12-01 10:52:36", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 10:52:36', '3', 'addsellBill', '197.41.122.222', '', 'DESKTOP');
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;
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 < "2021-12-01 07:24:19";
UPDATE user SET loginip = "197.41.122.222", lastactivetime = "2021-12-01 10:54:19", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-01 10:54:19', '3', '', '197.41.122.222', '', 'DESKTOP');
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 < "2021-12-01 07:24:19";
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 < "2021-12-01 07:24:23";
UPDATE user SET loginip = "197.41.122.222", lastactivetime = "2021-12-01 10:54:23", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 10:54:23', '3', 'addsellBill', '197.41.122.222', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:24:55";
UPDATE user SET loginip = "102.44.127.243", lastactivetime = "2021-12-01 10:54:55", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-01 10:54:55', '8', '', '102.44.127.243', '', 'DESKTOP');
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 < "2021-12-01 07:24:56";
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 < "2021-12-01 07:24:58";
UPDATE user SET loginip = "102.44.127.243", lastactivetime = "2021-12-01 10:54:58", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 10:54:58', '8', 'addsellBill', '102.44.127.243', '', 'DESKTOP');
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 < "2021-12-01 07:26:46";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 10:56:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-01 10:56:46', '1', '', '197.56.138.72', '', 'DESKTOP');
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 < "2021-12-01 07:26:46";
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 < "2021-12-01 07:42:28";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:12:28", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-01 11:12:28', '1', '', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:43:37";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:13:37", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 11:13:37', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:43:49";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:13:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 11:13:49', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:44:02";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:14:02", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 11:14:02', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:44:13";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:14:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 11:14:13', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:44:33";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:14:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-01 11:14:33', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:44:47";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:14:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-01 11:14:47', '1', 'edit', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:45:14";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:15:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 11:15:14', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:45:24";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:15:24", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 11:15:24', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:45:32";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:15:32", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 11:15:32', '1', '', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:46:44";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:16:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-01 11:16:45', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:46:52";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:16:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-01 11:16:52', '1', 'edit', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:47:03";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:17:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 11:17:03', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:47:12";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:17:12", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 11:17:13', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:47:27";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:17:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementKindSaveController.php', '2021-12-01 11:17:27', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:47:43";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:17:43", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-01 11:17:43', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:47:50";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:17:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-01 11:17:50', '1', 'edit', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:48:07";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:18:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 11:18:08', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:48:16";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:18:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 11:18:16', '1', '', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:52:21";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:22:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-01 11:22:21', '1', '', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:53:33";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:23:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-01 11:23:33', '1', 'add', '197.56.138.72', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '172', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1554';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '1', '172', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '172', '1', '2021-12-01','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:53:35";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:23:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-01 11:23:35', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:53:49";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:23:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-01 11:23:49', '1', '', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:54:49";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:24:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-01 11:24:49', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:55:02";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:25:02", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-01 11:25:02', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 07:55:14";
UPDATE user SET loginip = "197.56.138.72", lastactivetime = "2021-12-01 11:25:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-01 11:25:14', '1', 'show', '197.56.138.72', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 08:08:42";
UPDATE user SET loginip = "102.44.127.243", lastactivetime = "2021-12-01 11:38:42", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-01 11:38:42', '8', '', '102.44.127.243', '', 'DESKTOP');
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 < "2021-12-01 08:08:42";
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 < "2021-12-01 08:08:46";
UPDATE user SET loginip = "102.44.127.243", lastactivetime = "2021-12-01 11:38:46", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 11:38:46', '8', 'addsellBill', '102.44.127.243', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 08:36:27";
UPDATE user SET loginip = "102.44.127.243", lastactivetime = "2021-12-01 12:06:27", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-01 12:06:27', '8', '', '102.44.127.243', '', 'DESKTOP');
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 < "2021-12-01 08:36:27";
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 < "2021-12-01 08:38:45";
UPDATE user SET loginip = "102.44.127.243", lastactivetime = "2021-12-01 12:08:45", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 12:08:45', '8', 'addsellBill', '102.44.127.243', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 09:12:07";
UPDATE user SET loginip = "102.44.127.243", lastactivetime = "2021-12-01 12:42:07", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-01 12:42:07', '8', '', '102.44.127.243', '', 'DESKTOP');
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 < "2021-12-01 09:12:07";
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 < "2021-12-01 09:12:10";
UPDATE user SET loginip = "102.44.127.243", lastactivetime = "2021-12-01 12:42:10", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 12:42:10', '8', 'addsellBill', '102.44.127.243', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 09:12:11";
UPDATE user SET loginip = "102.44.127.243", lastactivetime = "2021-12-01 12:42:11", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 12:42:11', '8', 'addsellBill', '102.44.127.243', '', 'DESKTOP');
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 < "2021-12-01 09:44:42";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 13:14:42", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-01 13:14:42', '6', '', '41.43.10.231', '', 'DESKTOP');
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 < "2021-12-01 09:44:43";
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 < "2021-12-01 09:44:47";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 13:14:47", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-01 13:14:47', '6', '', '41.43.10.231', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 09:44:55";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 13:14:55", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2021-12-01 13:14:55', '6', '', '41.43.10.231', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 09:45:00";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 13:15:00", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-01 13:15:00', '6', '', '41.43.10.231', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 09:45:15";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 13:15:15", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 13:15:15', '6', 'addsellBill', '41.43.10.231', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 09:45:28";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 13:15:28", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-01 13:15:28', '6', '', '41.43.10.231', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 09:45:28";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 13:15:28", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-01 13:15:28', '6', '', '41.43.10.231', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 09:45:35";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 13:15:35", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storedetailController.php', '2021-12-01 13:15:35', '6', '', '41.43.10.231', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 09:45:39";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 13:15:39", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storedetailController.php', '2021-12-01 13:15:39', '6', '', '41.43.10.231', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:01:13";
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 < "2021-12-01 10:01:19";
UPDATE user SET loginip = "197.55.42.248", lastactivetime = "2021-12-01 13:31:19", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-01 13:31:19', '5', '', '197.55.42.248', '', 'DESKTOP');
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 < "2021-12-01 10:01:19";
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 < "2021-12-01 10:01:28";
UPDATE user SET loginip = "197.55.42.248", lastactivetime = "2021-12-01 13:31:28", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 13:31:28', '5', 'addsellBill', '197.55.42.248', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:02:09";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 13:32:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-01 13:32:09', '1', 'add', '102.46.62.240', '', 'DESKTOP');
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 ('818','','1','230','235', '265','245', '2021-12-01', '0', '1', '0', '', '0', '0', '0', '0', '0', '230','230','230','230','230','0','2.17','6.52','15.22','.','0','0','0','0','0','','','0','0','0');
UPDATE product SET productName = '818', productDescription = '', productCatId = '1', productBuyPrice = '230', productSellAllPrice = '235', productSellUnitPrice = '265', productSellHalfPrice = '245', productDate = '2021-12-01', conditions = '0', userId = '1', limitamount = '0', parcode = '00589',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '230',lastbuyprice_withDiscount = '230',meanbuyprice = '230',meanbuyprice_withDiscount = '230' , productbuypricereal = '230' , buypricereal_precentage = '0' , buytotal_precentage = '2.17' , buyhalf_precentage = '6.52' , buypart_precentage = '15.22',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '589';
INSERT INTO productunit (unitid, productid, productnumber, productunitdate, userid, conditions,proUnitParcode,proUnitSellAllPrice,proUnitSellHalfPrice,proUnitSellUnitPrice,proUnitBuyPrice) VALUES ('1', '589', '1', '2021-12-01', '1', '0','0058901','235','245','265','230');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('589', '1', '172', '1', '2021-12-01');
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '1', '172', '0', '589', 'إضافة منتج', 'productController.php', '0', '172', '1', '2021-12-01','0','0');
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (589, 1,'2021-12-01 13:32:09',1)
                ON DUPLICATE KEY UPDATE productid = 589, edited = 1, sysdate = '2021-12-01 13:32:09', userid = 1;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '39560', '39560', '2021-12-01', '1', '0', '0', '2021-12-01 13:32:09','إضافة منتج 818 الكمية 172','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('701', '19', '39560', '','0');
UPDATE accountstree SET name = 'البضاعة (بضاعة أول المدة)', customName = 'البضاعة (بضاعة أول المدة)', parent = '6', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '6067867.5', theOrder = '0', layingOrder = '121',reportid = '0' WHERE id = '19';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('701', '7', '39560', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '6922813.3', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
UPDATE product SET productName = '818', productDescription = '', productCatId = '1', productBuyPrice = '230.00', productSellAllPrice = '235.00', productSellUnitPrice = '265.00', productSellHalfPrice = '245.00', productDate = '2021-12-01', conditions = '0', userId = '1', limitamount = '0', parcode = '00589',type ='0', expireDate = '0' , dailyentryId = '701',isService = '0',isOptic = '0',lastbuyprice = '230',lastbuyprice_withDiscount = '230',meanbuyprice = '230',meanbuyprice_withDiscount = '230' , productbuypricereal = '230' , buypricereal_precentage = '0' , buytotal_precentage = '2.17' , buyhalf_precentage = '6.52' , buypart_precentage = '15.22',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '589';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:02:11";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 13:32:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-01 13:32:11', '1', '', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:36:37";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:06:37", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-01 14:06:37', '1', '', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:36:54";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:06:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-01 14:06:54', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:38:10";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:08:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-01 14:08:10', '1', 'add', '102.46.62.240', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '7', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1484';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '1', '7', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '7', '1', '2021-12-01','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:38:12";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:08:12", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-01 14:08:12', '1', 'show', '102.46.62.240', '', 'DESKTOP');
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 < "2021-12-01 10:39:45";
UPDATE user SET loginip = "156.160.175.36", lastactivetime = "2021-12-01 14:09:45", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-01 14:09:45', '7', '', '156.160.175.36', '', 'DESKTOP');
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 < "2021-12-01 10:39:45";
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 < "2021-12-01 10:39:46";
UPDATE user SET loginip = "156.160.175.36", lastactivetime = "2021-12-01 14:09:46", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-01 14:09:46', '7', '', '156.160.175.36', '', 'DESKTOP');
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 < "2021-12-01 10:39:46";
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 < "2021-12-01 10:39:50";
UPDATE user SET loginip = "156.160.175.36", lastactivetime = "2021-12-01 14:09:50", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 14:09:50', '7', 'addsellBill', '156.160.175.36', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:39:50";
UPDATE user SET loginip = "156.160.175.36", lastactivetime = "2021-12-01 14:09:50", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 14:09:51', '7', 'addsellBill', '156.160.175.36', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:40:11";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:10:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:10:11', '1', '', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:42:58";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:12:58", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:12:58', '1', 'add', '102.46.62.240', '', 'DESKTOP');
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(61,1,8,585,20,'2021-12-01',1,0, '' ,0,0,0,0,0,'2021-12-01 14:12:58',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '152', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1554';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 1, 585, 0, 0
                    , 220.00, -20, 0, 0, 1, '2021-12-01 14:12:58')
                ON DUPLICATE KEY UPDATE buyprice = 220.00,
                        buyQuantity =buyQuantity+-20, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:12:58' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "20*2021-12-01*220.00," WHERE transferproductid = 1003;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '1', '20', '1', '1003', 'تحويل منتجات من المخزن', 'storemovementController.php', '172.00', '152', '1', '2021-12-01','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('585', '8', '20', '1', '2021-12-01');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 8, 585, 0, 0
                    , 220.00, 20, 0, 0, 1, '2021-12-01 14:12:58')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+20, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:12:58' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '8', '20', '0', '1003', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '20', '1', '2021-12-01','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', '8', '589', '28', '2021-12-01', '1', '0','61',null,null,'2021-12-01 14:12:58',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '144', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1570';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 1, 589, 0, 0
                    , 230.00, -28, 0, 0, 1, '2021-12-01 14:12:58')
                ON DUPLICATE KEY UPDATE buyprice = 230.00,
                        buyQuantity =buyQuantity+-28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:12:58' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "28*2021-12-01*230.00," WHERE transferproductid = 1004;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '1', '28', '1', '1004', 'تحويل منتجات من المخزن', 'storemovementController.php', '172.00', '144', '1', '2021-12-01','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('589', '8', '28', '1', '2021-12-01');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 8, 589, 0, 0
                    , 230.00, 28, 0, 0, 1, '2021-12-01 14:12:58')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:12:58' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '8', '28', '0', '1004', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '28', '1', '2021-12-01','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:42:59";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:12:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:12:59', '1', 'editshow', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:43:33";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:13:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:13:34', '1', '', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:44:00";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:14:00", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-01 14:14:00', '1', '', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:44:10";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:14:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-01 14:14:10', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:45:56";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:15:56", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:15:57', '1', 'add', '102.46.62.240', '', 'DESKTOP');
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(62,1,7,585,24,'2021-12-01',1,0, '' ,0,0,0,0,0,'2021-12-01 14:15:57',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '128', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1554';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 1, 585, 0, 0
                    , 220.00, -24, 0, 0, 1, '2021-12-01 14:15:57')
                ON DUPLICATE KEY UPDATE buyprice = 220.00,
                        buyQuantity =buyQuantity+-24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:15:57' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "24*2021-12-01*220.00," WHERE transferproductid = 1005;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '1', '24', '1', '1005', 'تحويل منتجات من المخزن', 'storemovementController.php', '152.00', '128', '1', '2021-12-01','0','0');
UPDATE storedetail SET  productquantity = '31', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1555';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 7, 585, 0, 0
                    , 220.00, 24, 0, 0, 1, '2021-12-01 14:15:57')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:15:57' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '7', '24', '0', '1005', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '7.00', '31', '1', '2021-12-01','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', '589', '28', '2021-12-01', '1', '0','62',null,null,'2021-12-01 14:15:57',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '116', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1570';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 1, 589, 0, 0
                    , 230.00, -28, 0, 0, 1, '2021-12-01 14:15:57')
                ON DUPLICATE KEY UPDATE buyprice = 230.00,
                        buyQuantity =buyQuantity+-28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:15:57' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "28*2021-12-01*230.00," WHERE transferproductid = 1006;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '1', '28', '1', '1006', 'تحويل منتجات من المخزن', 'storemovementController.php', '144.00', '116', '1', '2021-12-01','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('589', '7', '28', '1', '2021-12-01');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 7, 589, 0, 0
                    , 230.00, 28, 0, 0, 1, '2021-12-01 14:15:57')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:15:57' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '7', '28', '0', '1006', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '28', '1', '2021-12-01','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', '565', '7', '2021-12-01', '1', '0','62',null,null,'2021-12-01 14:15:57',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1484';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 1, 565, 0, 0
                    , 150.00, -7, 0, 0, 1, '2021-12-01 14:15:57')
                ON DUPLICATE KEY UPDATE buyprice = 150.00,
                        buyQuantity =buyQuantity+-7, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:15:57' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "7*2021-12-01*150.00," WHERE transferproductid = 1007;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '1', '7', '1', '1007', 'تحويل منتجات من المخزن', 'storemovementController.php', '7.00', '0', '1', '2021-12-01','0','0');
UPDATE storedetail SET  productquantity = '30', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1514';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 7, 565, 0, 0
                    , 150.00, 7, 0, 0, 1, '2021-12-01 14:15:57')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+7, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:15:57' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '7', '7', '0', '1007', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '23.00', '30', '1', '2021-12-01','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:45:58";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:15:58", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:15:58', '1', 'editshow', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:58:21";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:28:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:28:21', '1', '', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:59:11";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:29:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:29:11', '1', 'add', '102.46.62.240', '', 'DESKTOP');
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(63,1,4,585,24,'2021-12-01',1,0, '' ,0,0,0,0,0,'2021-12-01 14:29:11',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '104', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1554';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 1, 585, 0, 0
                    , 220.00, -24, 0, 0, 1, '2021-12-01 14:29:11')
                ON DUPLICATE KEY UPDATE buyprice = 220.00,
                        buyQuantity =buyQuantity+-24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:29:11' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "24*2021-12-01*220.00," WHERE transferproductid = 1008;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '1', '24', '1', '1008', 'تحويل منتجات من المخزن', 'storemovementController.php', '128.00', '104', '1', '2021-12-01','0','0');
UPDATE storedetail SET  productquantity = '32', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1560';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 4, 585, 0, 0
                    , 220.00, 24, 0, 0, 1, '2021-12-01 14:29:11')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:29:11' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '4', '24', '0', '1008', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '8.00', '32', '1', '2021-12-01','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', '4', '589', '28', '2021-12-01', '1', '0','63',null,null,'2021-12-01 14:29:11',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '88', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1570';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 1, 589, 0, 0
                    , 230.00, -28, 0, 0, 1, '2021-12-01 14:29:11')
                ON DUPLICATE KEY UPDATE buyprice = 230.00,
                        buyQuantity =buyQuantity+-28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:29:11' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "28*2021-12-01*230.00," WHERE transferproductid = 1009;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '1', '28', '1', '1009', 'تحويل منتجات من المخزن', 'storemovementController.php', '116.00', '88', '1', '2021-12-01','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('589', '4', '28', '1', '2021-12-01');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 4, 589, 0, 0
                    , 230.00, 28, 0, 0, 1, '2021-12-01 14:29:11')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:29:11' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '4', '28', '0', '1009', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '28', '1', '2021-12-01','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:59:11";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:29:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:29:11', '1', 'editshow', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 10:59:22";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:29:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:29:22', '1', '', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:00:20";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:30:20", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:30:20', '1', 'add', '102.46.62.240', '', 'DESKTOP');
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(64,1,3,585,28,'2021-12-01',1,0, '' ,0,0,0,0,0,'2021-12-01 14:30:20',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '76', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1554';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 1, 585, 0, 0
                    , 220.00, -28, 0, 0, 1, '2021-12-01 14:30:20')
                ON DUPLICATE KEY UPDATE buyprice = 220.00,
                        buyQuantity =buyQuantity+-28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:30:20' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "28*2021-12-01*220.00," WHERE transferproductid = 1010;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '1', '28', '1', '1010', 'تحويل منتجات من المخزن', 'storemovementController.php', '104.00', '76', '1', '2021-12-01','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('585', '3', '28', '1', '2021-12-01');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 3, 585, 0, 0
                    , 220.00, 28, 0, 0, 1, '2021-12-01 14:30:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:30:20' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '3', '28', '0', '1010', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '28', '1', '2021-12-01','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', '3', '589', '30', '2021-12-01', '1', '0','64',null,null,'2021-12-01 14:30:20',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '58', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1570';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 1, 589, 0, 0
                    , 230.00, -30, 0, 0, 1, '2021-12-01 14:30:20')
                ON DUPLICATE KEY UPDATE buyprice = 230.00,
                        buyQuantity =buyQuantity+-30, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:30:20' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "30*2021-12-01*230.00," WHERE transferproductid = 1011;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '1', '30', '1', '1011', 'تحويل منتجات من المخزن', 'storemovementController.php', '88.00', '58', '1', '2021-12-01','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('589', '3', '30', '1', '2021-12-01');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 3, 589, 0, 0
                    , 230.00, 30, 0, 0, 1, '2021-12-01 14:30:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+30, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:30:20' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '3', '30', '0', '1011', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '30', '1', '2021-12-01','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:00:20";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:30:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:30:21', '1', 'editshow', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:00:55";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:30:55", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:30:55', '1', '', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:01:50";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:31:51", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:31:51', '1', 'add', '102.46.62.240', '', 'DESKTOP');
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(65,1,6,585,24,'2021-12-01',1,0, '' ,0,0,0,0,0,'2021-12-01 14:31:51',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '52', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1554';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 1, 585, 0, 0
                    , 220.00, -24, 0, 0, 1, '2021-12-01 14:31:51')
                ON DUPLICATE KEY UPDATE buyprice = 220.00,
                        buyQuantity =buyQuantity+-24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:31:51' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "24*2021-12-01*220.00," WHERE transferproductid = 1012;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '1', '24', '1', '1012', 'تحويل منتجات من المخزن', 'storemovementController.php', '76.00', '52', '1', '2021-12-01','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('585', '6', '24', '1', '2021-12-01');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 6, 585, 0, 0
                    , 220.00, 24, 0, 0, 1, '2021-12-01 14:31:51')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:31:51' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '6', '24', '0', '1012', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '24', '1', '2021-12-01','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', '6', '589', '28', '2021-12-01', '1', '0','65',null,null,'2021-12-01 14:31:51',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '30', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1570';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 1, 589, 0, 0
                    , 230.00, -28, 0, 0, 1, '2021-12-01 14:31:51')
                ON DUPLICATE KEY UPDATE buyprice = 230.00,
                        buyQuantity =buyQuantity+-28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:31:51' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "28*2021-12-01*230.00," WHERE transferproductid = 1013;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '1', '28', '1', '1013', 'تحويل منتجات من المخزن', 'storemovementController.php', '58.00', '30', '1', '2021-12-01','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('589', '6', '28', '1', '2021-12-01');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 6, 589, 0, 0
                    , 230.00, 28, 0, 0, 1, '2021-12-01 14:31:51')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:31:51' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '6', '28', '0', '1013', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '28', '1', '2021-12-01','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:01:51";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:31:51", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:31:51', '1', 'editshow', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:02:05";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:32:05", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:32:05', '1', '', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:03:07";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:33:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:33:07', '1', 'add', '102.46.62.240', '', 'DESKTOP');
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(66,1,5,585,28,'2021-12-01',1,0, '' ,0,0,0,0,0,'2021-12-01 14:33:07',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '24', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1554';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 1, 585, 0, 0
                    , 220.00, -28, 0, 0, 1, '2021-12-01 14:33:08')
                ON DUPLICATE KEY UPDATE buyprice = 220.00,
                        buyQuantity =buyQuantity+-28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:33:08' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "28*2021-12-01*220.00," WHERE transferproductid = 1014;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '1', '28', '1', '1014', 'تحويل منتجات من المخزن', 'storemovementController.php', '52.00', '24', '1', '2021-12-01','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('585', '5', '28', '1', '2021-12-01');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 5, 585, 0, 0
                    , 220.00, 28, 0, 0, 1, '2021-12-01 14:33:08')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:33:08' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '5', '28', '0', '1014', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '28', '1', '2021-12-01','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', '5', '589', '30', '2021-12-01', '1', '0','66',null,null,'2021-12-01 14:33:08',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1570';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 1, 589, 0, 0
                    , 230.00, -30, 0, 0, 1, '2021-12-01 14:33:08')
                ON DUPLICATE KEY UPDATE buyprice = 230.00,
                        buyQuantity =buyQuantity+-30, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:33:08' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "30*2021-12-01*230.00," WHERE transferproductid = 1015;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '1', '30', '1', '1015', 'تحويل منتجات من المخزن', 'storemovementController.php', '30.00', '0', '1', '2021-12-01','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('589', '5', '30', '1', '2021-12-01');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 5, 589, 0, 0
                    , 230.00, 30, 0, 0, 1, '2021-12-01 14:33:08')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+30, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 14:33:08' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '5', '30', '0', '1015', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '30', '1', '2021-12-01','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:03:08";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 14:33:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 14:33:08', '1', 'editshow', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:11:34";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 14:41:34", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 14:41:34', '6', 'addsellBill', '41.43.10.231', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:30:06";
UPDATE user SET loginip = "102.44.127.243", lastactivetime = "2021-12-01 15:00:06", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-01 15:00:06', '8', '', '102.44.127.243', '', 'DESKTOP');
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 < "2021-12-01 11:30:06";
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 < "2021-12-01 11:30:07";
UPDATE user SET loginip = "102.44.127.243", lastactivetime = "2021-12-01 15:00:07", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-01 15:00:07', '8', '', '102.44.127.243', '', 'DESKTOP');
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 < "2021-12-01 11:30:07";
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 < "2021-12-01 11:30:08";
UPDATE user SET loginip = "102.44.127.243", lastactivetime = "2021-12-01 15:00:08", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-01 15:00:08', '8', '', '102.44.127.243', '', 'DESKTOP');
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 < "2021-12-01 11:30:08";
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 < "2021-12-01 11:30:14";
UPDATE user SET loginip = "102.44.127.243", lastactivetime = "2021-12-01 15:00:14", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 15:00:14', '8', 'addsellBill', '102.44.127.243', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:41:18";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 15:11:18", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 15:11:18', '6', 'addAndRetuen', '41.43.10.231', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061a76d7ee324d
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-01 14:41:34', '061a76d7ee324d', '1', '0.00', '0', '0', '1', '915', '915', '915', '0', '4', '2021-12-01 15:11:18', '', '6', '0', 'نقدي', '4', '0', '3', '0', 'نقدي', '4' ,'0','','','','','-1','0','0','0','0','0','915','0','','0','0','915','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '6' WHERE clientid = '1';
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('1','0.00','0','0','اضافة فاتورة مبيعات','135', '0', '2021-12-01 15:11:18', '6', 'sellbillController.php', 'اضافة فاتورة مبيعات', '915', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+3 where id = 1900;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('150','00565', '135', '1', '565', '3', '230', '690', '0', '', '0', '2021-12-01 15:11:18', '565', '0.00', '0', '4','0','','','0','0','0','0','0','0','0','0','','1900-3,');
UPDATE sellbilldetail SET  lastbuyprice = 150.00 , meanbuyprice = 150.00, lastbuyprice_withDiscount = 150.00, meanbuyprice_withDiscount = 150.00
                where sellbilldetailid = 312;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (565, '2021-12-01', 690, 450, 450
                    , 450, 450, 450, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 3, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+690, sellCostBuyPrice =sellCostBuyPrice+450
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+450, sellCostMeanBuyPrice = sellCostMeanBuyPrice+450
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+450, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+450
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+3
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (4, '2021-12-01', 690, 450, 450
                    , 450, 450, 450, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+690, sellCostBuyPrice =sellCostBuyPrice+450
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+450, sellCostMeanBuyPrice = sellCostMeanBuyPrice+450
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+450, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+450
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '6', userid = '6', storedetaildate = '2021-12-01 15:11:18' WHERE storedetailid = '1509';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '4', '3', '1', '135', 'اضافة فاتورة مبيعات', 'sellbillController.php', '9.00', '6', '6', '2021-12-01 15:11:18','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1988;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('220','00585', '135', '1', '585', '1', '225', '225', '0', '', '0', '2021-12-01 15:11:18', '585', '0.00', '0', '4','0','','','0','0','0','0','0','0','0','0','','1988-1,');
UPDATE sellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where sellbilldetailid = 313;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (585, '2021-12-01', 225, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+225, sellCostBuyPrice =sellCostBuyPrice+220
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+220, sellCostMeanBuyPrice = sellCostMeanBuyPrice+220
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+220, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+220
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (4, '2021-12-01', 225, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+225, sellCostBuyPrice =sellCostBuyPrice+220
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+220, sellCostMeanBuyPrice = sellCostMeanBuyPrice+220
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+220, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+220
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '31', userid = '6', storedetaildate = '2021-12-01 15:11:18' WHERE storedetailid = '1560';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '4', '1', '1', '135', 'اضافة فاتورة مبيعات', 'sellbillController.php', '32.00', '31', '6', '2021-12-01 15:11:18','0','0');
UPDATE save SET  savecurrentvalue = '11905',  userid = '6' WHERE saveid = '4';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('10990.00','915', '0', '4', 'اضافة فاتورة مبيعات', '135', '11905', '2021-12-01 15:11:18', '6',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-01', 915, 670, 670
                    , 670, 670, 670, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+915, sellCostBuyPrice =sellCostBuyPrice+670
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+670, sellCostMeanBuyPrice = sellCostMeanBuyPrice+670
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+670, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+670
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-01', 915, 670, 670
                    , 670, 670, 670, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+915, sellCostBuyPrice =sellCostBuyPrice+670
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+670, sellCostMeanBuyPrice = sellCostMeanBuyPrice+670
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+670, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+670
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, 915, 670, 670
                    , 670, 670, 670, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+915, netSellCostBuyPrice = netSellCostBuyPrice+670
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+670
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+670
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+670
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+670
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061a76d7ee324d and sellbillId = 135 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:41:18";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 15:11:18", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 15:11:18', '6', 'addsellBill', '41.43.10.231', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:41:23";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 15:11:23", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-01 15:11:23', '6', '', '41.43.10.231', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:41:50";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 15:11:51", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-01 15:11:53', '6', 'add', '41.43.10.231', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('4', '', '', '10', '2021-12-01', '6', '0','-1','4','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '11895',  userid = '6' WHERE saveid = '4';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('11905.00','10', '1', '4', 'إضافة مصروف', '5', '11895', '2021-12-01 15:11:53', '6',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '10', '10', '2021-12-01', '6', '0', '0', '2021-12-01 15:11:53','اضافة اسم مصروف(  )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('702', '147', '10', '','0');
UPDATE accountstree SET name = 'نظافة', customName = 'نظافة', parent = '14', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-08', itemtype2 = '0', theValue = '10', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '147';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('702', '138', '10', '','0');
UPDATE accountstree SET name = 'خزينة محل روني', customName = 'خزينة محل روني', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '990', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '138';
UPDATE expenses SET expensestypeid = '4', expensesname = '', expensesdetails = '', expensesValue = '10.00', expensesdate = '2021-12-01', userid = '6', conditions = '0',saveid = '4' , dailyentryid = '702', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '5';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:41:54";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 15:11:54", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-01 15:11:54', '6', 'sucess', '41.43.10.231', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:41:57";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 15:11:57", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-01 15:11:57', '6', 'show', '41.43.10.231', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:41:58";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 15:11:58", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-01 15:11:58', '6', '', '41.43.10.231', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 11:42:03";
UPDATE user SET loginip = "41.43.10.231", lastactivetime = "2021-12-01 15:12:03", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 15:12:03', '6', 'addsellBill', '41.43.10.231', '', 'DESKTOP');
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 < "2021-12-01 14:10:28";
UPDATE user SET loginip = "197.41.122.222", lastactivetime = "2021-12-01 17:40:28", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-01 17:40:28', '3', '', '197.41.122.222', '', 'DESKTOP');
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 < "2021-12-01 14:10:29";
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 < "2021-12-01 14:10:38";
UPDATE user SET loginip = "197.41.122.222", lastactivetime = "2021-12-01 17:40:38", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 17:40:38', '3', 'addsellBill', '197.41.122.222', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:24:21";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 18:54:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 18:54:21', '1', '', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:24:43";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 18:54:43", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 18:54:43', '1', 'add', '102.46.62.240', '', 'DESKTOP');
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(67,1,7,585,24,'2021-12-01',1,0, '' ,0,0,0,0,0,'2021-12-01 18:54:43',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1554';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 1, 585, 0, 0
                    , 220.00, -24, 0, 0, 1, '2021-12-01 18:54:43')
                ON DUPLICATE KEY UPDATE buyprice = 220.00,
                        buyQuantity =buyQuantity+-24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 18:54:43' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "24*2021-12-01*220.00," WHERE transferproductid = 1016;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '1', '24', '1', '1016', 'تحويل منتجات من المخزن', 'storemovementController.php', '24.00', '0', '1', '2021-12-01','0','0');
UPDATE storedetail SET  productquantity = '55', userid = '1', storedetaildate = '2021-12-01' WHERE storedetailid = '1555';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 7, 585, 0, 0
                    , 220.00, 24, 0, 0, 1, '2021-12-01 18:54:43')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-01 18:54:43' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '7', '24', '0', '1016', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '31.00', '55', '1', '2021-12-01','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:24:44";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 18:54:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-01 18:54:44', '1', 'editshow', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:26:56";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 18:56:56", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 18:56:56', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:27:09";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 18:57:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 18:57:09', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:27:31";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 18:57:32", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 18:57:32', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:28:17";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 18:58:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 18:58:17', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:28:41";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 18:58:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementKindSaveController.php', '2021-12-01 18:58:41', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:28:49";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 18:58:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-01 18:58:49', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:28:58";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 18:58:58", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-01 18:58:58', '1', 'edit', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:29:16";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 18:59:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 18:59:16', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:29:23";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 18:59:23", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 18:59:23', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:29:44";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 18:59:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 18:59:44', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:29:47";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 18:59:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 18:59:47', '1', '', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:32:57";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 19:02:57", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 19:02:57', '1', 'add', '102.46.62.240', '', 'DESKTOP');
INSERT INTO impotencetreatmentsuppliersave (typesimpotencetreatmentid, saveid, supplierid, impotencetreatmentsuppliersavetype, impotencetreatmentsuppliersavebefore, impotencetreatmentsuppliersavetamount, impotencetreatmentsuppliersaveafter, impotencetreatmentsuppliersavecomment, conditions, impotencetreatmentsuppliersavedate, userid, tablename) VALUES ('-1', '4', '-1', '1', '11895.00', '10990', '905', '', '0', '2021-12-01 19:02:57', '1', 'settlementsaveController.php');
INSERT INTO supplierdebtchange (supplierid, supplierdebtchangebefore, supplierdebtchangeamount, supplierdebtchangetype, processname, supplierdebtchangemodelid, supplierdebtchangeafter, supplierdebtchangedate, userid, tablename, comment, dailyentryid,saveid, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor) VALUES ('-1', '', '10990', '0', 'اضافة معالجة عجز / ', '1', '10990', '2021-12-01', '1', 'supplierPayedDeptController.php', '', '0','4', '0','1','1','10990','1');
UPDATE supplier SET  suppliercurrentDebt = '10990', userid = '1', supplierdate = '2021-12-01'   WHERE supplierid = '-1';
INSERT INTO accountstree (name, customName, parent, itemtype, itemfrom, notes, del, userid, mydate, itemtype2, theValue, theOrder, layingOrder,reportid) VALUES ('', '', '10', '1', '0', '', '0', '1', '2021-12-01', '1', '0', '0', '','2');
UPDATE supplierdebtchange SET supplierid = '-1', supplierdebtchangebefore = '0.00', supplierdebtchangeamount = '10990.00', supplierdebtchangetype = '0', processname = 'اضافة معالجة عجز / ', supplierdebtchangemodelid = '1', supplierdebtchangeafter = '10990.00', supplierdebtchangedate = '2021-12-01 00:00:00', userid = '1', tablename = 'supplierPayedDeptController.php', comment = '', dailyentryid = '0',saveid = '4',currencyId='1',conversionFactor='1',payedInCurrency='10990',saveConversionFactor='1' WHERE supplierdebtchangeid = '1';
UPDATE save SET  savecurrentvalue = '905',  userid = '1' WHERE saveid = '4';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('11895.00','10990', '1', '4', 'تسوية خزنة بالنقص', '-1', '905', '2021-12-01 19:02:58', '1',  'settlementsaveController.php','0','');
UPDATE savedaily SET  savedailymodelid = '192' WHERE savedailyid = '192';
BEGIN;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '10990', '10990', '2021-12-01', '1', '0', '0', '2021-12-01 19:02:58','اضافة معالجة عجز ( بالخصم )','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('703', '27', '10990', '','0');
UPDATE accountstree SET name = 'معالجة عجز خزنة', customName = 'معالجة عجز خزنة', parent = '3', itemtype = '0', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-06-15', itemtype2 = '1', theValue = '10990', theOrder = '0', layingOrder = '35',reportid = '1' WHERE id = '27';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('703', '138', '10990', '','0');
UPDATE accountstree SET name = 'خزينة محل روني', customName = 'خزينة محل روني', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-10000', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '138';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:32:59";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 19:02:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 19:02:59', '1', 'sucess', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:33:02";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 19:03:02", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 19:03:02', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:33:17";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 19:03:18", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('billsettingsController.php', '2021-12-01 19:03:18', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:33:39";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 19:03:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 19:03:39', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:33:51";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 19:03:51", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 19:03:51', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:35:28";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 19:05:28", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 19:05:28', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:35:35";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 19:05:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 19:05:35', '1', '', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:38:32";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 19:08:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 19:08:33', '1', 'add', '102.46.62.240', '', 'DESKTOP');
INSERT INTO impotencetreatmentsuppliersave (typesimpotencetreatmentid, saveid, supplierid, impotencetreatmentsuppliersavetype, impotencetreatmentsuppliersavebefore, impotencetreatmentsuppliersavetamount, impotencetreatmentsuppliersaveafter, impotencetreatmentsuppliersavecomment, conditions, impotencetreatmentsuppliersavedate, userid, tablename) VALUES ('-1', '8', '-1', '1', '34413.00', '33063', '1350', '', '0', '2021-12-01 19:08:33', '1', 'settlementsaveController.php');
INSERT INTO supplierdebtchange (supplierid, supplierdebtchangebefore, supplierdebtchangeamount, supplierdebtchangetype, processname, supplierdebtchangemodelid, supplierdebtchangeafter, supplierdebtchangedate, userid, tablename, comment, dailyentryid,saveid, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor) VALUES ('-1', '', '33063', '0', 'اضافة معالجة عجز / ', '2', '33063', '2021-12-01', '1', 'supplierPayedDeptController.php', '', '0','8', '0','1','1','33063','1');
UPDATE supplier SET  suppliercurrentDebt = '33063', userid = '1', supplierdate = '2021-12-01'   WHERE supplierid = '-1';
UPDATE supplierdebtchange SET supplierid = '-1', supplierdebtchangebefore = '0.00', supplierdebtchangeamount = '33063.00', supplierdebtchangetype = '0', processname = 'اضافة معالجة عجز / ', supplierdebtchangemodelid = '2', supplierdebtchangeafter = '33063.00', supplierdebtchangedate = '2021-12-01 00:00:00', userid = '1', tablename = 'supplierPayedDeptController.php', comment = '', dailyentryid = '0',saveid = '8',currencyId='1',conversionFactor='1',payedInCurrency='33063',saveConversionFactor='1' WHERE supplierdebtchangeid = '2';
UPDATE save SET  savecurrentvalue = '1350',  userid = '1' WHERE saveid = '8';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('34413.00','33063', '1', '8', 'تسوية خزنة بالنقص', '-1', '1350', '2021-12-01 19:08:33', '1',  'settlementsaveController.php','0','');
UPDATE savedaily SET  savedailymodelid = '193' WHERE savedailyid = '193';
BEGIN;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '33063', '33063', '2021-12-01', '1', '0', '0', '2021-12-01 19:08:33','اضافة معالجة عجز ( بالخصم )','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('704', '27', '33063', '','0');
UPDATE accountstree SET name = 'معالجة عجز خزنة', customName = 'معالجة عجز خزنة', parent = '3', itemtype = '0', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-06-15', itemtype2 = '1', theValue = '44053', theOrder = '0', layingOrder = '35',reportid = '1' WHERE id = '27';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('704', '142', '33063', '','0');
UPDATE accountstree SET name = 'خزينة محل ابو كريم', customName = 'خزينة محل ابو كريم', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-33063', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '142';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:38:33";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 19:08:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 19:08:34', '1', 'sucess', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:38:36";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 19:08:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-01 19:08:36', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:42:03";
UPDATE user SET loginip = "197.41.122.222", lastactivetime = "2021-12-01 19:12:03", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storedetailController.php', '2021-12-01 19:12:03', '3', '', '197.41.122.222', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:42:11";
UPDATE user SET loginip = "197.41.122.222", lastactivetime = "2021-12-01 19:12:11", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-01 19:12:11', '3', '', '197.41.122.222', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:42:11";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 19:12:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-01 19:12:11', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:42:48";
UPDATE user SET loginip = "197.41.122.222", lastactivetime = "2021-12-01 19:12:48", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 19:12:48', '3', 'addsellBill', '197.41.122.222', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-01 15:42:49";
UPDATE user SET loginip = "102.46.62.240", lastactivetime = "2021-12-01 19:12:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-01 19:12:49', '1', 'show', '102.46.62.240', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 7;
UPDATE user SET loginip = "" WHERE userid = 1;
UPDATE user SET loginip = "" WHERE userid = 1;
UPDATE user SET loginip = "" WHERE userid = 1;
