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-11-18 07:15:10";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 10:45:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-11-18 10:45:11', '1', '', '197.56.104.132', '', '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-11-18',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-11-18 07:15:12";
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-11-18 07:15:19";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 10:45:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-11-18 10:45:19', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 07:33:22";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 11:03:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreportbills.php', '2021-11-18 11:03:24', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 07:33:35";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 11:03:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreportbills.php', '2021-11-18 11:03:35', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 07:33:44";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 11:03:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreportbills.php', '2021-11-18 11:03:44', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 07:34:18";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 11:04:18", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreportbills.php', '2021-11-18 11:04:18', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 07:34:32";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 11:04:32", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreportbills.php', '2021-11-18 11:04:32', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 07:34:44";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 11:04:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreportbills.php', '2021-11-18 11:04:44', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 07:34:58";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 11:04:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreportbills.php', '2021-11-18 11:04:59', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 07:35:30";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 11:05:32", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreportbills.php', '2021-11-18 11:05:32', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 07:49:42";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 11:19:42", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreportbills.php', '2021-11-18 11:19:42', '1', '', '197.56.104.132', '', '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-11-18 07:53:36";
UPDATE user SET loginip = "41.37.43.103", lastactivetime = "2021-11-18 11:23:36", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-11-18 11:23:36', '3', '', '41.37.43.103', '', '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-11-18 07:53:36";
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-11-18 07:54:01";
UPDATE user SET loginip = "41.37.43.103", lastactivetime = "2021-11-18 11:24:01", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-11-18 11:24:01', '3', 'addsellBill', '41.37.43.103', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 07:57:34";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 11:27:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreport.php', '2021-11-18 11:27:35', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 07:57:50";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 11:27:51", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreport.php', '2021-11-18 11:27:51', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 07:58:07";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 11:28:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreportbills.php', '2021-11-18 11:28:07', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 07:58:14";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 11:28:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreportbills.php', '2021-11-18 11:28:14', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:03:26";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 11:33:26", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 11:33:26', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:04:24";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 11:34:24", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 11:34:25', '1', 'add', '197.56.104.132', '', '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 ('817','','1','150','230', '260','240', '2021-11-18', '0', '1', '0', '', '0', '0', '0', '0', '0', '150','150','150','150','150','0','53.33','60','73.33','.','0','0','0','0','0','','','0','0','0');
UPDATE product SET productName = '817', productDescription = '', productCatId = '1', productBuyPrice = '150', productSellAllPrice = '230', productSellUnitPrice = '260', productSellHalfPrice = '240', productDate = '2021-11-18', conditions = '0', userId = '1', limitamount = '0', parcode = '00565',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '150',lastbuyprice_withDiscount = '150',meanbuyprice = '150',meanbuyprice_withDiscount = '150' , productbuypricereal = '150' , buypricereal_precentage = '0' , buytotal_precentage = '53.33' , buyhalf_precentage = '60' , buypart_precentage = '73.33',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '565';
INSERT INTO productunit (unitid, productid, productnumber, productunitdate, userid, conditions,proUnitParcode,proUnitSellAllPrice,proUnitSellHalfPrice,proUnitSellUnitPrice,proUnitBuyPrice) VALUES ('1', '565', '1', '2021-11-18', '1', '0','0056501','230','240','260','150');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('565', '1', '208', '1', '2021-11-18');
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '1', '208', '0', '565', 'إضافة منتج', 'productController.php', '0', '208', '1', '2021-11-18','0','0');
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (565, 1,'2021-11-18 11:34:25',1)
                ON DUPLICATE KEY UPDATE productid = 565, edited = 1, sysdate = '2021-11-18 11:34:25', userid = 1;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '31200', '31200', '2021-11-18', '1', '0', '0', '2021-11-18 11:34:25','إضافة منتج 817 الكمية 208','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('657', '19', '31200', '','0');
UPDATE accountstree SET name = 'البضاعة (بضاعة أول المدة)', customName = 'البضاعة (بضاعة أول المدة)', parent = '6', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '5704532.5', theOrder = '0', layingOrder = '121',reportid = '0' WHERE id = '19';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('657', '7', '31200', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '6559478.3', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
UPDATE product SET productName = '817', productDescription = '', productCatId = '1', productBuyPrice = '150.00', productSellAllPrice = '230.00', productSellUnitPrice = '260.00', productSellHalfPrice = '240.00', productDate = '2021-11-18', conditions = '0', userId = '1', limitamount = '0', parcode = '00565',type ='0', expireDate = '0' , dailyentryId = '657',isService = '0',isOptic = '0',lastbuyprice = '150',lastbuyprice_withDiscount = '150',meanbuyprice = '150',meanbuyprice_withDiscount = '150' , productbuypricereal = '150' , buypricereal_precentage = '0' , buytotal_precentage = '53.33' , buyhalf_precentage = '60' , buypart_precentage = '73.33',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '565';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:04:27";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 11:34:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 11:34:27', '1', '', '197.56.104.132', '', '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-11-18 08:30:28";
UPDATE user SET loginip = "41.34.113.71", lastactivetime = "2021-11-18 12:00:29", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-11-18 12:00:29', '6', '', '41.34.113.71', '', '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-11-18 08:30: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-11-18 08:30:45";
UPDATE user SET loginip = "41.34.113.71", lastactivetime = "2021-11-18 12:00:45", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-11-18 12:00:45', '6', 'addsellBill', '41.34.113.71', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:37:22";
UPDATE user SET loginip = "41.34.113.71", lastactivetime = "2021-11-18 12:07:22", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-11-18 12:07:22', '6', 'addAndRetuen', '41.34.113.71', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06196244e2ba09
-- ----------------------------------------------------------------------------------------------------

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-11-18 12:00:46', '06196244e2ba09', '1', '0.00', '0', '0', '1', '1720', '1720', '1720', '0', '4', '2021-11-18 12:07:22', '', '6', '0', 'نقدي', '4', '0', '3', '0', 'نقدي', '8' ,'0','','','','','-1','0','0','0','0','0','1720','0','','0','0','1720','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','اضافة فاتورة مبيعات','17', '0', '2021-11-18 12:07:22', '6', 'sellbillController.php', 'اضافة فاتورة مبيعات', '1720', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+6 where id = 258;
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 ('210','00127', '17', '1', '127', '6', '220.00', '1320', '0', '', '0', '2021-11-18 12:07:22', '127', '0.00', '0', '4','0','','','0','0','0','0','0','0','0','0','','258-6,');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 1148.55, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 1148.55
                where sellbilldetailid = 36;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (127, '2021-11-18', 1320, 1260, 1260
                    , 6891.3, 1260, 6891.3, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 6, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1320, sellCostBuyPrice =sellCostBuyPrice+1260
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1260, sellCostMeanBuyPrice = sellCostMeanBuyPrice+6891.3
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1260, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+6891.3
                            , 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+6
                        , 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-11-18', 1320, 1260, 1260
                    , 6891.3, 1260, 6891.3, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1320, sellCostBuyPrice =sellCostBuyPrice+1260
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1260, sellCostMeanBuyPrice = sellCostMeanBuyPrice+6891.3
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1260, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+6891.3
                            , 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 = '17', userid = '6', storedetaildate = '2021-11-18 12:07:22' WHERE storedetailid = '681';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('127', '4', '6', '1', '17', 'اضافة فاتورة مبيعات', 'sellbillController.php', '23.00', '17', '6', '2021-11-18 12:07:22','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+2 where id = 418;
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 ('200','00302', '17', '1', '302', '2', '200', '400', '0', '', '0', '2021-11-18 12:07:22', '302', '0.00', '0', '4','0','','','0','0','0','0','0','0','0','0','','418-2,');
UPDATE sellbilldetail SET  lastbuyprice = 200.00 , meanbuyprice = 200.00, lastbuyprice_withDiscount = 200.00, meanbuyprice_withDiscount = 200.00
                where sellbilldetailid = 37;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (302, '2021-11-18', 400, 400, 400
                    , 400, 400, 400, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 2, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+400, sellCostBuyPrice =sellCostBuyPrice+400
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+400, sellCostMeanBuyPrice = sellCostMeanBuyPrice+400
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+400, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+400
                            , 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+2
                        , 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-11-18', 400, 400, 400
                    , 400, 400, 400, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+400, sellCostBuyPrice =sellCostBuyPrice+400
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+400, sellCostMeanBuyPrice = sellCostMeanBuyPrice+400
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+400, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+400
                            , 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 = '13', userid = '6', storedetaildate = '2021-11-18 12:07:22' WHERE storedetailid = '761';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('302', '4', '2', '1', '17', 'اضافة فاتورة مبيعات', 'sellbillController.php', '15.00', '13', '6', '2021-11-18 12:07:22','0','0');
UPDATE save SET  savecurrentvalue = '3160',  userid = '6' WHERE saveid = '4';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1440.00','1720', '0', '4', 'اضافة فاتورة مبيعات', '17', '3160', '2021-11-18 12:07:22', '6',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-11-18', 1720, 1660, 1660
                    , 7291.3, 1660, 7291.3, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1720, sellCostBuyPrice =sellCostBuyPrice+1660
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1660, sellCostMeanBuyPrice = sellCostMeanBuyPrice+7291.3
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1660, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+7291.3
                            , 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-11-18', 1720, 1660, 1660
                    , 7291.3, 1660, 7291.3, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1720, sellCostBuyPrice =sellCostBuyPrice+1660
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1660, sellCostMeanBuyPrice = sellCostMeanBuyPrice+7291.3
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1660, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+7291.3
                            , 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, 1720, 1660, 1660
                    , 7291.3, 1660, 7291.3, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+1720, netSellCostBuyPrice = netSellCostBuyPrice+1660
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+1660
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+7291.3
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+1660
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+7291.3
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06196244e2ba09 and sellbillId = 17 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:37:23";
UPDATE user SET loginip = "41.34.113.71", lastactivetime = "2021-11-18 12:07:23", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-11-18 12:07:23', '6', 'addsellBill', '41.34.113.71', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:37:30";
UPDATE user SET loginip = "41.34.113.71", lastactivetime = "2021-11-18 12:07:30", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-11-18 12:07:30', '6', 'addsellBill', '41.34.113.71', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:38:04";
UPDATE user SET loginip = "41.34.113.71", lastactivetime = "2021-11-18 12:08:04", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-11-18 12:08:04', '6', 'addAndRetuen', '41.34.113.71', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 0619625e2f0202
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO returnsellbill (returnsellbilldate, returnsellbillserial, returnsellbillclientid, returnsellbilltotaldeptbefor, returnsellbilltotaldeptafter, returnsellbilldiscount, returnsellbilldiscounttype, returnsellbilltotalbill, returnsellbillaftertotalbill, returnsellbilltotalpayed, returnsellbillfinalbill, returnsellbillstoreid, returnsellbillsysdate,comment, userid, conditions, returnsellbillclientname, returnsellbillsaveid, returnsellbildirectpayment, billnameid, sellerid, tempclientName, returnsellQuantity,tax, carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,delbyuserid,billReservation,billReservationDate,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal) VALUES ('2021-11-18 12:07:30', '0619625e2f0202', '1', '0.00', '0', '0', '1', '450', '450', '-450', '0', '4', '2021-11-18 12:08:04', '', '6', '0', 'نقدي','4', '0', '5', '0', 'نقدي', '2', '0', '', '','','','-1','0','0','0','','0','-450','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','1','اضافة فاتورة مردوات مبيعات','5', '0', '2021-11-18 12:08:04', '6', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '450', '0', null, '0', null, null,'', '0','1','1','0','1');
INSERT INTO returnsellbilldetail (buyprice, parcode, returnsellbillid, returnsellbilldetailcatid, returnsellbilldetailproductid, returnsellbilldetailquantity, returnsellbilldetailprice, returnsellbilldetailtotalprice, conditions, note, pricetype, discountvalue, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,pricetypepro) VALUES ('220.00', '00515', '5', '1', '515', '1', '230.00', '230', '0', '', '0', '0', '515', '0.00', '0','4','0','','','0','0','0','0','0','0');
UPDATE returnsellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where returnsellbilldetailid = 6;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (515, '2021-11-18', 0, 0, 0
                    , 0, 0, 0, 0
                    , 230, 220, 220, 220
                    , 220, 220, 0, 0, 1)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+230, returnSellCostBuyPrice = returnSellCostBuyPrice+220, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+220
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+220, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+220
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+220
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+0
                        , netQuantityRet = netQuantityRet+1;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (4, '2021-11-18', 0, 0, 0
                    , 0, 0, 0, 0
                    , 230, 220, 220, 220
                    , 220, 220, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+230, returnSellCostBuyPrice = returnSellCostBuyPrice+220, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+220
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+220, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+220
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+220
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '12', userid = '6', storedetaildate = '2021-11-18 12:08:04' WHERE storedetailid = '789';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('515', '4', '1', '0', '5', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '11.00', '12', '6', '2021-11-18 12:08:04','0','0');
INSERT INTO returnsellbilldetail (buyprice, parcode, returnsellbillid, returnsellbilldetailcatid, returnsellbilldetailproductid, returnsellbilldetailquantity, returnsellbilldetailprice, returnsellbilldetailtotalprice, conditions, note, pricetype, discountvalue, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,pricetypepro) VALUES ('210.00', '00517', '5', '1', '517', '1', '220.00', '220', '0', '', '0', '0', '517', '0.00', '0','4','0','','','0','0','0','0','0','0');
UPDATE returnsellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 210.00, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 210.00
                where returnsellbilldetailid = 7;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (517, '2021-11-18', 0, 0, 0
                    , 0, 0, 0, 0
                    , 220, 210, 210, 210
                    , 210, 210, 0, 0, 1)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+220, returnSellCostBuyPrice = returnSellCostBuyPrice+210, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+210
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+210, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+210
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+210
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+0
                        , netQuantityRet = netQuantityRet+1;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (4, '2021-11-18', 0, 0, 0
                    , 0, 0, 0, 0
                    , 220, 210, 210, 210
                    , 210, 210, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+220, returnSellCostBuyPrice = returnSellCostBuyPrice+210, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+210
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+210, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+210
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+210
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '15', userid = '6', storedetaildate = '2021-11-18 12:08:05' WHERE storedetailid = '791';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('517', '4', '1', '0', '5', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '14.00', '15', '6', '2021-11-18 12:08:05','0','0');
UPDATE save SET  savecurrentvalue = '2710',  userid = '6' WHERE saveid = '4';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('3160.00','450', '1', '4', 'اضافة فاتورة مردوات مبيعات', '5', '2710', '2021-11-18 12:08:05', '6',  'returnsellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-11-18', 0, 0, 0
                    , 0, 0, 0, 0
                    , 450, 430, 430, 430
                    , 430, 430, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+450, returnSellCostBuyPrice = returnSellCostBuyPrice+430, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+430
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+430, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+430
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+430
                        , 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-11-18', 0, 0, 0
                    , 0, 0, 0, 0
                    , 450, 430, 430, 430
                    , 430, 430, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+450, returnSellCostBuyPrice = returnSellCostBuyPrice+430, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+430
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+430, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+430
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+430
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -450, -430, -430
                    , -430, -430, -430, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-450, netSellCostBuyPrice = netSellCostBuyPrice+-430
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-430
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-430
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-430
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-430
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 0619625e2f0202 and sellbillId = 5 and returnsellbillId = 5
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:38:05";
UPDATE user SET loginip = "41.34.113.71", lastactivetime = "2021-11-18 12:08:05", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-11-18 12:08:05', '6', 'addsellBill', '41.34.113.71', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:38:10";
UPDATE user SET loginip = "41.34.113.71", lastactivetime = "2021-11-18 12:08:10", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-11-18 12:08:10', '6', '', '41.34.113.71', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:38:15";
UPDATE user SET loginip = "41.34.113.71", lastactivetime = "2021-11-18 12:08:15", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-11-18 12:08:15', '6', 'addsellBill', '41.34.113.71', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:43:03";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:13:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storedetailController.php', '2021-11-18 12:13:03', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:44:45";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:14:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storedetailController.php', '2021-11-18 12:14:45', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:45:34";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:15:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productcardController.php', '2021-11-18 12:15:34', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:45:46";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:15:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productcardController.php', '2021-11-18 12:15:46', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:46:15";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:16:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productcardController.php', '2021-11-18 12:16:15', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:46:26";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:16:26", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productcardController.php', '2021-11-18 12:16:26', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:47:27";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:17:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:17:27', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:47:29";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:17:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:17:29', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:47:30";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:17:30", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:17:30', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:47:48";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:17:48", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:17:48', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:49:39";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:19:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:19:39', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:49:56";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:19:57", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:19:57', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:50:02";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:20:02", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:20:02', '1', 'edit', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:50:16";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:20:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:20:16', '1', 'update', '197.56.104.132', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 302;
UPDATE productunit SET unitid = '1', productid = '302', productnumber = '1.00', productunitdate = '2021-11-18', userid = '1', conditions = '0',proUnitParcode='0030201',proUnitSellAllPrice='210',proUnitSellHalfPrice='220',proUnitSellUnitPrice ='250',proUnitBuyPrice='200' WHERE productunitid = '302';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (302, 1,'2021-11-18 12:20:16',1)
                ON DUPLICATE KEY UPDATE productid = 302, edited = 1, sysdate = '2021-11-18 12:20:16', userid = 1;
UPDATE product SET productName = '809شتوي', productDescription = '', productCatId = '1', productBuyPrice = '200', productSellAllPrice = '210', productSellUnitPrice = '241.5', productSellHalfPrice = '220.5', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00302',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '200.00',lastbuyprice_withDiscount = '200',meanbuyprice = '200.00',meanbuyprice_withDiscount = '200' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '5' , buyhalf_precentage = '5' , buypart_precentage = '15',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '302';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:50:18";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:20:18", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:20:18', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:50:41";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:20:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 12:20:41', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:51:05";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:21:05", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 12:21:05', '1', 'add', '197.56.104.132', '', '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(28,1,4,563,30,'2021-11-18',1,0, '' ,0,0,0,0,0,'2021-11-18 12:21:06',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '24', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1482';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 563, 0, 0
                    , 210.00, -30, 0, 0, 1, '2021-11-18 12:21:06')
                ON DUPLICATE KEY UPDATE buyprice = 210.00,
                        buyQuantity =buyQuantity+-30, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 12:21:06' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "30*2021-11-18*210.00," WHERE transferproductid = 924;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '1', '30', '1', '924', 'تحويل منتجات من المخزن', 'storemovementController.php', '54.00', '24', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('563', '4', '30', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 4, 563, 0, 0
                    , 210.00, 30, 0, 0, 1, '2021-11-18 12:21:06')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+30, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 12:21:06' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '4', '30', '0', '924', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '30', '1', '2021-11-18','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:51:06";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:21:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 12:21:06', '1', 'sucess', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:51:08";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:21:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 12:21:09', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:51:40";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:21:40", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 12:21:40', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:52:22";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:22:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 12:22:22', '1', 'add', '197.56.104.132', '', '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(29,1,8,560,16,'2021-11-18',1,0, '' ,0,0,0,0,0,'2021-11-18 12:22:22',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '7', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1479';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 560, 0, 0
                    , 220.00, -16, 0, 0, 1, '2021-11-18 12:22:22')
                ON DUPLICATE KEY UPDATE buyprice = 220.00,
                        buyQuantity =buyQuantity+-16, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 12:22:22' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "16*2021-11-18*220.00," WHERE transferproductid = 925;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('560', '1', '16', '1', '925', 'تحويل منتجات من المخزن', 'storemovementController.php', '23.00', '7', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('560', '8', '16', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 8, 560, 0, 0
                    , 220.00, 16, 0, 0, 1, '2021-11-18 12:22:22')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+16, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 12:22:22' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('560', '8', '16', '0', '925', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '16', '1', '2021-11-18','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', '563', '10', '2021-11-18', '1', '0','29',null,null,'2021-11-18 12:22:22',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '14', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1482';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 563, 0, 0
                    , 210.00, -10, 0, 0, 1, '2021-11-18 12:22:22')
                ON DUPLICATE KEY UPDATE buyprice = 210.00,
                        buyQuantity =buyQuantity+-10, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 12:22:22' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "10*2021-11-18*210.00," WHERE transferproductid = 926;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '1', '10', '1', '926', 'تحويل منتجات من المخزن', 'storemovementController.php', '24.00', '14', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('563', '8', '10', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 8, 563, 0, 0
                    , 210.00, 10, 0, 0, 1, '2021-11-18 12:22:22')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+10, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 12:22:22' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '8', '10', '0', '926', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '10', '1', '2021-11-18','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:52:23";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:22:23", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 12:22:23', '1', 'sucess', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 08:52:25";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:22:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 12:22:25', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:01:27";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:31:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:31:27', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:07:48";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:37:48", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:37:48', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:08:47";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:38:48", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:38:48', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:17:59";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:47:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:47:59', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:18:07";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:48:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:48:07', '1', 'edit', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:18:48";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:48:48", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:48:48', '1', 'update', '197.56.104.132', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 383;
UPDATE productunit SET unitid = '1', productid = '383', productnumber = '1.00', productunitdate = '2021-11-18', userid = '1', conditions = '0',proUnitParcode='0038301',proUnitSellAllPrice='210',proUnitSellHalfPrice='210',proUnitSellUnitPrice ='250',proUnitBuyPrice='185' WHERE productunitid = '383';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (383, 1,'2021-11-18 12:48:48',1)
                ON DUPLICATE KEY UPDATE productid = 383, edited = 1, sysdate = '2021-11-18 12:48:48', userid = 1;
UPDATE product SET productName = 'ديجيتال 634', productDescription = '', productCatId = '1', productBuyPrice = '185', productSellAllPrice = '190', productSellUnitPrice = '220.21', productSellHalfPrice = '200.67', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00383',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '185.00',lastbuyprice_withDiscount = '185',meanbuyprice = '185.00',meanbuyprice_withDiscount = '185' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '2.7' , buyhalf_precentage = '8.47' , buypart_precentage = '19.03',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '383';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:18:50";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:48:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:48:50', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:22:41";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:52:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:52:41', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:23:05";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:53:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 12:53:06', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:23:41";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:53:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-11-18 12:53:41', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:24:55";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:54:55", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreport.php', '2021-11-18 12:54:55', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:25:11";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:55:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreport.php', '2021-11-18 12:55:12', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:25:25";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:55:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreport.php', '2021-11-18 12:55:25', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:26:00";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:56:00", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreport.php', '2021-11-18 12:56:00', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:26:23";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:56:23", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreport.php', '2021-11-18 12:56:23', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:26:35";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:56:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreport.php', '2021-11-18 12:56:36', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:26:45";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:56:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreport.php', '2021-11-18 12:56:46', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:26:55";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:56:55", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreport.php', '2021-11-18 12:56:55', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:27:22";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:57:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreport.php', '2021-11-18 12:57:22', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:27:35";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:57:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreport.php', '2021-11-18 12:57:36', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:29:15";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:59:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreport.php', '2021-11-18 12:59:16', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:29:32";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 12:59:32", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('salesreport.php', '2021-11-18 12:59:32', '1', '', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:46:46";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:16:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:16:46', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:47:01";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:17:02", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:17:02', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:47:24";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:17:24", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:17:24', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE product SET productName = 'كريشه 104', productDescription = '', productCatId = '1', productBuyPrice = '180.00', productSellAllPrice = '165.00', productSellUnitPrice = '165.00', productSellHalfPrice = '165.00', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00480',type ='0', expireDate = '0' , dailyentryId = '480',isService = '0',isOptic = '0',lastbuyprice = '180.00',lastbuyprice_withDiscount = '180',meanbuyprice = '180.00',meanbuyprice_withDiscount = '180' , productbuypricereal = '0.00' , buypricereal_precentage = '0.00' , buytotal_precentage = '0.00' , buyhalf_precentage = '0.00' , buypart_precentage = '0.00',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '480';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (480, 1,'2021-11-18 13:17:38',1)
                ON DUPLICATE KEY UPDATE productid = 480, edited = 1, sysdate = '2021-11-18 13:17:38', userid = 1;
UPDATE product SET productName = 'كريشه 104', productDescription = '', productCatId = '1', productBuyPrice = '180.00', productSellAllPrice = '165.00', productSellUnitPrice = '165.00', productSellHalfPrice = '175.00', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00480',type ='0', expireDate = '0' , dailyentryId = '480',isService = '0',isOptic = '0',lastbuyprice = '180.00',lastbuyprice_withDiscount = '180',meanbuyprice = '180.00',meanbuyprice_withDiscount = '180' , productbuypricereal = '0.00' , buypricereal_precentage = '0.00' , buytotal_precentage = '0.00' , buyhalf_precentage = '0.00' , buypart_precentage = '0.00',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '480';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (480, 1,'2021-11-18 13:17:44',1)
                ON DUPLICATE KEY UPDATE productid = 480, edited = 1, sysdate = '2021-11-18 13:17:44', userid = 1;
UPDATE product SET productName = 'كريشه 104', productDescription = '', productCatId = '1', productBuyPrice = '180.00', productSellAllPrice = '165.00', productSellUnitPrice = '195.00', productSellHalfPrice = '175.00', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00480',type ='0', expireDate = '0' , dailyentryId = '480',isService = '0',isOptic = '0',lastbuyprice = '180.00',lastbuyprice_withDiscount = '180',meanbuyprice = '180.00',meanbuyprice_withDiscount = '180' , productbuypricereal = '0.00' , buypricereal_precentage = '0.00' , buytotal_precentage = '0.00' , buyhalf_precentage = '0.00' , buypart_precentage = '0.00',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '480';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (480, 1,'2021-11-18 13:17:50',1)
                ON DUPLICATE KEY UPDATE productid = 480, edited = 1, sysdate = '2021-11-18 13:17:50', userid = 1;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:48:00";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:18:00", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:18:00', '1', 'edit', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:48:13";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:18:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:18:13', '1', 'update', '197.56.104.132', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 480;
UPDATE productunit SET unitid = '1', productid = '480', productnumber = '1.00', productunitdate = '2021-11-18', userid = '1', conditions = '0',proUnitParcode='0048001',proUnitSellAllPrice='165',proUnitSellHalfPrice='175',proUnitSellUnitPrice ='195',proUnitBuyPrice='180' WHERE productunitid = '480';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (480, 1,'2021-11-18 13:18:13',1)
                ON DUPLICATE KEY UPDATE productid = 480, edited = 1, sysdate = '2021-11-18 13:18:13', userid = 1;
UPDATE product SET productName = 'كريشه 104', productDescription = '', productCatId = '1', productBuyPrice = '180', productSellAllPrice = '165', productSellUnitPrice = '195', productSellHalfPrice = '175', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00480',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '180.00',lastbuyprice_withDiscount = '180',meanbuyprice = '180.00',meanbuyprice_withDiscount = '180' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '0' , buyhalf_precentage = '0' , buypart_precentage = '0',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '480';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:48:16";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:18:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:18:16', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:48:36";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:18:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:18:36', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:49:33";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:19:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:19:34', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:49:47";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:19:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:19:47', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:50:06";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:20:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:20:06', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:50:26";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:20:26", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:20:26', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:50:41";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:20:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:20:41', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:50:46";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:20:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:20:46', '1', 'edit', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:51:09";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:21:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:21:10', '1', 'update', '197.56.104.132', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 85;
UPDATE productunit SET unitid = '1', productid = '85', productnumber = '1.00', productunitdate = '2021-11-18', userid = '1', conditions = '0',proUnitParcode='0008501',proUnitSellAllPrice='210',proUnitSellHalfPrice='220',proUnitSellUnitPrice ='240',proUnitBuyPrice='205' WHERE productunitid = '85';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (85, 1,'2021-11-18 13:21:11',1)
                ON DUPLICATE KEY UPDATE productid = 85, edited = 1, sysdate = '2021-11-18 13:21:11', userid = 1;
UPDATE product SET productName = '516', productDescription = '', productCatId = '1', productBuyPrice = '205', productSellAllPrice = '180', productSellUnitPrice = '210', productSellHalfPrice = '190', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00085',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '205.00',lastbuyprice_withDiscount = '205',meanbuyprice = '205.00',meanbuyprice_withDiscount = '205' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '-12.2' , buyhalf_precentage = '-7.32' , buypart_precentage = '2.44',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '85';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:51:13";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:21:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:21:13', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:53:05";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:23:05", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:23:05', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:53:08";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:23:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:23:08', '1', 'edit', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:53:41";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:23:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:23:41', '1', 'update', '197.56.104.132', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 300;
UPDATE productunit SET unitid = '1', productid = '300', productnumber = '1.00', productunitdate = '2021-11-18', userid = '1', conditions = '0',proUnitParcode='0030001',proUnitSellAllPrice='210',proUnitSellHalfPrice='220',proUnitSellUnitPrice ='240',proUnitBuyPrice='205' WHERE productunitid = '300';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (300, 1,'2021-11-18 13:23:42',1)
                ON DUPLICATE KEY UPDATE productid = 300, edited = 1, sysdate = '2021-11-18 13:23:42', userid = 1;
UPDATE product SET productName = '708كريشه', productDescription = '', productCatId = '1', productBuyPrice = '205', productSellAllPrice = '180', productSellUnitPrice = '210', productSellHalfPrice = '190', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00300',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '205.00',lastbuyprice_withDiscount = '205',meanbuyprice = '205.00',meanbuyprice_withDiscount = '205' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '-12.2' , buyhalf_precentage = '-7.32' , buypart_precentage = '2.44',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '300';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:53:44";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:23:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:23:44', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:57:37";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:27:37", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:27:37', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:57:40";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:27:40", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:27:40', '1', 'edit', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:58:07";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:28:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:28:07', '1', 'update', '197.56.104.132', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 31;
UPDATE productunit SET unitid = '1', productid = '31', productnumber = '1.00', productunitdate = '2021-11-18', userid = '1', conditions = '0',proUnitParcode='0003101',proUnitSellAllPrice='200',proUnitSellHalfPrice='200',proUnitSellUnitPrice ='250',proUnitBuyPrice='180' WHERE productunitid = '31';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (31, 1,'2021-11-18 13:28:07',1)
                ON DUPLICATE KEY UPDATE productid = 31, edited = 1, sysdate = '2021-11-18 13:28:07', userid = 1;
UPDATE product SET productName = '104', productDescription = '', productCatId = '1', productBuyPrice = '180', productSellAllPrice = '165', productSellUnitPrice = '195', productSellHalfPrice = '175', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00031',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '180.00',lastbuyprice_withDiscount = '180',meanbuyprice = '180.00',meanbuyprice_withDiscount = '180' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '-8.33' , buyhalf_precentage = '-2.78' , buypart_precentage = '8.33',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '31';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:58:09";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:28:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:28:09', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:58:46";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:28:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:28:47', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:58:51";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:28:51", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:28:51', '1', 'edit', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:59:38";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:29:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:29:39', '1', 'update', '197.56.104.132', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 109;
UPDATE productunit SET unitid = '1', productid = '109', productnumber = '1.00', productunitdate = '2021-11-18', userid = '1', conditions = '0',proUnitParcode='0010901',proUnitSellAllPrice='185',proUnitSellHalfPrice='195',proUnitSellUnitPrice ='215',proUnitBuyPrice='185' WHERE productunitid = '109';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (109, 1,'2021-11-18 13:29:39',1)
                ON DUPLICATE KEY UPDATE productid = 109, edited = 1, sysdate = '2021-11-18 13:29:39', userid = 1;
UPDATE product SET productName = '620', productDescription = '', productCatId = '1', productBuyPrice = '185', productSellAllPrice = '170', productSellUnitPrice = '200', productSellHalfPrice = '180', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00109',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '185.00',lastbuyprice_withDiscount = '185',meanbuyprice = '185.00',meanbuyprice_withDiscount = '185' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '-8.11' , buyhalf_precentage = '-2.7' , buypart_precentage = '8.11',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '109';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 09:59:41";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:29:42", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:29:42', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:11:57";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:41:57", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:41:57', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:12:01";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:42:01", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:42:02', '1', 'edit', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:12:29";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:42:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:42:29', '1', 'update', '197.56.104.132', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 86;
UPDATE productunit SET unitid = '1', productid = '86', productnumber = '1.00', productunitdate = '2021-11-18', userid = '1', conditions = '0',proUnitParcode='0008601',proUnitSellAllPrice='210',proUnitSellHalfPrice='225',proUnitSellUnitPrice ='240',proUnitBuyPrice='200' WHERE productunitid = '86';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (86, 1,'2021-11-18 13:42:30',1)
                ON DUPLICATE KEY UPDATE productid = 86, edited = 1, sysdate = '2021-11-18 13:42:30', userid = 1;
UPDATE product SET productName = '517', productDescription = '', productCatId = '1', productBuyPrice = '200', productSellAllPrice = '180', productSellUnitPrice = '210', productSellHalfPrice = '190', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00086',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '200.00',lastbuyprice_withDiscount = '200',meanbuyprice = '200.00',meanbuyprice_withDiscount = '200' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '-10' , buyhalf_precentage = '-5' , buypart_precentage = '5',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '86';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:12:33";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:42:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:42:33', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:13:40";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:43:40", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:43:40', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:13:48";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:43:48", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:43:48', '1', 'edit', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:14:05";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:44:05", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:44:05', '1', 'update', '197.56.104.132', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 119;
UPDATE productunit SET unitid = '1', productid = '119', productnumber = '1.00', productunitdate = '2021-11-18', userid = '1', conditions = '0',proUnitParcode='0011901',proUnitSellAllPrice='185',proUnitSellHalfPrice='200',proUnitSellUnitPrice ='215',proUnitBuyPrice='175' WHERE productunitid = '119';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (119, 1,'2021-11-18 13:44:06',1)
                ON DUPLICATE KEY UPDATE productid = 119, edited = 1, sysdate = '2021-11-18 13:44:06', userid = 1;
UPDATE product SET productName = '630', productDescription = '', productCatId = '1', productBuyPrice = '175', productSellAllPrice = '165', productSellUnitPrice = '195', productSellHalfPrice = '175', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00119',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '175.00',lastbuyprice_withDiscount = '175',meanbuyprice = '175.00',meanbuyprice_withDiscount = '175' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '-5.71' , buyhalf_precentage = '0' , buypart_precentage = '11.43',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '119';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:14:08";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:44:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:44:08', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:14:23";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:44:23", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:44:23', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:14:40";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:44:40", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:44:40', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:14:45";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:44:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:44:45', '1', 'edit', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:15:07";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:45:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:45:07', '1', 'update', '197.56.104.132', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 382;
UPDATE productunit SET unitid = '1', productid = '382', productnumber = '1.00', productunitdate = '2021-11-18', userid = '1', conditions = '0',proUnitParcode='0038201',proUnitSellAllPrice='200',proUnitSellHalfPrice='240',proUnitSellUnitPrice ='240',proUnitBuyPrice='190' WHERE productunitid = '382';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (382, 1,'2021-11-18 13:45:07',1)
                ON DUPLICATE KEY UPDATE productid = 382, edited = 1, sysdate = '2021-11-18 13:45:07', userid = 1;
UPDATE product SET productName = 'ديجيتال 633', productDescription = '', productCatId = '1', productBuyPrice = '190', productSellAllPrice = '190', productSellUnitPrice = '220', productSellHalfPrice = '200', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00382',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '190.00',lastbuyprice_withDiscount = '190',meanbuyprice = '190.00',meanbuyprice_withDiscount = '190' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '0' , buyhalf_precentage = '5.26' , buypart_precentage = '15.79',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '382';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:15:09";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 13:45:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 13:45:09', '1', 'show', '197.56.104.132', '', '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-11-18 10:31:03";
UPDATE user SET loginip = "156.160.204.193", lastactivetime = "2021-11-18 14:01:03", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-11-18 14:01:03', '7', '', '156.160.204.193', '', '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-11-18 10:31:04";
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-11-18 10:31:08";
UPDATE user SET loginip = "156.160.204.193", lastactivetime = "2021-11-18 14:01:08", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-11-18 14:01:08', '7', 'addsellBill', '156.160.204.193', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:31:08";
UPDATE user SET loginip = "156.160.204.193", lastactivetime = "2021-11-18 14:01:08", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-11-18 14:01:08', '7', 'addsellBill', '156.160.204.193', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:34:34";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:04:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:04:34', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:35:14";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:05:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:05:14', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:35:20";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:05:20", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:05:20', '1', 'edit', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:35:46";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:05:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:05:47', '1', 'update', '197.56.104.132', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 128;
UPDATE productunit SET unitid = '1', productid = '128', productnumber = '1.00', productunitdate = '2021-11-18', userid = '1', conditions = '0',proUnitParcode='0012801',proUnitSellAllPrice='260',proUnitSellHalfPrice='260',proUnitSellUnitPrice ='320',proUnitBuyPrice='235' WHERE productunitid = '128';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (128, 1,'2021-11-18 14:05:47',1)
                ON DUPLICATE KEY UPDATE productid = 128, edited = 1, sysdate = '2021-11-18 14:05:47', userid = 1;
UPDATE product SET productName = '813', productDescription = '', productCatId = '1', productBuyPrice = '235', productSellAllPrice = '250', productSellUnitPrice = '280', productSellHalfPrice = '260', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00128',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '235.00',lastbuyprice_withDiscount = '235',meanbuyprice = '235.00',meanbuyprice_withDiscount = '235' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '6.38' , buyhalf_precentage = '10.64' , buypart_precentage = '19.15',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '128';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:35:50";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:05:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:05:50', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:36:06";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:06:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:06:06', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:36:11";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:06:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:06:11', '1', 'edit', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:36:34";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:06:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:06:34', '1', 'update', '197.56.104.132', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 80;
UPDATE productunit SET unitid = '1', productid = '80', productnumber = '1.00', productunitdate = '2021-11-18', userid = '1', conditions = '0',proUnitParcode='0008001',proUnitSellAllPrice='210',proUnitSellHalfPrice='225',proUnitSellUnitPrice ='240',proUnitBuyPrice='200' WHERE productunitid = '80';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (80, 1,'2021-11-18 14:06:34',1)
                ON DUPLICATE KEY UPDATE productid = 80, edited = 1, sysdate = '2021-11-18 14:06:34', userid = 1;
UPDATE product SET productName = '506', productDescription = '', productCatId = '1', productBuyPrice = '200', productSellAllPrice = '180', productSellUnitPrice = '180', productSellHalfPrice = '180', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00080',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '200.00',lastbuyprice_withDiscount = '200',meanbuyprice = '200.00',meanbuyprice_withDiscount = '200' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '-10' , buyhalf_precentage = '0' , buypart_precentage = '0',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '80';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:36:36";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:06:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:06:36', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:36:48";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:06:48", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:06:48', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:36:51";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:06:51", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:06:51', '1', 'edit', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:37:13";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:07:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:07:13', '1', 'update', '197.56.104.132', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 80;
UPDATE productunit SET unitid = '1', productid = '80', productnumber = '1.00', productunitdate = '2021-11-18', userid = '1', conditions = '0',proUnitParcode='0008001',proUnitSellAllPrice='210',proUnitSellHalfPrice='225',proUnitSellUnitPrice ='240',proUnitBuyPrice='200' WHERE productunitid = '80';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (80, 1,'2021-11-18 14:07:13',1)
                ON DUPLICATE KEY UPDATE productid = 80, edited = 1, sysdate = '2021-11-18 14:07:13', userid = 1;
UPDATE product SET productName = '506', productDescription = '', productCatId = '1', productBuyPrice = '200', productSellAllPrice = '180', productSellUnitPrice = '200', productSellHalfPrice = '190', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00080',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '200.00',lastbuyprice_withDiscount = '200',meanbuyprice = '200.00',meanbuyprice_withDiscount = '200' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '-10' , buyhalf_precentage = '-5' , buypart_precentage = '0',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '80';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:37:16";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:07:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:07:17', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:37:45";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:07:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:07:45', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:38:06";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:08:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:08:06', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:38:35";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:08:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:08:35', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:38:40";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:08:40", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:08:40', '1', 'edit', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:39:00";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:09:00", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:09:01', '1', 'update', '197.56.104.132', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 391;
UPDATE productunit SET unitid = '1', productid = '391', productnumber = '1.00', productunitdate = '2021-11-18', userid = '1', conditions = '0',proUnitParcode='0039101',proUnitSellAllPrice='200',proUnitSellHalfPrice='210',proUnitSellUnitPrice ='240',proUnitBuyPrice='190' WHERE productunitid = '391';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (391, 1,'2021-11-18 14:09:01',1)
                ON DUPLICATE KEY UPDATE productid = 391, edited = 1, sysdate = '2021-11-18 14:09:01', userid = 1;
UPDATE product SET productName = 'ديجيتال807', productDescription = '', productCatId = '1', productBuyPrice = '190', productSellAllPrice = '210', productSellUnitPrice = '240', productSellHalfPrice = '220', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00391',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '190.00',lastbuyprice_withDiscount = '190',meanbuyprice = '190.00',meanbuyprice_withDiscount = '190' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '10.53' , buyhalf_precentage = '15.79' , buypart_precentage = '26.32',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '391';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 10:39:03";
UPDATE user SET loginip = "197.56.104.132", lastactivetime = "2021-11-18 14:09:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-11-18 14:09:03', '1', 'show', '197.56.104.132', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 11:15:18";
UPDATE user SET loginip = "41.34.113.71", lastactivetime = "2021-11-18 14:45:18", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-11-18 14:45:19', '6', 'addAndRetuen', '41.34.113.71', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06196260fe3d0f
-- ----------------------------------------------------------------------------------------------------

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-11-18 12:08:15', '06196260fe3d0f', '1', '0.00', '0', '0', '1', '330', '330', '330', '0', '4', '2021-11-18 14:45:19', '', '6', '0', 'نقدي', '4', '0', '3', '0', 'نقدي', '2' ,'0','','','','','-1','0','0','0','0','0','330','0','','0','0','330','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','اضافة فاتورة مبيعات','18', '0', '2021-11-18 14:45:19', '6', 'sellbillController.php', 'اضافة فاتورة مبيعات', '330', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 482;
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 ('100','00218', '18', '1', '218', '1', '110.00', '110', '0', '', '0', '2021-11-18 14:45:20', '218', '0.00', '0', '4','0','','','0','0','0','0','0','0','0','0','','482-1,');
UPDATE sellbilldetail SET  lastbuyprice = 100.00 , meanbuyprice = 100.00, lastbuyprice_withDiscount = 100.00, meanbuyprice_withDiscount = 100.00
                where sellbilldetailid = 38;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (218, '2021-11-18', 110, 100, 100
                    , 100, 100, 100, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+110, sellCostBuyPrice =sellCostBuyPrice+100
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+100, sellCostMeanBuyPrice = sellCostMeanBuyPrice+100
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+100, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+100
                            , 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-11-18', 110, 100, 100
                    , 100, 100, 100, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+110, sellCostBuyPrice =sellCostBuyPrice+100
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+100, sellCostMeanBuyPrice = sellCostMeanBuyPrice+100
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+100, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+100
                            , 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 = '33', userid = '6', storedetaildate = '2021-11-18 14:45:20' WHERE storedetailid = '793';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('218', '4', '1', '1', '18', 'اضافة فاتورة مبيعات', 'sellbillController.php', '34.00', '33', '6', '2021-11-18 14:45:20','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 258;
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 ('210','00127', '18', '1', '127', '1', '220.00', '220', '0', '', '0', '2021-11-18 14:45:21', '127', '0.00', '0', '4','0','','','0','0','0','0','0','0','0','0','','258-1,');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 1148.55, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 1148.55
                where sellbilldetailid = 39;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (127, '2021-11-18', 220, 210, 210
                    , 1148.55, 210, 1148.55, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+220, sellCostBuyPrice =sellCostBuyPrice+210
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+210, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1148.55
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+210, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1148.55
                            , 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-11-18', 220, 210, 210
                    , 1148.55, 210, 1148.55, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+220, sellCostBuyPrice =sellCostBuyPrice+210
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+210, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1148.55
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+210, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1148.55
                            , 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 = '16', userid = '6', storedetaildate = '2021-11-18 14:45:21' WHERE storedetailid = '681';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('127', '4', '1', '1', '18', 'اضافة فاتورة مبيعات', 'sellbillController.php', '17.00', '16', '6', '2021-11-18 14:45:21','0','0');
UPDATE save SET  savecurrentvalue = '3040',  userid = '6' WHERE saveid = '4';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2710.00','330', '0', '4', 'اضافة فاتورة مبيعات', '18', '3040', '2021-11-18 14:45:21', '6',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-11-18', 330, 310, 310
                    , 1248.55, 310, 1248.55, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+330, sellCostBuyPrice =sellCostBuyPrice+310
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+310, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1248.55
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+310, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1248.55
                            , 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-11-18', 330, 310, 310
                    , 1248.55, 310, 1248.55, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+330, sellCostBuyPrice =sellCostBuyPrice+310
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+310, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1248.55
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+310, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1248.55
                            , 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, 330, 310, 310
                    , 1248.55, 310, 1248.55, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+330, netSellCostBuyPrice = netSellCostBuyPrice+310
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+310
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+1248.55
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+310
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+1248.55
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06196260fe3d0f and sellbillId = 18 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 11:15:22";
UPDATE user SET loginip = "41.34.113.71", lastactivetime = "2021-11-18 14:45:22", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-11-18 14:45:22', '6', 'addsellBill', '41.34.113.71', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 11:17:57";
UPDATE user SET loginip = "41.34.113.71", lastactivetime = "2021-11-18 14:47:57", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-11-18 14:47:57', '6', '', '41.34.113.71', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 11:59:40";
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 11:59:41";
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-11-18 12:01:47";
UPDATE user SET loginip = "154.180.88.192", lastactivetime = "2021-11-18 15:31:47", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-11-18 15:31:47', '5', '', '154.180.88.192', '', '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-11-18 12:01:47";
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-11-18 12:02:21";
UPDATE user SET loginip = "154.180.88.192", lastactivetime = "2021-11-18 15:32:21", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-11-18 15:32:21', '5', 'addsellBill', '154.180.88.192', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 12:16:14";
UPDATE user SET loginip = "154.180.88.192", lastactivetime = "2021-11-18 15:46:14", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-11-18 15:46:14', '5', 'addsellBill', '154.180.88.192', '', '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-11-18 12:58:24";
UPDATE user SET loginip = "156.160.204.193", lastactivetime = "2021-11-18 16:28:24", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-11-18 16:28:24', '7', '', '156.160.204.193', '', '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-11-18 12:58:25";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
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-11-18 13:38:39";
UPDATE user SET loginip = "154.180.88.192", lastactivetime = "2021-11-18 17:08:39", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-11-18 17:08:39', '5', '', '154.180.88.192', '', '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-11-18 13:38:40";
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-11-18 13:38:45";
UPDATE user SET loginip = "154.180.88.192", lastactivetime = "2021-11-18 17:08:45", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-11-18 17:08:46', '5', '', '154.180.88.192', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 13:38:51";
UPDATE user SET loginip = "154.180.88.192", lastactivetime = "2021-11-18 17:08:51", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-11-18 17:08:51', '5', 'addsellBill', '154.180.88.192', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 13:55:06";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 17:25:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 17:25:07', '1', '', '197.56.63.164', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:22:35";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 17:52:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 17:52:35', '1', 'add', '197.56.63.164', '', '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(30,1,6,562,28,'2021-11-18',1,0, '' ,0,0,0,0,0,'2021-11-18 17:52:36',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '194', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1481';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 562, 0, 0
                    , 225.00, -28, 0, 0, 1, '2021-11-18 17:52:36')
                ON DUPLICATE KEY UPDATE buyprice = 225.00,
                        buyQuantity =buyQuantity+-28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:52:36' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "28*2021-11-18*225.00," WHERE transferproductid = 927;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '1', '28', '1', '927', 'تحويل منتجات من المخزن', 'storemovementController.php', '222.00', '194', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('562', '6', '28', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 6, 562, 0, 0
                    , 225.00, 28, 0, 0, 1, '2021-11-18 17:52:36')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:52:36' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '6', '28', '0', '927', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '28', '1', '2021-11-18','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', '565', '24', '2021-11-18', '1', '0','30',null,null,'2021-11-18 17:52:36',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '184', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1484';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 565, 0, 0
                    , 150.00, -24, 0, 0, 1, '2021-11-18 17:52:36')
                ON DUPLICATE KEY UPDATE buyprice = 150.00,
                        buyQuantity =buyQuantity+-24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:52:36' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "24*2021-11-18*150.00," WHERE transferproductid = 928;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '1', '24', '1', '928', 'تحويل منتجات من المخزن', 'storemovementController.php', '208.00', '184', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('565', '6', '24', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 6, 565, 0, 0
                    , 150.00, 24, 0, 0, 1, '2021-11-18 17:52:36')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:52:36' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '6', '24', '0', '928', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '24', '1', '2021-11-18','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', '556', '16', '2021-11-18', '1', '0','30',null,null,'2021-11-18 17:52:36',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '37', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1469';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 556, 0, 0
                    , 195.00, -16, 0, 0, 1, '2021-11-18 17:52:36')
                ON DUPLICATE KEY UPDATE buyprice = 195.00,
                        buyQuantity =buyQuantity+-16, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:52:36' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "16*2021-11-18*195.00," WHERE transferproductid = 929;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('556', '1', '16', '1', '929', 'تحويل منتجات من المخزن', 'storemovementController.php', '53.00', '37', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('556', '6', '16', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 6, 556, 0, 0
                    , 195.00, 16, 0, 0, 1, '2021-11-18 17:52:36')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+16, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:52:36' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('556', '6', '16', '0', '929', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '16', '1', '2021-11-18','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', '555', '20', '2021-11-18', '1', '0','30',null,null,'2021-11-18 17:52:36',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '72', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1468';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 555, 0, 0
                    , 195.00, -20, 0, 0, 1, '2021-11-18 17:52:36')
                ON DUPLICATE KEY UPDATE buyprice = 195.00,
                        buyQuantity =buyQuantity+-20, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:52:36' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "20*2021-11-18*195.00," WHERE transferproductid = 930;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '1', '20', '1', '930', 'تحويل منتجات من المخزن', 'storemovementController.php', '92.00', '72', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('555', '6', '20', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 6, 555, 0, 0
                    , 195.00, 20, 0, 0, 1, '2021-11-18 17:52:36')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+20, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:52:36' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '6', '20', '0', '930', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '20', '1', '2021-11-18','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', '561', '19', '2021-11-18', '1', '0','30',null,null,'2021-11-18 17:52:36',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-10', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1480';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 561, 0, 0
                    , 210.00, -19, 0, 0, 1, '2021-11-18 17:52:36')
                ON DUPLICATE KEY UPDATE buyprice = 210.00,
                        buyQuantity =buyQuantity+-19, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:52:36' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "19*2021-11-18*210.00," WHERE transferproductid = 931;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '1', '19', '1', '931', 'تحويل منتجات من المخزن', 'storemovementController.php', '9.00', '-10', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('561', '6', '19', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 6, 561, 0, 0
                    , 210.00, 19, 0, 0, 1, '2021-11-18 17:52:36')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+19, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:52:36' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '6', '19', '0', '931', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '19', '1', '2021-11-18','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:22:37";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 17:52:37", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 17:52:37', '1', 'editshow', '197.56.63.164', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:23:23";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 17:53:23", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 17:53:23', '1', '', '197.56.63.164', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:26:42";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 17:56:42", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 17:56:42', '1', 'add', '197.56.63.164', '', '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(31,1,5,562,40,'2021-11-18',1,0, '' ,0,0,0,0,0,'2021-11-18 17:56:42',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '154', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1481';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 562, 0, 0
                    , 225.00, -40, 0, 0, 1, '2021-11-18 17:56:42')
                ON DUPLICATE KEY UPDATE buyprice = 225.00,
                        buyQuantity =buyQuantity+-40, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:56:42' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "40*2021-11-18*225.00," WHERE transferproductid = 932;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '1', '40', '1', '932', 'تحويل منتجات من المخزن', 'storemovementController.php', '194.00', '154', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('562', '5', '40', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 5, 562, 0, 0
                    , 225.00, 40, 0, 0, 1, '2021-11-18 17:56:42')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+40, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:56:42' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '5', '40', '0', '932', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '40', '1', '2021-11-18','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', '565', '36', '2021-11-18', '1', '0','31',null,null,'2021-11-18 17:56:42',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '148', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1484';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 565, 0, 0
                    , 150.00, -36, 0, 0, 1, '2021-11-18 17:56:42')
                ON DUPLICATE KEY UPDATE buyprice = 150.00,
                        buyQuantity =buyQuantity+-36, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:56:42' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "36*2021-11-18*150.00," WHERE transferproductid = 933;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '1', '36', '1', '933', 'تحويل منتجات من المخزن', 'storemovementController.php', '184.00', '148', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('565', '5', '36', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 5, 565, 0, 0
                    , 150.00, 36, 0, 0, 1, '2021-11-18 17:56:42')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+36, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:56:42' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '5', '36', '0', '933', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '36', '1', '2021-11-18','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', '561', '78', '2021-11-18', '1', '0','31',null,null,'2021-11-18 17:56:42',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-88', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1480';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 561, 0, 0
                    , 210.00, -78, 0, 0, 1, '2021-11-18 17:56:42')
                ON DUPLICATE KEY UPDATE buyprice = 210.00,
                        buyQuantity =buyQuantity+-78, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:56:42' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "78*2021-11-18*210.00," WHERE transferproductid = 934;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '1', '78', '1', '934', 'تحويل منتجات من المخزن', 'storemovementController.php', '-10.00', '-88', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('561', '5', '78', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 5, 561, 0, 0
                    , 210.00, 78, 0, 0, 1, '2021-11-18 17:56:42')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+78, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:56:42' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '5', '78', '0', '934', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '78', '1', '2021-11-18','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', '555', '28', '2021-11-18', '1', '0','31',null,null,'2021-11-18 17:56:42',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '44', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1468';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 555, 0, 0
                    , 195.00, -28, 0, 0, 1, '2021-11-18 17:56:42')
                ON DUPLICATE KEY UPDATE buyprice = 195.00,
                        buyQuantity =buyQuantity+-28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:56:42' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "28*2021-11-18*195.00," WHERE transferproductid = 935;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '1', '28', '1', '935', 'تحويل منتجات من المخزن', 'storemovementController.php', '72.00', '44', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('555', '5', '28', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 5, 555, 0, 0
                    , 195.00, 28, 0, 0, 1, '2021-11-18 17:56:42')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:56:42' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '5', '28', '0', '935', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '28', '1', '2021-11-18','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', '556', '20', '2021-11-18', '1', '0','31',null,null,'2021-11-18 17:56:42',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '17', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1469';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 556, 0, 0
                    , 195.00, -20, 0, 0, 1, '2021-11-18 17:56:42')
                ON DUPLICATE KEY UPDATE buyprice = 195.00,
                        buyQuantity =buyQuantity+-20, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:56:42' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "20*2021-11-18*195.00," WHERE transferproductid = 936;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('556', '1', '20', '1', '936', 'تحويل منتجات من المخزن', 'storemovementController.php', '37.00', '17', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('556', '5', '20', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 5, 556, 0, 0
                    , 195.00, 20, 0, 0, 1, '2021-11-18 17:56:42')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+20, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:56:42' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('556', '5', '20', '0', '936', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '20', '1', '2021-11-18','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', '125', '24', '2021-11-18', '1', '0','31',null,null,'2021-11-18 17:56:42',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-24', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '125';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 125, 0, 0
                    , 185.00, -24, 0, 0, 1, '2021-11-18 17:56:42')
                ON DUPLICATE KEY UPDATE buyprice = 185.00,
                        buyQuantity =buyQuantity+-24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:56:42' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "24*2021-11-18*185.00," WHERE transferproductid = 937;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('125', '1', '24', '1', '937', 'تحويل منتجات من المخزن', 'storemovementController.php', '0.00', '-24', '1', '2021-11-18','0','0');
UPDATE storedetail SET  productquantity = '108', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '914';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 5, 125, 0, 0
                    , 185.00, 24, 0, 0, 1, '2021-11-18 17:56:42')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:56:42' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('125', '5', '24', '0', '937', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '84.00', '108', '1', '2021-11-18','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', '128', '27', '2021-11-18', '1', '0','31',null,null,'2021-11-18 17:56:42',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-52', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '128';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 128, 0, 0
                    , 235.00, -27, 0, 0, 1, '2021-11-18 17:56:42')
                ON DUPLICATE KEY UPDATE buyprice = 235.00,
                        buyQuantity =buyQuantity+-27, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:56:42' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "27*2021-11-18*235.00," WHERE transferproductid = 938;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('128', '1', '27', '1', '938', 'تحويل منتجات من المخزن', 'storemovementController.php', '-25.00', '-52', '1', '2021-11-18','0','0');
UPDATE storedetail SET  productquantity = '61', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '917';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 5, 128, 0, 0
                    , 235.00, 27, 0, 0, 1, '2021-11-18 17:56:42')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+27, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:56:42' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('128', '5', '27', '0', '938', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '34.00', '61', '1', '2021-11-18','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', '462', '24', '2021-11-18', '1', '0','31',null,null,'2021-11-18 17:56:42',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-24', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '462';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 462, 0, 0
                    , 190.00, -24, 0, 0, 1, '2021-11-18 17:56:42')
                ON DUPLICATE KEY UPDATE buyprice = 190.00,
                        buyQuantity =buyQuantity+-24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:56:42' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "24*2021-11-18*190.00," WHERE transferproductid = 939;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('462', '1', '24', '1', '939', 'تحويل منتجات من المخزن', 'storemovementController.php', '0.00', '-24', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('462', '5', '24', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 5, 462, 0, 0
                    , 190.00, 24, 0, 0, 1, '2021-11-18 17:56:42')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 17:56:42' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('462', '5', '24', '0', '939', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '24', '1', '2021-11-18','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:26:43";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 17:56:43", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 17:56:43', '1', 'editshow', '197.56.63.164', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:27:11";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 17:57:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 17:57:11', '1', '', '197.56.63.164', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:30:35";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 18:00:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 18:00:35', '1', 'add', '197.56.63.164', '', '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(32,1,3,562,40,'2021-11-18',1,0, '' ,0,0,0,0,0,'2021-11-18 18:00:35',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '114', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1481';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 562, 0, 0
                    , 225.00, -40, 0, 0, 1, '2021-11-18 18:00:35')
                ON DUPLICATE KEY UPDATE buyprice = 225.00,
                        buyQuantity =buyQuantity+-40, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "40*2021-11-18*225.00," WHERE transferproductid = 940;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '1', '40', '1', '940', 'تحويل منتجات من المخزن', 'storemovementController.php', '154.00', '114', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('562', '3', '40', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 3, 562, 0, 0
                    , 225.00, 40, 0, 0, 1, '2021-11-18 18:00:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+40, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '3', '40', '0', '940', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '40', '1', '2021-11-18','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', '565', '32', '2021-11-18', '1', '0','32',null,null,'2021-11-18 18:00:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '116', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1484';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 565, 0, 0
                    , 150.00, -32, 0, 0, 1, '2021-11-18 18:00:35')
                ON DUPLICATE KEY UPDATE buyprice = 150.00,
                        buyQuantity =buyQuantity+-32, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "32*2021-11-18*150.00," WHERE transferproductid = 941;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '1', '32', '1', '941', 'تحويل منتجات من المخزن', 'storemovementController.php', '148.00', '116', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('565', '3', '32', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 3, 565, 0, 0
                    , 150.00, 32, 0, 0, 1, '2021-11-18 18:00:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+32, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '3', '32', '0', '941', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '32', '1', '2021-11-18','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', '560', '23', '2021-11-18', '1', '0','32',null,null,'2021-11-18 18:00:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-16', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1479';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 560, 0, 0
                    , 220.00, -23, 0, 0, 1, '2021-11-18 18:00:35')
                ON DUPLICATE KEY UPDATE buyprice = 220.00,
                        buyQuantity =buyQuantity+-23, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "23*2021-11-18*220.00," WHERE transferproductid = 942;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('560', '1', '23', '1', '942', 'تحويل منتجات من المخزن', 'storemovementController.php', '7.00', '-16', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('560', '3', '23', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 3, 560, 0, 0
                    , 220.00, 23, 0, 0, 1, '2021-11-18 18:00:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+23, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('560', '3', '23', '0', '942', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '23', '1', '2021-11-18','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', '555', '24', '2021-11-18', '1', '0','32',null,null,'2021-11-18 18:00:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '20', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1468';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 555, 0, 0
                    , 195.00, -24, 0, 0, 1, '2021-11-18 18:00:35')
                ON DUPLICATE KEY UPDATE buyprice = 195.00,
                        buyQuantity =buyQuantity+-24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "24*2021-11-18*195.00," WHERE transferproductid = 943;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '1', '24', '1', '943', 'تحويل منتجات من المخزن', 'storemovementController.php', '44.00', '20', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('555', '3', '24', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 3, 555, 0, 0
                    , 195.00, 24, 0, 0, 1, '2021-11-18 18:00:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '3', '24', '0', '943', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '24', '1', '2021-11-18','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', '556', '17', '2021-11-18', '1', '0','32',null,null,'2021-11-18 18:00:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1469';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 556, 0, 0
                    , 195.00, -17, 0, 0, 1, '2021-11-18 18:00:35')
                ON DUPLICATE KEY UPDATE buyprice = 195.00,
                        buyQuantity =buyQuantity+-17, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "17*2021-11-18*195.00," WHERE transferproductid = 944;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('556', '1', '17', '1', '944', 'تحويل منتجات من المخزن', 'storemovementController.php', '17.00', '0', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('556', '3', '17', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 3, 556, 0, 0
                    , 195.00, 17, 0, 0, 1, '2021-11-18 18:00:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+17, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('556', '3', '17', '0', '944', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '17', '1', '2021-11-18','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', '561', '28', '2021-11-18', '1', '0','32',null,null,'2021-11-18 18:00:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-116', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1480';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 561, 0, 0
                    , 210.00, -28, 0, 0, 1, '2021-11-18 18:00:35')
                ON DUPLICATE KEY UPDATE buyprice = 210.00,
                        buyQuantity =buyQuantity+-28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "28*2021-11-18*210.00," WHERE transferproductid = 945;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '1', '28', '1', '945', 'تحويل منتجات من المخزن', 'storemovementController.php', '-88.00', '-116', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('561', '3', '28', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 3, 561, 0, 0
                    , 210.00, 28, 0, 0, 1, '2021-11-18 18:00:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '3', '28', '0', '945', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '28', '1', '2021-11-18','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', '563', '38', '2021-11-18', '1', '0','32',null,null,'2021-11-18 18:00:36',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-24', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1482';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 563, 0, 0
                    , 210.00, -38, 0, 0, 1, '2021-11-18 18:00:36')
                ON DUPLICATE KEY UPDATE buyprice = 210.00,
                        buyQuantity =buyQuantity+-38, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:36' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "38*2021-11-18*210.00," WHERE transferproductid = 946;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '1', '38', '1', '946', 'تحويل منتجات من المخزن', 'storemovementController.php', '14.00', '-24', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('563', '3', '38', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 3, 563, 0, 0
                    , 210.00, 38, 0, 0, 1, '2021-11-18 18:00:36')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+38, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:36' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '3', '38', '0', '946', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '38', '1', '2021-11-18','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', '463', '47', '2021-11-18', '1', '0','32',null,null,'2021-11-18 18:00:36',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-47', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '463';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 463, 0, 0
                    , 190.00, -47, 0, 0, 1, '2021-11-18 18:00:36')
                ON DUPLICATE KEY UPDATE buyprice = 190.00,
                        buyQuantity =buyQuantity+-47, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:36' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "47*2021-11-18*190.00," WHERE transferproductid = 947;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('463', '1', '47', '1', '947', 'تحويل منتجات من المخزن', 'storemovementController.php', '0.00', '-47', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('463', '3', '47', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 3, 463, 0, 0
                    , 190.00, 47, 0, 0, 1, '2021-11-18 18:00:36')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+47, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:36' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('463', '3', '47', '0', '947', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '47', '1', '2021-11-18','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', '466', '28', '2021-11-18', '1', '0','32',null,null,'2021-11-18 18:00:36',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '22', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '466';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 466, 0, 0
                    , 240.00, -28, 0, 0, 1, '2021-11-18 18:00:36')
                ON DUPLICATE KEY UPDATE buyprice = 240.00,
                        buyQuantity =buyQuantity+-28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:36' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "28*2021-11-18*240.00," WHERE transferproductid = 948;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('466', '1', '28', '1', '948', 'تحويل منتجات من المخزن', 'storemovementController.php', '50.00', '22', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('466', '3', '28', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 3, 466, 0, 0
                    , 240.00, 28, 0, 0, 1, '2021-11-18 18:00:36')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:36' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('466', '3', '28', '0', '948', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '28', '1', '2021-11-18','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', '518', '13', '2021-11-18', '1', '0','32',null,null,'2021-11-18 18:00:36',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '518';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 518, 0, 0
                    , 210.00, -13, 0, 0, 1, '2021-11-18 18:00:36')
                ON DUPLICATE KEY UPDATE buyprice = 210.00,
                        buyQuantity =buyQuantity+-13, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:36' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "13*2021-11-18*210.00," WHERE transferproductid = 949;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('518', '1', '13', '1', '949', 'تحويل منتجات من المخزن', 'storemovementController.php', '13.00', '0', '1', '2021-11-18','0','0');
UPDATE storedetail SET  productquantity = '45', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1452';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 3, 518, 0, 0
                    , 210.00, 13, 0, 0, 1, '2021-11-18 18:00:36')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+13, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:00:36' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('518', '3', '13', '0', '949', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '32.00', '45', '1', '2021-11-18','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:30:36";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 18:00:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 18:00:36', '1', 'editshow', '197.56.63.164', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:31:03";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 18:01:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 18:01:03', '1', '', '197.56.63.164', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:32:39";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 18:02:40", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 18:02:40', '1', 'add', '197.56.63.164', '', '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(33,1,4,562,36,'2021-11-18',1,0, '' ,0,0,0,0,0,'2021-11-18 18:02:40',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '78', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1481';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 562, 0, 0
                    , 225.00, -36, 0, 0, 1, '2021-11-18 18:02:40')
                ON DUPLICATE KEY UPDATE buyprice = 225.00,
                        buyQuantity =buyQuantity+-36, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:02:40' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "36*2021-11-18*225.00," WHERE transferproductid = 950;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '1', '36', '1', '950', 'تحويل منتجات من المخزن', 'storemovementController.php', '114.00', '78', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('562', '4', '36', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 4, 562, 0, 0
                    , 225.00, 36, 0, 0, 1, '2021-11-18 18:02:40')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+36, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:02:40' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '4', '36', '0', '950', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '36', '1', '2021-11-18','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', '565', '36', '2021-11-18', '1', '0','33',null,null,'2021-11-18 18:02:40',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '80', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1484';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 565, 0, 0
                    , 150.00, -36, 0, 0, 1, '2021-11-18 18:02:41')
                ON DUPLICATE KEY UPDATE buyprice = 150.00,
                        buyQuantity =buyQuantity+-36, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:02:41' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "36*2021-11-18*150.00," WHERE transferproductid = 951;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '1', '36', '1', '951', 'تحويل منتجات من المخزن', 'storemovementController.php', '116.00', '80', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('565', '4', '36', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 4, 565, 0, 0
                    , 150.00, 36, 0, 0, 1, '2021-11-18 18:02:41')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+36, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:02:41' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '4', '36', '0', '951', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '36', '1', '2021-11-18','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', '561', '28', '2021-11-18', '1', '0','33',null,null,'2021-11-18 18:02:41',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-144', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1480';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 561, 0, 0
                    , 210.00, -28, 0, 0, 1, '2021-11-18 18:02:41')
                ON DUPLICATE KEY UPDATE buyprice = 210.00,
                        buyQuantity =buyQuantity+-28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:02:41' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "28*2021-11-18*210.00," WHERE transferproductid = 952;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '1', '28', '1', '952', 'تحويل منتجات من المخزن', 'storemovementController.php', '-116.00', '-144', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('561', '4', '28', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 4, 561, 0, 0
                    , 210.00, 28, 0, 0, 1, '2021-11-18 18:02:41')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:02:41' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '4', '28', '0', '952', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '28', '1', '2021-11-18','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', '463', '26', '2021-11-18', '1', '0','33',null,null,'2021-11-18 18:02:41',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-73', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '463';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 463, 0, 0
                    , 190.00, -26, 0, 0, 1, '2021-11-18 18:02:41')
                ON DUPLICATE KEY UPDATE buyprice = 190.00,
                        buyQuantity =buyQuantity+-26, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:02:41' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "26*2021-11-18*190.00," WHERE transferproductid = 953;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('463', '1', '26', '1', '953', 'تحويل منتجات من المخزن', 'storemovementController.php', '-47.00', '-73', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('463', '4', '26', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 4, 463, 0, 0
                    , 190.00, 26, 0, 0, 1, '2021-11-18 18:02:41')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+26, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:02:41' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('463', '4', '26', '0', '953', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '26', '1', '2021-11-18','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', '465', '22', '2021-11-18', '1', '0','33',null,null,'2021-11-18 18:02:41',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-46', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '465';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 465, 0, 0
                    , 210.00, -22, 0, 0, 1, '2021-11-18 18:02:41')
                ON DUPLICATE KEY UPDATE buyprice = 210.00,
                        buyQuantity =buyQuantity+-22, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:02:41' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "22*2021-11-18*210.00," WHERE transferproductid = 954;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('465', '1', '22', '1', '954', 'تحويل منتجات من المخزن', 'storemovementController.php', '-24.00', '-46', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('465', '4', '22', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 4, 465, 0, 0
                    , 210.00, 22, 0, 0, 1, '2021-11-18 18:02:41')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+22, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:02:41' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('465', '4', '22', '0', '954', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '22', '1', '2021-11-18','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:32:41";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 18:02:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 18:02:41', '1', 'editshow', '197.56.63.164', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:33:49";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 18:03:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 18:03:49', '1', '', '197.56.63.164', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:35:13";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 18:05:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 18:05:13', '1', 'add', '197.56.63.164', '', '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(34,1,7,562,40,'2021-11-18',1,0, '' ,0,0,0,0,0,'2021-11-18 18:05:13',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '38', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1481';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 562, 0, 0
                    , 225.00, -40, 0, 0, 1, '2021-11-18 18:05:13')
                ON DUPLICATE KEY UPDATE buyprice = 225.00,
                        buyQuantity =buyQuantity+-40, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:05:13' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "40*2021-11-18*225.00," WHERE transferproductid = 955;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '1', '40', '1', '955', 'تحويل منتجات من المخزن', 'storemovementController.php', '78.00', '38', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('562', '7', '40', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 7, 562, 0, 0
                    , 225.00, 40, 0, 0, 1, '2021-11-18 18:05:13')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+40, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:05:13' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '7', '40', '0', '955', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '40', '1', '2021-11-18','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', '36', '2021-11-18', '1', '0','34',null,null,'2021-11-18 18:05:13',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '44', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1484';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 565, 0, 0
                    , 150.00, -36, 0, 0, 1, '2021-11-18 18:05:13')
                ON DUPLICATE KEY UPDATE buyprice = 150.00,
                        buyQuantity =buyQuantity+-36, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:05:13' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "36*2021-11-18*150.00," WHERE transferproductid = 956;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '1', '36', '1', '956', 'تحويل منتجات من المخزن', 'storemovementController.php', '80.00', '44', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('565', '7', '36', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 7, 565, 0, 0
                    , 150.00, 36, 0, 0, 1, '2021-11-18 18:05:13')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+36, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:05:13' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '7', '36', '0', '956', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '36', '1', '2021-11-18','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', '561', '32', '2021-11-18', '1', '0','34',null,null,'2021-11-18 18:05:13',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-176', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1480';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 561, 0, 0
                    , 210.00, -32, 0, 0, 1, '2021-11-18 18:05:13')
                ON DUPLICATE KEY UPDATE buyprice = 210.00,
                        buyQuantity =buyQuantity+-32, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:05:13' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "32*2021-11-18*210.00," WHERE transferproductid = 957;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '1', '32', '1', '957', 'تحويل منتجات من المخزن', 'storemovementController.php', '-144.00', '-176', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('561', '7', '32', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 7, 561, 0, 0
                    , 210.00, 32, 0, 0, 1, '2021-11-18 18:05:13')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+32, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:05:13' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '7', '32', '0', '957', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '32', '1', '2021-11-18','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', '463', '24', '2021-11-18', '1', '0','34',null,null,'2021-11-18 18:05:13',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-97', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '463';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 463, 0, 0
                    , 190.00, -24, 0, 0, 1, '2021-11-18 18:05:13')
                ON DUPLICATE KEY UPDATE buyprice = 190.00,
                        buyQuantity =buyQuantity+-24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:05:13' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "24*2021-11-18*190.00," WHERE transferproductid = 958;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('463', '1', '24', '1', '958', 'تحويل منتجات من المخزن', 'storemovementController.php', '-73.00', '-97', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('463', '7', '24', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 7, 463, 0, 0
                    , 190.00, 24, 0, 0, 1, '2021-11-18 18:05:13')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:05:13' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('463', '7', '24', '0', '958', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '24', '1', '2021-11-18','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', '466', '28', '2021-11-18', '1', '0','34',null,null,'2021-11-18 18:05:13',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-6', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '466';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 466, 0, 0
                    , 240.00, -28, 0, 0, 1, '2021-11-18 18:05:13')
                ON DUPLICATE KEY UPDATE buyprice = 240.00,
                        buyQuantity =buyQuantity+-28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:05:13' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "28*2021-11-18*240.00," WHERE transferproductid = 959;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('466', '1', '28', '1', '959', 'تحويل منتجات من المخزن', 'storemovementController.php', '22.00', '-6', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('466', '7', '28', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 7, 466, 0, 0
                    , 240.00, 28, 0, 0, 1, '2021-11-18 18:05:13')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:05:13' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('466', '7', '28', '0', '959', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '28', '1', '2021-11-18','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:35:14";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 18:05:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 18:05:14', '1', 'editshow', '197.56.63.164', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:38:21";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 18:08:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 18:08:21', '1', '', '197.56.63.164', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:40:05";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 18:10:05", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 18:10:05', '1', 'add', '197.56.63.164', '', '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(35,1,8,562,37,'2021-11-18',1,0, '' ,0,0,0,0,0,'2021-11-18 18:10:05',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '1', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1481';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 562, 0, 0
                    , 225.00, -37, 0, 0, 1, '2021-11-18 18:10:05')
                ON DUPLICATE KEY UPDATE buyprice = 225.00,
                        buyQuantity =buyQuantity+-37, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:10:05' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "37*2021-11-18*225.00," WHERE transferproductid = 960;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '1', '37', '1', '960', 'تحويل منتجات من المخزن', 'storemovementController.php', '38.00', '1', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('562', '8', '37', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 8, 562, 0, 0
                    , 225.00, 37, 0, 0, 1, '2021-11-18 18:10:05')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+37, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:10:05' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '8', '37', '0', '960', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '37', '1', '2021-11-18','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', '565', '36', '2021-11-18', '1', '0','35',null,null,'2021-11-18 18:10:05',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '8', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1484';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 565, 0, 0
                    , 150.00, -36, 0, 0, 1, '2021-11-18 18:10:05')
                ON DUPLICATE KEY UPDATE buyprice = 150.00,
                        buyQuantity =buyQuantity+-36, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:10:05' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "36*2021-11-18*150.00," WHERE transferproductid = 961;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '1', '36', '1', '961', 'تحويل منتجات من المخزن', 'storemovementController.php', '44.00', '8', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('565', '8', '36', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 8, 565, 0, 0
                    , 150.00, 36, 0, 0, 1, '2021-11-18 18:10:05')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+36, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:10:05' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '8', '36', '0', '961', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '36', '1', '2021-11-18','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', '561', '24', '2021-11-18', '1', '0','35',null,null,'2021-11-18 18:10:05',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-200', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1480';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 561, 0, 0
                    , 210.00, -24, 0, 0, 1, '2021-11-18 18:10:05')
                ON DUPLICATE KEY UPDATE buyprice = 210.00,
                        buyQuantity =buyQuantity+-24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:10:05' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "24*2021-11-18*210.00," WHERE transferproductid = 962;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '1', '24', '1', '962', 'تحويل منتجات من المخزن', 'storemovementController.php', '-176.00', '-200', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('561', '8', '24', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 8, 561, 0, 0
                    , 210.00, 24, 0, 0, 1, '2021-11-18 18:10:05')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:10:05' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '8', '24', '0', '962', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '24', '1', '2021-11-18','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', '463', '18', '2021-11-18', '1', '0','35',null,null,'2021-11-18 18:10:05',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-115', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '463';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 463, 0, 0
                    , 190.00, -18, 0, 0, 1, '2021-11-18 18:10:05')
                ON DUPLICATE KEY UPDATE buyprice = 190.00,
                        buyQuantity =buyQuantity+-18, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:10:05' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "18*2021-11-18*190.00," WHERE transferproductid = 963;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('463', '1', '18', '1', '963', 'تحويل منتجات من المخزن', 'storemovementController.php', '-97.00', '-115', '1', '2021-11-18','0','0');
UPDATE storedetail SET  productquantity = '37', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1193';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 8, 463, 0, 0
                    , 190.00, 18, 0, 0, 1, '2021-11-18 18:10:05')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+18, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:10:05' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('463', '8', '18', '0', '963', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '19.00', '37', '1', '2021-11-18','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', '302', '28', '2021-11-18', '1', '0','35',null,null,'2021-11-18 18:10:05',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-28', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '302';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 302, 0, 0
                    , 200.00, -28, 0, 0, 1, '2021-11-18 18:10:05')
                ON DUPLICATE KEY UPDATE buyprice = 200.00,
                        buyQuantity =buyQuantity+-28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:10:05' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "28*2021-11-18*200.00," WHERE transferproductid = 964;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('302', '1', '28', '1', '964', 'تحويل منتجات من المخزن', 'storemovementController.php', '0.00', '-28', '1', '2021-11-18','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('302', '8', '28', '1', '2021-11-18');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 8, 302, 0, 0
                    , 200.00, 28, 0, 0, 1, '2021-11-18 18:10:05')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:10:05' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('302', '8', '28', '0', '964', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '28', '1', '2021-11-18','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', '555', '20', '2021-11-18', '1', '0','35',null,null,'2021-11-18 18:10:05',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1468';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 555, 0, 0
                    , 195.00, -20, 0, 0, 1, '2021-11-18 18:10:05')
                ON DUPLICATE KEY UPDATE buyprice = 195.00,
                        buyQuantity =buyQuantity+-20, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:10:05' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "20*2021-11-18*195.00," WHERE transferproductid = 965;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '1', '20', '1', '965', 'تحويل منتجات من المخزن', 'storemovementController.php', '20.00', '0', '1', '2021-11-18','0','0');
UPDATE storedetail SET  productquantity = '40', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '1478';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 8, 555, 0, 0
                    , 195.00, 20, 0, 0, 1, '2021-11-18 18:10:05')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+20, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:10:05' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '8', '20', '0', '965', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '20.00', '40', '1', '2021-11-18','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:40:06";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 18:10:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 18:10:06', '1', 'editshow', '197.56.63.164', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:50:49";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 18:20:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-11-18 18:20:49', '1', '', '197.56.63.164', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 14:51:01";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 18:21:01", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-11-18 18:21:01', '1', 'show', '197.56.63.164', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 15:09:15";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 18:39:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 18:39:15', '1', '', '197.56.63.164', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 15:10:27";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 18:40:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 18:40:27', '1', 'add', '197.56.63.164', '', '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(36,1,5,450,22,'2021-11-18',1,0, '' ,0,0,0,0,0,'2021-11-18 18:40:27',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '-22', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '450';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 450, 0, 0
                    , 280.00, -22, 0, 0, 1, '2021-11-18 18:40:28')
                ON DUPLICATE KEY UPDATE buyprice = 280.00,
                        buyQuantity =buyQuantity+-22, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:40:28' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "22*2021-11-18*280.00," WHERE transferproductid = 966;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('450', '1', '22', '1', '966', 'تحويل منتجات من المخزن', 'storemovementController.php', '0.00', '-22', '1', '2021-11-18','0','0');
UPDATE storedetail SET  productquantity = '119', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '910';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 5, 450, 0, 0
                    , 280.00, 22, 0, 0, 1, '2021-11-18 18:40:28')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+22, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:40:28' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('450', '5', '22', '0', '966', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '97.00', '119', '1', '2021-11-18','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', '518', '1', '2021-11-18', '1', '0','36',null,null,'2021-11-18 18:40:28',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-1', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '518';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 518, 0, 0
                    , 210.00, -1, 0, 0, 1, '2021-11-18 18:40:28')
                ON DUPLICATE KEY UPDATE buyprice = 210.00,
                        buyQuantity =buyQuantity+-1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:40:28' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "1*2021-11-18*210.00," WHERE transferproductid = 967;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('518', '1', '1', '1', '967', 'تحويل منتجات من المخزن', 'storemovementController.php', '0.00', '-1', '1', '2021-11-18','0','0');
UPDATE storedetail SET  productquantity = '57', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '909';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 5, 518, 0, 0
                    , 210.00, 1, 0, 0, 1, '2021-11-18 18:40:28')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:40:28' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('518', '5', '1', '0', '967', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '56.00', '57', '1', '2021-11-18','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', '513', '1', '2021-11-18', '1', '0','36',null,null,'2021-11-18 18:40:28',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-1', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '513';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 1, 513, 0, 0
                    , 210.00, -1, 0, 0, 1, '2021-11-18 18:40:28')
                ON DUPLICATE KEY UPDATE buyprice = 210.00,
                        buyQuantity =buyQuantity+-1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:40:28' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "1*2021-11-18*210.00," WHERE transferproductid = 968;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('513', '1', '1', '1', '968', 'تحويل منتجات من المخزن', 'storemovementController.php', '0.00', '-1', '1', '2021-11-18','0','0');
UPDATE storedetail SET  productquantity = '43', userid = '1', storedetaildate = '2021-11-18' WHERE storedetailid = '904';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-18', 5, 513, 0, 0
                    , 210.00, 1, 0, 0, 1, '2021-11-18 18:40:28')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-11-18 18:40:28' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('513', '5', '1', '0', '968', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '42.00', '43', '1', '2021-11-18','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-11-18 15:10:28";
UPDATE user SET loginip = "197.56.63.164", lastactivetime = "2021-11-18 18:40:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-11-18 18:40:29', '1', 'editshow', '197.56.63.164', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 3;
