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

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 06:50:53";
UPDATE user SET loginip = "41.238.95.36", lastactivetime = "2021-12-08 10:20:53", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 10:20:53', '4', 'addsellBill', '41.238.95.36', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 06:51:10";
UPDATE user SET loginip = "41.238.95.36", lastactivetime = "2021-12-08 10:21:10", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-08 10:21:10', '4', '', '41.238.95.36', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 06:51:12";
UPDATE user SET loginip = "41.238.95.36", lastactivetime = "2021-12-08 10:21:12", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 10:21:12', '4', 'addsellBill', '41.238.95.36', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 06:51:18";
UPDATE user SET loginip = "41.238.95.36", lastactivetime = "2021-12-08 10:21:18", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-08 10:21:18', '4', '', '41.238.95.36', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 06:51:26";
UPDATE user SET loginip = "41.238.95.36", lastactivetime = "2021-12-08 10:21:26", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storedetailController.php', '2021-12-08 10:21:26', '4', '', '41.238.95.36', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 06:51:34";
UPDATE user SET loginip = "41.238.95.36", lastactivetime = "2021-12-08 10:21:34", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 10:21:34', '4', 'addsellBill', '41.238.95.36', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 07:13:17";
UPDATE user SET loginip = "41.238.95.36", lastactivetime = "2021-12-08 10:43:17", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 10:43:17', '4', 'addsellBill', '41.238.95.36', '', 'DESKTOP');
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 07:22:03";
UPDATE user SET loginip = "41.36.9.120", lastactivetime = "2021-12-08 10:52:03", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-08 10:52:03', '6', '', '41.36.9.120', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 07:22:03";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 07:22:09";
UPDATE user SET loginip = "41.36.9.120", lastactivetime = "2021-12-08 10:52:09", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storedetailController.php', '2021-12-08 10:52:09', '6', '', '41.36.9.120', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 07:22:12";
UPDATE user SET loginip = "41.36.9.120", lastactivetime = "2021-12-08 10:52:12", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-08 10:52:12', '6', '', '41.36.9.120', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 07:22:18";
UPDATE user SET loginip = "41.36.9.120", lastactivetime = "2021-12-08 10:52:18", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 10:52:18', '6', 'addsellBill', '41.36.9.120', '', 'DESKTOP');
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 08:07:43";
UPDATE user SET loginip = "154.176.121.199", lastactivetime = "2021-12-08 11:37:43", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-08 11:37:43', '8', '', '154.176.121.199', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 08:07:43";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 08:07:51";
UPDATE user SET loginip = "154.176.121.199", lastactivetime = "2021-12-08 11:37:51", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 11:37:51', '8', 'addsellBill', '154.176.121.199', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 08:42:42";
UPDATE user SET loginip = "41.36.9.120", lastactivetime = "2021-12-08 12:12:42", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 12:12:42', '6', 'addsellBill', '41.36.9.120', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 08:43:01";
UPDATE user SET loginip = "41.36.9.120", lastactivetime = "2021-12-08 12:13:01", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 12:13:01', '6', 'addAndRetuen', '41.36.9.120', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b0851ac2e13
-- ----------------------------------------------------------------------------------------------------

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-12-08 12:12:42', '061b0851ac2e13', '1', '0.00', '0', '0', '1', '250', '250', '-250', '0', '4', '2021-12-08 12:13:01', '', '6', '0', 'نقدي','4', '0', '5', '0', 'نقدي', '1', '0', '', '','','','-1','0','0','0','','0','-250','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','اضافة فاتورة مردوات مبيعات','51', '0', '2021-12-08 12:13:01', '6', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '250', '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 ('235.00', '00129', '51', '1', '129', '1', '250.00', '250', '0', '', '0', '0', '129', '0.00', '0','4','0','','','0','0','0','0','0','0');
UPDATE returnsellbilldetail SET  lastbuyprice = 235.00 , meanbuyprice = 235.00, lastbuyprice_withDiscount = 235.00, meanbuyprice_withDiscount = 235.00
                where returnsellbilldetailid = 85;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (129, '2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 235, 235, 235
                    , 235, 235, 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+250, returnSellCostBuyPrice = returnSellCostBuyPrice+235, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+235
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+235, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+235
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+235
                            , 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-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 235, 235, 235
                    , 235, 235, 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+250, returnSellCostBuyPrice = returnSellCostBuyPrice+235, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+235
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+235, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+235
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+235
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '28', userid = '6', storedetaildate = '2021-12-08 12:13:01' WHERE storedetailid = '1559';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('129', '4', '1', '0', '51', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '27.00', '28', '6', '2021-12-08 12:13:01','0','0');
UPDATE save SET  savecurrentvalue = '490',  userid = '6' WHERE saveid = '4';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('740.00','250', '1', '4', 'اضافة فاتورة مردوات مبيعات', '51', '490', '2021-12-08 12:13:01', '6',  'returnsellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 235, 235, 235
                    , 235, 235, 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+250, returnSellCostBuyPrice = returnSellCostBuyPrice+235, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+235
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+235, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+235
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+235
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 235, 235, 235
                    , 235, 235, 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+250, returnSellCostBuyPrice = returnSellCostBuyPrice+235, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+235
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+235, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+235
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+235
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -250, -235, -235
                    , -235, -235, -235, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-250, netSellCostBuyPrice = netSellCostBuyPrice+-235
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-235
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-235
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-235
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-235
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b0851ac2e13 and sellbillId = 51 and returnsellbillId = 51
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 08:43:01";
UPDATE user SET loginip = "41.36.9.120", lastactivetime = "2021-12-08 12:13:01", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 12:13:01', '6', 'addsellBill', '41.36.9.120', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 08:43:07";
UPDATE user SET loginip = "41.36.9.120", lastactivetime = "2021-12-08 12:13:07", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-08 12:13:07', '6', '', '41.36.9.120', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 08:43:18";
UPDATE user SET loginip = "41.36.9.120", lastactivetime = "2021-12-08 12:13:18", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-08 12:13:18', '6', '', '41.36.9.120', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 08:43:21";
UPDATE user SET loginip = "41.36.9.120", lastactivetime = "2021-12-08 12:13:21", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 12:13:21', '6', 'addsellBill', '41.36.9.120', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 08:43:41";
UPDATE user SET loginip = "41.36.9.120", lastactivetime = "2021-12-08 12:13:41", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 12:13:41', '6', 'addsellBill', '41.36.9.120', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 08:51:20";
UPDATE user SET loginip = "41.36.106.84", lastactivetime = "2021-12-08 12:21:20", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 12:21:20', '4', 'addsellBill', '41.36.106.84', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 08:56:22";
UPDATE user SET loginip = "41.36.106.84", lastactivetime = "2021-12-08 12:26:22", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 12:26:22', '4', 'addsellBill', '41.36.106.84', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 08:56:48";
UPDATE user SET loginip = "41.36.106.84", lastactivetime = "2021-12-08 12:26:48", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 12:26:48', '4', 'addAndRetuen', '41.36.106.84', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b0884ec7ca0
-- ----------------------------------------------------------------------------------------------------

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-12-08 12:26:22', '061b0884ec7ca0', '1', '0.00', '0', '0', '1', '440', '440', '-440', '0', '7', '2021-12-08 12:26:48', '', '4', '0', 'نقدي','7', '0', '5', '0', 'نقدي', '2', '0', '', '','','','-1','0','0','0','','0','-440','0','0','0','0','0','0');
UPDATE client SET  clientdebt = '0', userid = '4' 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','اضافة فاتورة مردوات مبيعات','52', '0', '2021-12-08 12:26:48', '4', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '440', '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 ('210.00', '00563', '52', '1', '563', '1', '220.00', '220', '0', '', '0', '0', '563', '0.00', '0','7','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 = 86;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (563, '2021-12-08', 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 (7, '2021-12-08', 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 = '6', userid = '4', storedetaildate = '2021-12-08 12:26:48' WHERE storedetailid = '1553';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '7', '1', '0', '52', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '5.00', '6', '4', '2021-12-08 12:26:48','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', '00465', '52', '1', '465', '1', '220.00', '220', '0', '', '0', '0', '465', '0.00', '0','7','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 = 87;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (465, '2021-12-08', 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 (7, '2021-12-08', 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 = '16', userid = '4', storedetaildate = '2021-12-08 12:26:48' WHERE storedetailid = '1467';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('465', '7', '1', '0', '52', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '15.00', '16', '4', '2021-12-08 12:26:48','0','0');
UPDATE save SET  savecurrentvalue = '340',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('780.00','440', '1', '7', 'اضافة فاتورة مردوات مبيعات', '52', '340', '2021-12-08 12:26:48', '4',  'returnsellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 440, 420, 420, 420
                    , 420, 420, 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+440, returnSellCostBuyPrice = returnSellCostBuyPrice+420, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+420
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+420, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+420
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+420
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 440, 420, 420, 420
                    , 420, 420, 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+440, returnSellCostBuyPrice = returnSellCostBuyPrice+420, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+420
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+420, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+420
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+420
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -440, -420, -420
                    , -420, -420, -420, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-440, netSellCostBuyPrice = netSellCostBuyPrice+-420
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-420
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-420
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-420
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-420
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b0884ec7ca0 and sellbillId = 52 and returnsellbillId = 52
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 08:56:48";
UPDATE user SET loginip = "41.36.106.84", lastactivetime = "2021-12-08 12:26:48", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 12:26:48', '4', 'addsellBill', '41.36.106.84', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 08:56:53";
UPDATE user SET loginip = "41.36.106.84", lastactivetime = "2021-12-08 12:26:53", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-08 12:26:53', '4', '', '41.36.106.84', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 08:56:57";
UPDATE user SET loginip = "41.36.106.84", lastactivetime = "2021-12-08 12:26:57", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 12:26:57', '4', 'addsellBill', '41.36.106.84', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:08:21";
UPDATE user SET loginip = "154.177.16.220", lastactivetime = "2021-12-08 12:38:21", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-08 12:38:21', '8', '', '154.177.16.220', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:08:21";
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 userid = 8;
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:09:05";
UPDATE user SET loginip = "154.177.16.220", lastactivetime = "2021-12-08 12:39:05", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-08 12:39:05', '1', '', '154.177.16.220', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:09:06";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:09:16";
UPDATE user SET loginip = "154.177.16.220", lastactivetime = "2021-12-08 12:39:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 12:39:16', '1', '', '154.177.16.220', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:25:06";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 12:55:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 12:55:06', '1', '', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:25:50";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 12:55:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 12:55:50', '1', '', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:27:04";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 12:57:04", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 12:57:04', '1', 'addsellBill', '154.176.124.59', '', 'DESKTOP');
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:28:16";
UPDATE user SET loginip = "197.41.23.60", lastactivetime = "2021-12-08 12:58:16", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-08 12:58:17', '3', '', '197.41.23.60', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:28:17";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:31:29";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:01:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-08 13:01:30', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:31:47";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:01:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-08 13:01:47', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:32:44";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:02:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:02:44', '1', '', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:33:00";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:03:00", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:03:00', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1584';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '6', '28', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '28.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1578';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '6', '0', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية لم يتغير', 'inventoryController.php', '0.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1577';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '6', '24', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '24.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1492';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '6', '19', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '19.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1491';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '6', '20', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '20.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1490';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('556', '6', '16', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '16.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1489';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '6', '24', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '24.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1488';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '6', '28', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '28.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1062';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('255', '6', '11', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '11.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1061';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('254', '6', '10', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '10.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1060';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('251', '6', '19', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '19.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1059';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('252', '6', '6', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '6.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1058';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('249', '6', '11', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '11.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1057';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('124', '6', '24', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '24.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1056';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('125', '6', '24', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '24.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1055';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('126', '6', '25', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '25.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1054';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('128', '6', '15', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '15.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1053';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('450', '6', '19', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '19.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1052';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('518', '6', '21', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '21.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1051';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('517', '6', '19', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '19.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1050';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('516', '6', '18', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '18.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1049';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('515', '6', '26', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '26.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1048';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('514', '6', '15', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '15.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1047';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('513', '6', '17', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '17.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1046';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('389', '6', '15', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '15.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1045';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('385', '6', '16', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '16.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1044';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('384', '6', '10', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '10.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1043';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('383', '6', '21', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '21.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1042';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('382', '6', '26', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '26.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1041';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('452', '6', '1', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '1.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1040';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('454', '6', '12', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '12.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1039';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('455', '6', '11', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '11.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1038';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('453', '6', '6', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '6.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1037';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('532', '6', '23', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '23.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1036';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('535', '6', '27', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '27.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1035';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('534', '6', '13', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '13.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1034';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('485', '6', '14', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '14.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1033';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('527', '6', '12', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '12.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1032';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('533', '6', '13', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '13.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1031';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('526', '6', '4', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '4.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1030';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('531', '6', '2', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '2.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1029';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('501', '6', '4', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '4.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1028';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('489', '6', '6', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '6.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1027';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('479', '6', '3', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '3.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1026';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('530', '6', '6', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '6.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1025';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('497', '6', '16', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '16.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1024';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('538', '6', '22', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '22.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1023';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('529', '6', '9', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '9.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1022';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('536', '6', '24', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '24.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1021';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('303', '6', '18', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '18.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1020';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('374', '6', '36', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '36.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1019';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('537', '6', '22', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '22.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1018';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('424', '6', '20', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '20.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1017';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('499', '6', '24', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '24.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1016';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('470', '6', '79', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '79.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1015';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('416', '6', '2', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '2.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1014';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('412', '6', '2', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '2.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1013';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('444', '6', '98', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '98.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1012';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('417', '6', '25', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '25.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1011';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('413', '6', '22', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '22.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1010';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('415', '6', '11', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '11.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1009';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('414', '6', '11', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '11.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1008';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('418', '6', '10', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '10.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1007';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('304', '6', '3', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '3.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1006';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('459', '6', '6', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '6.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1005';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('457', '6', '9', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '9.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1004';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('477', '6', '22', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '22.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1003';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('504', '6', '15', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '15.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1002';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('421', '6', '12', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '12.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1001';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('431', '6', '101', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '101.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1000';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('435', '6', '13', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '13.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '999';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('420', '6', '7', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '7.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '998';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('419', '6', '23', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '23.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '997';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('428', '6', '16', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '16.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '996';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('429', '6', '27', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '27.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '995';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('427', '6', '2', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '2.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '994';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('422', '6', '3', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '3.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '993';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('423', '6', '11', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '11.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '992';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('426', '6', '14', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '14.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '991';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('330', '6', '1', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '1.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '990';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('341', '6', '19', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '19.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '989';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('503', '6', '20', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '20.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '988';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('335', '6', '4', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '4.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '987';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('370', '6', '10', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '10.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '986';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('372', '6', '12', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '12.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '985';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('375', '6', '18', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '18.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '984';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('334', '6', '7', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '7.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '983';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('468', '6', '8', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '8.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '982';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('467', '6', '4', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '4.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '981';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('471', '6', '8', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '8.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '980';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('469', '6', '7', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '7.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '979';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('344', '6', '3', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '3.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '978';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('326', '6', '15', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '15.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '977';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('542', '6', '221', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '221.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '976';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('521', '6', '99', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '99.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '975';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('311', '6', '87', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '87.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '974';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('338', '6', '1', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '1.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '973';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('337', '6', '1', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '1.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '972';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('346', '6', '1', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '1.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '971';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('519', '6', '18', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '18.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '970';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('474', '6', '22', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '22.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '969';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('483', '6', '11', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '11.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '968';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('487', '6', '23', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '23.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '967';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('480', '6', '18', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '18.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '966';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('505', '6', '5', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '5.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '965';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('494', '6', '31', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '31.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '964';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('493', '6', '31', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '31.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '963';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('486', '6', '8', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '8.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '962';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('492', '6', '52', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '52.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '961';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('491', '6', '14', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '14.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '960';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('478', '6', '20', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '20.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '959';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('496', '6', '13', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '13.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '958';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('498', '6', '13', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '13.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '957';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('502', '6', '9', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '9.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '956';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('481', '6', '6', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '6.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '955';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('490', '6', '20', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '20.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '954';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('458', '6', '15', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '15.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '953';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('397', '6', '187', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '187.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '952';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('394', '6', '58', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '58.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '951';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('359', '6', '16', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '16.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '950';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('353', '6', '15', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '15.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '949';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('163', '6', '6', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '6.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '948';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('488', '6', '41', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '41.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '947';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('90', '6', '20', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '20.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '946';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('322', '6', '11', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '11.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '945';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('528', '6', '11', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '11.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '944';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('395', '6', '16', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '16.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '943';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('331', '6', '13', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '13.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '942';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('377', '6', '13', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '13.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '941';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('327', '6', '4', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '4.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '940';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('328', '6', '11', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '11.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '939';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('333', '6', '3', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '3.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '938';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('339', '6', '5', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '5.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '937';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('369', '6', '46', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '46.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '936';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('360', '6', '7', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '7.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '935';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('425', '6', '17', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '17.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '934';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('376', '6', '15', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '15.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '933';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('357', '6', '11', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '11.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '932';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('364', '6', '21', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '21.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '931';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('350', '6', '22', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '22.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '930';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('356', '6', '23', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '23.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '929';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('354', '6', '24', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '24.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '928';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('355', '6', '25', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '25.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '927';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('358', '6', '14', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '14.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '926';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('348', '6', '17', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '17.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '925';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('343', '6', '30', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '30.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '924';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('365', '6', '23', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '23.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '923';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('352', '6', '11', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '11.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '922';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('371', '6', '8', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '8.00', '0', '1', '2021-12-08','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '921';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('340', '6', '9', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '9.00', '0', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:33:26";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:03:26", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:03:26', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:36:55";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:06:55", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:06:56', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '41', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1586';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '5', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '40.00', '41', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 09:36:58";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:06:58", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:06:58', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:01:55";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:31:55", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:31:55', '1', '', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:02:20";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:32:20", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:32:20', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '1', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '466';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('466', '1', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '1', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:02:22";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:32:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:32:22', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:02:35";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:32:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 13:32:35', '1', 'add', '154.176.124.59', '', '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(145,1,6,466,1,'2021-12-08',1,0, '' ,0,0,0,0,0,'2021-12-08 13:32:35',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '466';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-08', 1, 466, 0, 0
                    , 240.00, -1, 0, 0, 1, '2021-12-08 13:32:35')
                ON DUPLICATE KEY UPDATE buyprice = 240.00,
                        buyQuantity =buyQuantity+-1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-08 13:32:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "1*2021-12-08*240.00," WHERE transferproductid = 1101;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('466', '1', '1', '1', '1101', 'تحويل منتجات من المخزن', 'storemovementController.php', '1.00', '0', '1', '2021-12-08','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('466', '6', '1', '1', '2021-12-08');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-08', 6, 466, 0, 0
                    , 240.00, 1, 0, 0, 1, '2021-12-08 13:32:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-08 13:32:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('466', '6', '1', '0', '1101', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '1', '1', '2021-12-08','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:02:37";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:32:37", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 13:32:37', '1', 'sucess', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:02:39";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:32:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 13:32:39', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:02:50";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:32:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:32:50', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '25', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1660';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('466', '6', '24', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '1.00', '25', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:02:52";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:32:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:32:52', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:03:45";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:33:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:33:45', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '18', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1056';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('125', '6', '18', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '18', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:03:46";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:33:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:33:46', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:05:18";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:35:18", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:35:18', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '28', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1057';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('124', '6', '28', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '28', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:05:20";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:35:20", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:35:20', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:05:45";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:35:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:35:45', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '12', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1491';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '6', '12', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '12', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:05:47";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:35:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:35:47', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:06:17";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:36:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:36:17', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '21', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1488';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '6', '21', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '21', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:06:19";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:36:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:36:19', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:06:43";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:36:43", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:36:43', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '17', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1051';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('517', '6', '17', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '17', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:06:45";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:36:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:36:45', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:07:34";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:37:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:37:34', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '9', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1048';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('514', '6', '9', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '9', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:07:36";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:37:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:37:36', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:09:15";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:39:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:39:15', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '11', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1048';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('514', '6', '2', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '9.00', '11', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:09:17";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:39:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:39:17', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:09:37";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:39:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:39:38', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '18', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1047';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('513', '6', '18', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '18', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:09:39";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:39:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:39:39', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:10:48";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:40:48", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:40:48', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '20', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1052';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('518', '6', '20', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '20', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:10:50";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:40:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:40:50', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:11:37";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:41:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:41:42', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '24', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1049';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('515', '6', '24', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '24', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:11:44";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:41:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:41:44', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:12:07";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:42:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:42:07', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '14', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1050';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('516', '6', '14', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '14', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:12:09";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:42:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:42:09', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:12:43";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:42:43", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:42:43', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '18', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1492';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '6', '18', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '18', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:12:45";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:42:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:42:45', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:13:32";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:43:32", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:43:32', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '14', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1055';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('126', '6', '14', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '14', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:13:34";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:43:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:43:34', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:13:54";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:43:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:43:54', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '25', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1049';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('515', '6', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '24.00', '25', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:13:56";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:43:56", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:43:56', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:14:15";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:44:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:44:15', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '15', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1050';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('516', '6', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '14.00', '15', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:14:17";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:44:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:44:17', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:14:48";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:44:48", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:44:48', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '14', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1053';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('450', '6', '14', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '14', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:14:50";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:44:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:44:50', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:16:35";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:46:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:46:35', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '1', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '465';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('465', '1', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '1', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:16:36";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:46:37", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:46:37', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:16:38";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:46:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 13:46:38', '1', '', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:16:50";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:46:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 13:46:50', '1', 'add', '154.176.124.59', '', '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(146,1,6,465,1,'2021-12-08',1,0, '' ,0,0,0,0,0,'2021-12-08 13:46:50',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '465';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-08', 1, 465, 0, 0
                    , 210.00, -1, 0, 0, 1, '2021-12-08 13:46:50')
                ON DUPLICATE KEY UPDATE buyprice = 210.00,
                        buyQuantity =buyQuantity+-1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-08 13:46:50' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "1*2021-12-08*210.00," WHERE transferproductid = 1102;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('465', '1', '1', '1', '1102', 'تحويل منتجات من المخزن', 'storemovementController.php', '1.00', '0', '1', '2021-12-08','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('465', '6', '1', '1', '2021-12-08');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-08', 6, 465, 0, 0
                    , 210.00, 1, 0, 0, 1, '2021-12-08 13:46:50')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-08 13:46:50' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('465', '6', '1', '0', '1102', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '1', '1', '2021-12-08','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:16:52";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:46:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 13:46:52', '1', 'sucess', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:16:54";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:46:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 13:46:54', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:17:08";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:47:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:47:08', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '13', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1661';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('465', '6', '12', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '1.00', '13', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:17:21";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:47:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:47:21', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:17:50";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:47:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:47:50', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '1', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1482';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '1', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '1', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:17:52";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:47:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:47:52', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:17:54";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:47:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 13:47:54', '1', '', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:18:15";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:48:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 13:48:15', '1', 'add', '154.176.124.59', '', '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(147,1,6,563,1,'2021-12-08',1,0, '' ,0,0,0,0,0,'2021-12-08 13:48:15',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1482';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-08', 1, 563, 0, 0
                    , 210.00, -1, 0, 0, 1, '2021-12-08 13:48:15')
                ON DUPLICATE KEY UPDATE buyprice = 210.00,
                        buyQuantity =buyQuantity+-1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-08 13:48:15' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "1*2021-12-08*210.00," WHERE transferproductid = 1103;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '1', '1', '1', '1103', 'تحويل منتجات من المخزن', 'storemovementController.php', '1.00', '0', '1', '2021-12-08','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('563', '6', '1', '1', '2021-12-08');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-08', 6, 563, 0, 0
                    , 210.00, 1, 0, 0, 1, '2021-12-08 13:48:15')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-08 13:48:15' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '6', '1', '0', '1103', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '1', '1', '2021-12-08','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:18:16";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:48:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 13:48:16', '1', 'sucess', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:18:17";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:48:18", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 13:48:18', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:18:29";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:48:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:48:29', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '15', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1662';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '6', '14', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '1.00', '15', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:18:41";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:48:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:48:41', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:20:04";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:50:04", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:50:04', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '41', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1577';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '6', '41', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '41', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:20:06";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:50:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:50:06', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:20:46";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:50:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:50:46', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '17', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1489';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '6', '17', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '17', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:20:48";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:50:48", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:50:48', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:21:24";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:51:24", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:51:24', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '6', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1061';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('254', '6', '6', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '6', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:21:26";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:51:26", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:51:26', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:23:04";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:53:04", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:53:04', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '9', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1062';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('255', '6', '9', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '9', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:23:06";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:53:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:53:06', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:23:38";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:53:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:53:38', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '1', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '253';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('253', '1', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '1', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:23:40";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:53:40", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:53:40', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:23:41";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:53:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 13:53:41', '1', '', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:24:06";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:54:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 13:54:06', '1', 'add', '154.176.124.59', '', '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(148,1,6,253,1,'2021-12-08',1,0, '' ,0,0,0,0,0,'2021-12-08 13:54:06',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '253';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-08', 1, 253, 0, 0
                    , 225.00, -1, 0, 0, 1, '2021-12-08 13:54:06')
                ON DUPLICATE KEY UPDATE buyprice = 225.00,
                        buyQuantity =buyQuantity+-1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-08 13:54:06' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "1*2021-12-08*225.00," WHERE transferproductid = 1104;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('253', '1', '1', '1', '1104', 'تحويل منتجات من المخزن', 'storemovementController.php', '1.00', '0', '1', '2021-12-08','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('253', '6', '1', '1', '2021-12-08');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-08', 6, 253, 0, 0
                    , 225.00, 1, 0, 0, 1, '2021-12-08 13:54:06')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-08 13:54:06' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('253', '6', '1', '0', '1104', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '1', '1', '2021-12-08','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:24:06";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:54:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 13:54:06', '1', 'sucess', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:24:08";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:54:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 13:54:08', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:24:18";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:54:18", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:54:18', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '11', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1663';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('253', '6', '10', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '1.00', '11', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:24:29";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:54:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:54:29', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:25:00";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:55:00", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:55:00', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '19', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1060';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('251', '6', '19', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '19', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:25:02";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:55:02", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:55:02', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:25:45";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:55:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:55:45', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '15', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1054';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('128', '6', '15', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '15', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:25:47";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:55:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:55:47', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:26:39";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:56:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:56:39', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '15', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1490';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('556', '6', '15', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '15', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:26:41";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 13:56:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 13:56:41', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:36:08";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:06:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:06:08', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '146', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '953';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('397', '6', '146', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '146', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:36:10";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:06:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:06:11', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:37:04";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:07:04", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:07:05', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '12', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '986';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('372', '6', '12', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '12', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:37:07";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:07:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:07:07', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:37:48";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:07:48", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:07:48', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '9', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '933';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('357', '6', '9', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '9', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:37:50";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:07:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:07:50', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:38:07";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:08:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:08:07', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '34', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1020';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('374', '6', '34', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '34', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:38:09";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:08:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:08:09', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:38:40";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:08:40", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:08:40', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '21', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '989';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('503', '6', '21', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '21', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:38:41";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:08:42", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:08:42', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:39:43";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:09:43", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:09:44', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '26', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1036';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('535', '6', '26', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '26', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:39:45";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:09:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:09:46', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:40:55";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:10:55", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:10:55', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '14', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1025';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('497', '6', '14', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '14', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:40:57";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:10:57", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:10:57', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:41:26";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:11:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:11:27', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '13', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '958';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('498', '6', '13', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '13', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:41:28";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:11:28", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:11:28', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:41:49";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:11:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:11:49', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '24', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1022';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('536', '6', '24', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '24', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:41:51";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:11:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:11:52', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:42:11";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:12:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:12:12', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '13', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1019';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('537', '6', '13', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '13', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:42:14";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:12:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:12:14', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:42:33";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:12:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:12:33', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '10', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1033';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('527', '6', '10', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '10', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:42:35";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:12:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:12:35', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:43:49";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:13:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:13:50', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '15', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1026';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('530', '6', '15', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '15', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:43:51";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:13:51", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:13:51', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:44:08";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:14:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:14:08', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '12', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1032';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('533', '6', '12', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '12', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:44:09";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:14:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:14:10', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:45:15";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:15:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:15:15', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '17', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '967';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('480', '6', '17', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '17', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:45:17";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:15:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:15:17', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:45:36";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:15:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:15:36', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '14', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1019';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('537', '6', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '13.00', '14', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:45:38";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:15:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:15:38', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:46:09";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:16:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:16:09', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '24', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1037';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('532', '6', '24', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '24', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:46:11";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:16:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:16:11', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:47:07";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:17:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:17:07', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '3', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1031';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('526', '6', '3', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '3', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:47:09";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:17:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:17:09', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:47:28";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:17:28", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:17:28', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '26', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1037';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('532', '6', '2', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '24.00', '26', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:47:30";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:17:30", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:17:30', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:47:52";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:17:53", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:17:53', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '10', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '933';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('357', '6', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '9.00', '10', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:47:54";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:17:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:17:54', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:48:28";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:18:28", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:18:28', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '2', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1030';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('531', '6', '2', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '2', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:48:29";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:18:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:18:29', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:49:17";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:19:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 14:19:17', '1', '', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:49:39";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:19:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:19:39', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '1', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '336';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('336', '1', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '1', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:49:41";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:19:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:19:41', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:49:47";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:19:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 14:19:47', '1', 'add', '154.176.124.59', '', '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(149,1,6,336,1,'2021-12-08',1,0, '' ,0,0,0,0,0,'2021-12-08 14:19:47',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '336';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-08', 1, 336, 0, 0
                    , 150.00, -1, 0, 0, 1, '2021-12-08 14:19:47')
                ON DUPLICATE KEY UPDATE buyprice = 150.00,
                        buyQuantity =buyQuantity+-1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-08 14:19:47' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "1*2021-12-08*150.00," WHERE transferproductid = 1105;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('336', '1', '1', '1', '1105', 'تحويل منتجات من المخزن', 'storemovementController.php', '1.00', '0', '1', '2021-12-08','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('336', '6', '1', '1', '2021-12-08');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-08', 6, 336, 0, 0
                    , 150.00, 1, 0, 0, 1, '2021-12-08 14:19:47')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-08 14:19:47' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('336', '6', '1', '0', '1105', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '1', '1', '2021-12-08','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:49:48";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:19:48", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 14:19:48', '1', 'sucess', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:49:49";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:19:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 14:19:50', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:50:14";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:20:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:20:14', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '21', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1664';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('336', '6', '20', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '1.00', '21', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:50:16";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:20:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:20:16', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:50:49";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:20:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:20:49', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '18', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '985';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('375', '6', '18', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '18', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:50:51";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:20:51", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:20:51', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:51:22";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:21:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:21:22', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '12', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '934';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('376', '6', '12', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '12', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:51:24";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:21:24", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:21:24', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:51:50";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:21:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:21:50', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '6', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '984';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('334', '6', '6', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '6', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:51:52";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:21:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:21:52', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:52:12";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:22:12", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:22:12', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '14', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '950';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('353', '6', '14', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '14', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:52:14";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:22:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:22:14', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:53:31";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:23:31", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:23:31', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '10', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '945';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('528', '6', '10', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '10', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:53:32";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:23:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:23:33', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:54:47";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:24:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-08 14:24:47', '1', '', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:55:21";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:25:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-08 14:25:22', '1', 'add', '154.176.124.59', '', '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 ('اطفال دكرون','','1','95','100', '130','110', '2021-12-08', '0', '1', '0', '', '0', '0', '0', '0', '0', '95','95','95','95','95','0','5.26','15.79','36.84','.','0','0','0','0','0','','','0','0','0');
UPDATE product SET productName = 'اطفال دكرون', productDescription = '', productCatId = '1', productBuyPrice = '95', productSellAllPrice = '100', productSellUnitPrice = '130', productSellHalfPrice = '110', productDate = '2021-12-08', conditions = '0', userId = '1', limitamount = '0', parcode = '00599',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '95',lastbuyprice_withDiscount = '95',meanbuyprice = '95',meanbuyprice_withDiscount = '95' , productbuypricereal = '95' , buypricereal_precentage = '0' , buytotal_precentage = '5.26' , buyhalf_precentage = '15.79' , buypart_precentage = '36.84',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '599';
INSERT INTO productunit (unitid, productid, productnumber, productunitdate, userid, conditions,proUnitParcode,proUnitSellAllPrice,proUnitSellHalfPrice,proUnitSellUnitPrice,proUnitBuyPrice) VALUES ('1', '599', '1', '2021-12-08', '1', '0','0059901','100','110','130','95');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('599', '1', '80', '1', '2021-12-08');
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('599', '1', '80', '0', '599', 'إضافة منتج', 'productController.php', '0', '80', '1', '2021-12-08','0','0');
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (599, 1,'2021-12-08 14:25:22',1)
                ON DUPLICATE KEY UPDATE productid = 599, edited = 1, sysdate = '2021-12-08 14:25:22', userid = 1;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '7600', '7600', '2021-12-08', '1', '0', '0', '2021-12-08 14:25:22','إضافة منتج اطفال دكرون الكمية 80','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('765', '19', '7600', '','0');
UPDATE accountstree SET name = 'البضاعة (بضاعة أول المدة)', customName = 'البضاعة (بضاعة أول المدة)', parent = '6', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '6127062.5', theOrder = '0', layingOrder = '121',reportid = '0' WHERE id = '19';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('765', '7', '7600', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '6978448.3', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
UPDATE product SET productName = 'اطفال دكرون', productDescription = '', productCatId = '1', productBuyPrice = '95.00', productSellAllPrice = '100.00', productSellUnitPrice = '130.00', productSellHalfPrice = '110.00', productDate = '2021-12-08', conditions = '0', userId = '1', limitamount = '0', parcode = '00599',type ='0', expireDate = '0' , dailyentryId = '765',isService = '0',isOptic = '0',lastbuyprice = '95',lastbuyprice_withDiscount = '95',meanbuyprice = '95',meanbuyprice_withDiscount = '95' , productbuypricereal = '95' , buypricereal_precentage = '0' , buytotal_precentage = '5.26' , buyhalf_precentage = '15.79' , buypart_precentage = '36.84',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '599';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:55:23";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:25:23", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-08 14:25:24', '1', '', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:55:49";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:25:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 14:25:49', '1', '', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:56:13";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:26:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 14:26:13', '1', 'add', '154.176.124.59', '', '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(150,1,6,599,80,'2021-12-08',1,0, '' ,0,0,0,0,0,'2021-12-08 14:26:13',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1665';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-08', 1, 599, 0, 0
                    , 95.00, -80, 0, 0, 1, '2021-12-08 14:26:13')
                ON DUPLICATE KEY UPDATE buyprice = 95.00,
                        buyQuantity =buyQuantity+-80, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-08 14:26:13' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "80*2021-12-08*95.00," WHERE transferproductid = 1106;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('599', '1', '80', '1', '1106', 'تحويل منتجات من المخزن', 'storemovementController.php', '80.00', '0', '1', '2021-12-08','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('599', '6', '80', '1', '2021-12-08');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-08', 6, 599, 0, 0
                    , 95.00, 80, 0, 0, 1, '2021-12-08 14:26:13')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+80, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-08 14:26:13' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('599', '6', '80', '0', '1106', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '80', '1', '2021-12-08','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:56:14";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:26:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 14:26:14', '1', 'sucess', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:56:16";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:26:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 14:26:16', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:56:27";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:26:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:26:27', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '80', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1666';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('599', '6', '80', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية لم يتغير', 'inventoryController.php', '80.00', '80', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 10:56:29";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:26:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:26:29', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:01:19";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:31:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:31:19', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '14', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1043';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('383', '6', '14', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '14', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:01:21";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:31:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:31:21', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:01:42";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:31:42", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:31:42', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '15', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1045';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('385', '6', '15', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '15', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:01:44";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:31:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:31:44', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:06:56";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:36:56", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:36:56', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '19', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1042';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('382', '6', '19', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '19', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:06:58";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:36:58", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:36:58', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:07:27";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:37:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:37:27', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '6', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1044';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('384', '6', '6', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '6', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:07:29";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:37:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:37:29', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:08:27";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:38:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:38:27', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '14', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '386';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('386', '1', '14', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '14', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:08:29";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:38:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:38:29', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:08:35";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:38:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 14:38:35', '1', '', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:08:59";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:38:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 14:38:59', '1', 'add', '154.176.124.59', '', '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(151,1,6,386,14,'2021-12-08',1,0, '' ,0,0,0,0,0,'2021-12-08 14:38:59',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '386';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-08', 1, 386, 0, 0
                    , 185.00, -14, 0, 0, 1, '2021-12-08 14:38:59')
                ON DUPLICATE KEY UPDATE buyprice = 185.00,
                        buyQuantity =buyQuantity+-14, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-08 14:38:59' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "14*2021-12-08*185.00," WHERE transferproductid = 1107;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('386', '1', '14', '1', '1107', 'تحويل منتجات من المخزن', 'storemovementController.php', '14.00', '0', '1', '2021-12-08','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('386', '6', '14', '1', '2021-12-08');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-08', 6, 386, 0, 0
                    , 185.00, 14, 0, 0, 1, '2021-12-08 14:38:59')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+14, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-08 14:38:59' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('386', '6', '14', '0', '1107', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '14', '1', '2021-12-08','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:08:59";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:38:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 14:38:59', '1', 'sucess', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:09:01";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:39:01", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-08 14:39:01', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:09:13";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:39:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:39:13', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '14', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1667';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('386', '6', '14', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية لم يتغير', 'inventoryController.php', '14.00', '14', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:09:24";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:39:24", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:39:24', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:09:45";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:39:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:39:45', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '27', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '1042';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('382', '6', '8', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '19.00', '27', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:09:47";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:39:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:39:47', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:10:39";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:40:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:40:39', '1', 'add', '154.176.124.59', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '30', userid = '1', storedetaildate = '2021-12-08' WHERE storedetailid = '977';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('542', '6', '30', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '30', '1', '2021-12-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:10:41";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:40:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:40:41', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 1;
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:27:37";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:57:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-08 14:57:38', '1', '', '154.176.124.59', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:27:38";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:28:11";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 14:58:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-08 14:58:11', '1', '', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:28:35";
UPDATE user SET loginip = "41.36.106.84", lastactivetime = "2021-12-08 14:58:35", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-08 14:58:35', '4', '', '41.36.106.84', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:28:47";
UPDATE user SET loginip = "41.36.106.84", lastactivetime = "2021-12-08 14:58:47", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2021-12-08 14:58:47', '4', 'showDetail', '41.36.106.84', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:29:00";
UPDATE user SET loginip = "41.36.106.84", lastactivetime = "2021-12-08 14:59:00", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-08 14:59:00', '4', '', '41.36.106.84', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:37:03";
UPDATE user SET loginip = "41.36.106.84", lastactivetime = "2021-12-08 15:07:03", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 15:07:03', '4', 'addsellBill', '41.36.106.84', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:37:52";
UPDATE user SET loginip = "41.36.106.84", lastactivetime = "2021-12-08 15:07:52", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 15:07:52', '4', 'addsellBill', '41.36.106.84', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 1;
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:45:50";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 15:15:50", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-08 15:15:50', '8', '', '154.176.124.59', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:45:50";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:57:45";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 15:27:45", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-08 15:27:45', '5', '', '197.55.224.197', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:57:45";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:57:48";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 15:27:49", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 15:27:49', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:57:49";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 15:27:49", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 15:27:49', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:58:51";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 15:28:51", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 15:28:51', '5', 'addAndRetuen', '197.55.224.197', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b0b2d5acc84
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-08 15:27:49', '061b0b2d5acc84', '1', '0.00', '0', '0', '1', '1175', '1175', '1175', '0', '3', '2021-12-08 15:28:51', '', '5', '0', 'نقدي', '3', '0', '3', '0', 'نقدي', '5' ,'0','','','','','-1','0','0','0','0','0','1175','0','','0','0','1175','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '5' 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','اضافة فاتورة مبيعات','193', '0', '2021-12-08 15:28:51', '5', 'sellbillController.php', 'اضافة فاتورة مبيعات', '1175', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+3 where id = 1890;
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','00563', '193', '1', '563', '3', '230', '690', '0', '', '2', '2021-12-08 15:28:51', '563', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','1890-3,');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 210.00, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 210.00
                where sellbilldetailid = 436;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (563, '2021-12-08', 690, 630, 630
                    , 630, 630, 630, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 3, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+690, sellCostBuyPrice =sellCostBuyPrice+630
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+630, sellCostMeanBuyPrice = sellCostMeanBuyPrice+630
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+630, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+630
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+3
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2021-12-08', 690, 630, 630
                    , 630, 630, 630, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+690, sellCostBuyPrice =sellCostBuyPrice+630
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+630, sellCostMeanBuyPrice = sellCostMeanBuyPrice+630
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+630, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+630
                            , 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 = '5', storedetaildate = '2021-12-08 15:28:51' WHERE storedetailid = '1505';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '3', '3', '1', '193', 'اضافة فاتورة مبيعات', 'sellbillController.php', '19.00', '16', '5', '2021-12-08 15:28:51','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1880;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('150','00565', '193', '1', '565', '1', '240', '240', '0', '', '2', '2021-12-08 15:28:51', '565', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','1880-1,');
UPDATE sellbilldetail SET  lastbuyprice = 150.00 , meanbuyprice = 150.00, lastbuyprice_withDiscount = 150.00, meanbuyprice_withDiscount = 150.00
                where sellbilldetailid = 437;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (565, '2021-12-08', 240, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+240, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+150, sellCostMeanBuyPrice = sellCostMeanBuyPrice+150
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+150, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+150
                            , 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 (3, '2021-12-08', 240, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+240, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+150, sellCostMeanBuyPrice = sellCostMeanBuyPrice+150
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+150, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+150
                            , 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 = '30', userid = '5', storedetaildate = '2021-12-08 15:28:51' WHERE storedetailid = '1500';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '3', '1', '1', '193', 'اضافة فاتورة مبيعات', 'sellbillController.php', '31.00', '30', '5', '2021-12-08 15:28:51','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2056;
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 ('230','00590', '193', '1', '590', '1', '245', '245', '0', '', '2', '2021-12-08 15:28:51', '590', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','2056-1,');
UPDATE sellbilldetail SET  lastbuyprice = 230.00 , meanbuyprice = 230.00, lastbuyprice_withDiscount = 230.00, meanbuyprice_withDiscount = 230.00
                where sellbilldetailid = 438;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (590, '2021-12-08', 245, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+245, sellCostBuyPrice =sellCostBuyPrice+230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+230
                            , 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 (3, '2021-12-08', 245, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+245, sellCostBuyPrice =sellCostBuyPrice+230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+230
                            , 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 = '37', userid = '5', storedetaildate = '2021-12-08 15:28:51' WHERE storedetailid = '1585';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '3', '1', '1', '193', 'اضافة فاتورة مبيعات', 'sellbillController.php', '38.00', '37', '5', '2021-12-08 15:28:51','0','0');
UPDATE save SET  savecurrentvalue = '4465',  userid = '5' WHERE saveid = '3';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('3290.00','1175', '0', '3', 'اضافة فاتورة مبيعات', '193', '4465', '2021-12-08 15:28:51', '5',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-08', 1175, 1010, 1010
                    , 1010, 1010, 1010, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1175, sellCostBuyPrice =sellCostBuyPrice+1010
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1010, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1010
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1010, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1010
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-08', 1175, 1010, 1010
                    , 1010, 1010, 1010, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1175, sellCostBuyPrice =sellCostBuyPrice+1010
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1010, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1010
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1010, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1010
                            , 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, 1175, 1010, 1010
                    , 1010, 1010, 1010, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+1175, netSellCostBuyPrice = netSellCostBuyPrice+1010
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+1010
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+1010
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+1010
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+1010
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b0b2d5acc84 and sellbillId = 193 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:58:52";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 15:28:52", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 15:28:52', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:59:12";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 15:29:12", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-08 15:29:12', '5', '', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:59:12";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 15:29:12", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-08 15:29:12', '5', '', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:59:29";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 15:29:29", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 15:29:29', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:59:29";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 15:29:29", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 15:29:29', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 8;
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:59:54";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 15:29:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-08 15:29:54', '1', '', '154.176.124.59', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 11:59:54";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 12:00:00";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 15:30:00", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-08 15:30:00', '1', 'show', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 12:00:02";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 15:30:02", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-08 15:30:02', '1', '', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 1;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:06:08";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 16:36:08", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 16:36:08', '5', 'addAndRetuen', '197.55.224.197', '', 'DESKTOP');
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

;

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b0b339bfc0b
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(69,@clientdebt,@clientname);
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-08 15:29:29', '061b0b339bfc0b', '69', '36605.00', '42125', '240', '1', '5760', '5520', '0', '5520', '3', '2021-12-08 16:36:08', '', '5', '0', 'سنتر مكه', '3', '1', '3', '0', 'سنتر مكه', '24' ,'0','','','','','-1','0','0','0','0','0','5520','0','','0','0','0','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '42125', userid = '5' WHERE clientid = '69';
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 ('69','36605.00','5520','0','اضافة فاتورة مبيعات','194', '42125', '2021-12-08 16:36:08', '5', 'sellbillController.php', 'اضافة فاتورة مبيعات', '5520', '0', null, '0', null, null,'', '0','1','1','5520','1');
UPDATE client SET  inUse = 0 where clientid = 69;
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+8 where id = 1890;
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','00563', '194', '1', '563', '8', '230', '1840', '0', '', '2', '2021-12-08 16:36:08', '563', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','1890-8,');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 210.00, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 210.00
                where sellbilldetailid = 439;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (563, '2021-12-08', 1763.33333333, 1680, 1680
                    , 1680, 1680, 1680, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 8, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1763.33333333, sellCostBuyPrice =sellCostBuyPrice+1680
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1680, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1680
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1680, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1680
                            , 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+8
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2021-12-08', 1763.33333333, 1680, 1680
                    , 1680, 1680, 1680, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1763.33333333, sellCostBuyPrice =sellCostBuyPrice+1680
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1680, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1680
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1680, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1680
                            , 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 = '8', userid = '5', storedetaildate = '2021-12-08 16:36:08' WHERE storedetailid = '1505';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '3', '8', '1', '194', 'اضافة فاتورة مبيعات', 'sellbillController.php', '16.00', '8', '5', '2021-12-08 16:36:08','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+8 where id = 2020;
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 ('230','00589', '194', '1', '589', '8', '245', '1960', '0', '', '2', '2021-12-08 16:36:08', '589', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','2020-8,');
UPDATE sellbilldetail SET  lastbuyprice = 230.00 , meanbuyprice = 230.00, lastbuyprice_withDiscount = 230.00, meanbuyprice_withDiscount = 230.00
                where sellbilldetailid = 440;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (589, '2021-12-08', 1878.33333333, 1840, 1840
                    , 1840, 1840, 1840, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 8, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1878.33333333, sellCostBuyPrice =sellCostBuyPrice+1840
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1840, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1840
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1840, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1840
                            , 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+8
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2021-12-08', 1878.33333333, 1840, 1840
                    , 1840, 1840, 1840, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1878.33333333, sellCostBuyPrice =sellCostBuyPrice+1840
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1840, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1840
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1840, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1840
                            , 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 = '20', userid = '5', storedetaildate = '2021-12-08 16:36:08' WHERE storedetailid = '1576';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '3', '8', '1', '194', 'اضافة فاتورة مبيعات', 'sellbillController.php', '28.00', '20', '5', '2021-12-08 16:36:08','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+8 where id = 2056;
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 ('230','00590', '194', '1', '590', '8', '245', '1960', '0', '', '2', '2021-12-08 16:36:08', '590', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','2056-8,');
UPDATE sellbilldetail SET  lastbuyprice = 230.00 , meanbuyprice = 230.00, lastbuyprice_withDiscount = 230.00, meanbuyprice_withDiscount = 230.00
                where sellbilldetailid = 441;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (590, '2021-12-08', 1878.33333333, 1840, 1840
                    , 1840, 1840, 1840, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 8, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1878.33333333, sellCostBuyPrice =sellCostBuyPrice+1840
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1840, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1840
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1840, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1840
                            , 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+8
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2021-12-08', 1878.33333333, 1840, 1840
                    , 1840, 1840, 1840, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1878.33333333, sellCostBuyPrice =sellCostBuyPrice+1840
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1840, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1840
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1840, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1840
                            , 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 = '29', userid = '5', storedetaildate = '2021-12-08 16:36:08' WHERE storedetailid = '1585';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '3', '8', '1', '194', 'اضافة فاتورة مبيعات', 'sellbillController.php', '37.00', '29', '5', '2021-12-08 16:36:08','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-08', 5520, 5360, 5360
                    , 5360, 5360, 5360, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+5520, sellCostBuyPrice =sellCostBuyPrice+5360
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+5360, sellCostMeanBuyPrice = sellCostMeanBuyPrice+5360
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+5360, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+5360
                            , 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 (69, '2021-12-08', 5520, 5360, 5360
                    , 5360, 5360, 5360, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+5520, sellCostBuyPrice =sellCostBuyPrice+5360
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+5360, sellCostMeanBuyPrice = sellCostMeanBuyPrice+5360
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+5360, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+5360
                            , 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, 5520, 5360, 5360
                    , 5360, 5360, 5360, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+5520, netSellCostBuyPrice = netSellCostBuyPrice+5360
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+5360
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+5360
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+5360
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+5360
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b0b339bfc0b and sellbillId = 194 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:06:09";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 16:36:09", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 16:36:09', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:06:15";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 16:36:15", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 16:36:15', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:06:15";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 16:36:15", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 16:36:15', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:08:04";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 16:38:04", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 16:38:05', '5', 'addAndRetuen', '197.55.224.197', '', 'DESKTOP');
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

;

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b0c2e0196b5
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(69,@clientdebt,@clientname);
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-12-08 16:36:16', '061b0c2e0196b5', '69', '42125.00', '35930', '375', '1', '6570', '6195', '0', '-6195', '3', '2021-12-08 16:38:05', '', '5', '0', 'سنتر مكه','3', '1', '5', '0', 'سنتر مكه', '27', '0', '', '','','','-1','0','0','0','','0','0','0','0','0','0','0','0');
UPDATE client SET  clientdebt = '35930', userid = '5' WHERE clientid = '69';
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 ('69','42125.00','6195','1','اضافة فاتورة مردوات مبيعات','53', '35930', '2021-12-08 16:38:05', '5', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '6195', '0', null, '0', null, null,'', '0','1','1','6195','1');
UPDATE client SET  inUse = 0 where clientid = 69;
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', '00560', '53', '1', '560', '14', '235', '3290', '0', '', '2', '0', '560', '0.00', '0','3','0','','','0','0','0','0','0','2');
UPDATE returnsellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where returnsellbilldetailid = 88;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (560, '2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 3477.78538813, 3080, 3080, 3080
                    , 3080, 3080, 0, 0, 14)
                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+3477.78538813, returnSellCostBuyPrice = returnSellCostBuyPrice+3080, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+3080
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+3080, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+3080
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+3080
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+0
                        , netQuantityRet = netQuantityRet+14;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 3477.78538813, 3080, 3080, 3080
                    , 3080, 3080, 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+3477.78538813, returnSellCostBuyPrice = returnSellCostBuyPrice+3080, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+3080
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+3080, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+3080
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+3080
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '62', userid = '5', storedetaildate = '2021-12-08 16:38:05' WHERE storedetailid = '1501';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('560', '3', '14', '0', '53', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '48.00', '62', '5', '2021-12-08 16:38:05','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 ('235.00', '00129', '53', '1', '129', '11', '260', '2860', '0', '', '2', '0', '129', '0.00', '0','3','0','','','0','0','0','0','0','2');
UPDATE returnsellbilldetail SET  lastbuyprice = 235.00 , meanbuyprice = 235.00, lastbuyprice_withDiscount = 235.00, meanbuyprice_withDiscount = 235.00
                where returnsellbilldetailid = 89;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (129, '2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 3023.24200913, 2585, 2585, 2585
                    , 2585, 2585, 0, 0, 11)
                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+3023.24200913, returnSellCostBuyPrice = returnSellCostBuyPrice+2585, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+2585
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+2585, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+2585
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+2585
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+0
                        , netQuantityRet = netQuantityRet+11;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 3023.24200913, 2585, 2585, 2585
                    , 2585, 2585, 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+3023.24200913, returnSellCostBuyPrice = returnSellCostBuyPrice+2585, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+2585
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+2585, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+2585
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+2585
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '11', userid = '5', storedetaildate = '2021-12-08 16:38:05' WHERE storedetailid = '1547';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('129', '3', '11', '0', '53', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '0.00', '11', '5', '2021-12-08 16:38:05','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 ('185.00', '00125', '53', '1', '125', '1', '210', '210', '0', '', '2', '0', '125', '0.00', '0','3','0','','','0','0','0','0','0','2');
UPDATE returnsellbilldetail SET  lastbuyprice = 185.00 , meanbuyprice = 185.00, lastbuyprice_withDiscount = 185.00, meanbuyprice_withDiscount = 185.00
                where returnsellbilldetailid = 90;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (125, '2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 221.98630137, 185, 185, 185
                    , 185, 185, 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+221.98630137, returnSellCostBuyPrice = returnSellCostBuyPrice+185, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+185
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+185, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+185
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+185
                            , 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 (3, '2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 221.98630137, 185, 185, 185
                    , 185, 185, 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+221.98630137, returnSellCostBuyPrice = returnSellCostBuyPrice+185, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+185
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+185, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+185
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+185
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '112', userid = '5', storedetaildate = '2021-12-08 16:38:05' WHERE storedetailid = '1459';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('125', '3', '1', '0', '53', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '111.00', '112', '5', '2021-12-08 16:38:05','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 ('185.00', '00124', '53', '1', '124', '1', '210', '210', '0', '', '2', '0', '124', '0.00', '0','3','0','','','0','0','0','0','0','2');
UPDATE returnsellbilldetail SET  lastbuyprice = 185.00 , meanbuyprice = 185.00, lastbuyprice_withDiscount = 185.00, meanbuyprice_withDiscount = 185.00
                where returnsellbilldetailid = 91;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (124, '2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 221.98630137, 185, 185, 185
                    , 185, 185, 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+221.98630137, returnSellCostBuyPrice = returnSellCostBuyPrice+185, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+185
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+185, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+185
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+185
                            , 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 (3, '2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 221.98630137, 185, 185, 185
                    , 185, 185, 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+221.98630137, returnSellCostBuyPrice = returnSellCostBuyPrice+185, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+185
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+185, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+185
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+185
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '95', userid = '5', storedetaildate = '2021-12-08 16:38:05' WHERE storedetailid = '1462';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('124', '3', '1', '0', '53', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '94.00', '95', '5', '2021-12-08 16:38:05','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 6195, 6035, 6035, 6035
                    , 6035, 6035, 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+6195, returnSellCostBuyPrice = returnSellCostBuyPrice+6035, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+6035
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+6035, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+6035
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+6035
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (69, '2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 6195, 6035, 6035, 6035
                    , 6035, 6035, 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+6195, returnSellCostBuyPrice = returnSellCostBuyPrice+6035, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+6035
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+6035, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+6035
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+6035
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -6195, -6035, -6035
                    , -6035, -6035, -6035, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-6195, netSellCostBuyPrice = netSellCostBuyPrice+-6035
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-6035
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-6035
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-6035
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-6035
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b0c2e0196b5 and sellbillId = 53 and returnsellbillId = 53
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:08:05";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 16:38:05", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 16:38:05', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:19:31";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 16:49:31", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 16:49:31', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:19:31";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 16:49:31", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 16:49:31', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:42:37";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 17:12:37", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 17:12:37', '5', 'addAndRetuen', '197.55.224.197', '', 'DESKTOP');
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

;

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b0c5fbc3de6
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(70,@clientdebt,@clientname);
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-08 16:49:31', '061b0c5fbc3de6', '70', '16945.00', '22345', '360', '1', '5760', '5400', '0', '5400', '3', '2021-12-08 17:12:37', '', '5', '0', 'سنتر اولاد حموده', '3', '1', '3', '0', 'سنتر اولاد حموده', '24' ,'0','','','','','-1','0','0','0','0','0','5400','0','','0','0','0','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '22345', userid = '5' WHERE clientid = '70';
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 ('70','16945.00','5400','0','اضافة فاتورة مبيعات','195', '22345', '2021-12-08 17:12:37', '5', 'sellbillController.php', 'اضافة فاتورة مبيعات', '5400', '0', null, '0', null, null,'', '0','1','1','5400','1');
UPDATE client SET  inUse = 0 where clientid = 70;
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+24 where id = 1952;
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 ('195','00555', '195', '1', '555', '24', '240', '5760', '0', '', '2', '2021-12-08 17:12:37', '555', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','1952-24,');
UPDATE sellbilldetail SET  lastbuyprice = 195.00 , meanbuyprice = 195.00, lastbuyprice_withDiscount = 195.00, meanbuyprice_withDiscount = 195.00
                where sellbilldetailid = 442;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (555, '2021-12-08', 5400, 4680, 4680
                    , 4680, 4680, 4680, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 24, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+5400, sellCostBuyPrice =sellCostBuyPrice+4680
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4680, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4680
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4680, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4680
                            , 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+24
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2021-12-08', 5400, 4680, 4680
                    , 4680, 4680, 4680, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+5400, sellCostBuyPrice =sellCostBuyPrice+4680
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4680, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4680
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4680, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4680
                            , 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 = '18', userid = '5', storedetaildate = '2021-12-08 17:12:37' WHERE storedetailid = '1502';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '3', '24', '1', '195', 'اضافة فاتورة مبيعات', 'sellbillController.php', '42.00', '18', '5', '2021-12-08 17:12:37','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-08', 5400, 4680, 4680
                    , 4680, 4680, 4680, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+5400, sellCostBuyPrice =sellCostBuyPrice+4680
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4680, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4680
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4680, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4680
                            , 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 (70, '2021-12-08', 5400, 4680, 4680
                    , 4680, 4680, 4680, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+5400, sellCostBuyPrice =sellCostBuyPrice+4680
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4680, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4680
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4680, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4680
                            , 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, 5400, 4680, 4680
                    , 4680, 4680, 4680, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+5400, netSellCostBuyPrice = netSellCostBuyPrice+4680
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+4680
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+4680
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+4680
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+4680
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b0c5fbc3de6 and sellbillId = 195 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:42:37";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 17:12:37", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 17:12:37', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:51:01";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 17:21:01", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-08 17:21:01', '8', '', '154.176.124.59', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:51:01";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:51:04";
UPDATE user SET loginip = "154.176.124.59", lastactivetime = "2021-12-08 17:21:04", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 17:21:04', '8', 'addsellBill', '154.176.124.59', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:58:47";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 17:28:47", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 17:28:48', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:58:48";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 17:28:48", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 17:28:48', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:59:47";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 17:29:47", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 17:29:47', '5', 'addAndRetuen', '197.55.224.197', '', 'DESKTOP');
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

;

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b0cf3076379
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(69,@clientdebt,@clientname);
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-12-08 17:28:48', '061b0cf3076379', '69', '35930.00', '35710', '15', '1', '235', '220', '0', '-220', '3', '2021-12-08 17:29:47', '', '5', '0', 'سنتر مكه','3', '1', '5', '0', 'سنتر مكه', '1', '0', '', '','','','-1','0','0','0','','0','0','0','0','0','0','0','0');
UPDATE client SET  clientdebt = '35710', userid = '5' WHERE clientid = '69';
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 ('69','35930.00','220','1','اضافة فاتورة مردوات مبيعات','54', '35710', '2021-12-08 17:29:47', '5', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '220', '0', null, '0', null, null,'', '0','1','1','220','1');
UPDATE client SET  inUse = 0 where clientid = 69;
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', '00560', '54', '1', '560', '1', '235.00', '235', '0', '', '2', '0', '560', '0.00', '0','3','0','','','0','0','0','0','0','2');
UPDATE returnsellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where returnsellbilldetailid = 92;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (560, '2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 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+250, 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 (3, '2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 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+250, returnSellCostBuyPrice = returnSellCostBuyPrice+220, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+220
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+220, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+220
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+220
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '63', userid = '5', storedetaildate = '2021-12-08 17:29:47' WHERE storedetailid = '1501';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('560', '3', '1', '0', '54', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '62.00', '63', '5', '2021-12-08 17:29:47','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 220, 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+220, returnSellCostBuyPrice = returnSellCostBuyPrice+220, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+220
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+220, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+220
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+220
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (69, '2021-12-08', 0, 0, 0
                    , 0, 0, 0, 0
                    , 220, 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+220, returnSellCostBuyPrice = returnSellCostBuyPrice+220, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+220
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+220, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+220
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+220
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -220, -220, -220
                    , -220, -220, -220, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-220, netSellCostBuyPrice = netSellCostBuyPrice+-220
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-220
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-220
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-220
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-220
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b0cf3076379 and sellbillId = 54 and returnsellbillId = 54
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:59:47";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 17:29:47", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 17:29:47', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:59:55";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 17:29:55", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 17:29:55', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:59:56";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 17:29:56", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 17:29:56', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:59:58";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 17:29:58", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 17:29:58', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 13:59:59";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 17:29:59", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 17:29:59', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 14:48:57";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 18:18:57", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-08 18:18:57', '7', '', '156.164.214.28', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 14:48:58";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 14:49:02";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 18:19:02", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 18:19:02', '7', 'addsellBill', '156.164.214.28', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 14:49:02";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 18:19:02", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 18:19:02', '7', 'addsellBill', '156.164.214.28', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 14:49:26";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 18:19:26", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 18:19:26', '7', 'addAndRetuen', '156.164.214.28', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b0daf6b4d7f
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-08 18:19:02', '061b0daf6b4d7f', '1', '0.00', '0', '0', '1', '240', '240', '240', '0', '5', '2021-12-08 18:19:26', '', '7', '0', 'نقدي', '5', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','240','0','','0','0','240','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '7' 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','اضافة فاتورة مبيعات','196', '0', '2021-12-08 18:19:26', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '240', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1864;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('150','00565', '196', '1', '565', '1', '240.00', '240', '0', '', '2', '2021-12-08 18:19:26', '565', '0.00', '0', '5','0','','','0','0','0','0','0','0','2','0','','1864-1,');
UPDATE sellbilldetail SET  lastbuyprice = 150.00 , meanbuyprice = 150.00, lastbuyprice_withDiscount = 150.00, meanbuyprice_withDiscount = 150.00
                where sellbilldetailid = 443;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (565, '2021-12-08', 240, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+240, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+150, sellCostMeanBuyPrice = sellCostMeanBuyPrice+150
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+150, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+150
                            , 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 (5, '2021-12-08', 240, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+240, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+150, sellCostMeanBuyPrice = sellCostMeanBuyPrice+150
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+150, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+150
                            , 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 = '10', userid = '7', storedetaildate = '2021-12-08 18:19:26' WHERE storedetailid = '1494';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '5', '1', '1', '196', 'اضافة فاتورة مبيعات', 'sellbillController.php', '11.00', '10', '7', '2021-12-08 18:19:26','0','0');
UPDATE save SET  savecurrentvalue = '2525',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2285.00','240', '0', '5', 'اضافة فاتورة مبيعات', '196', '2525', '2021-12-08 18:19:26', '7',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-08', 240, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+240, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+150, sellCostMeanBuyPrice = sellCostMeanBuyPrice+150
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+150, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+150
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-08', 240, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+240, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+150, sellCostMeanBuyPrice = sellCostMeanBuyPrice+150
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+150, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+150
                            , 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, 240, 150, 150
                    , 150, 150, 150, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+240, netSellCostBuyPrice = netSellCostBuyPrice+150
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+150
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+150
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+150
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+150
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b0daf6b4d7f and sellbillId = 196 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 14:49:26";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 18:19:26", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 18:19:26', '7', 'addsellBill', '156.164.214.28', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 14:49:40";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 18:19:40", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-08 18:19:40', '7', '', '156.164.214.28', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 14:49:40";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 18:19:40", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-08 18:19:40', '7', '', '156.164.214.28', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 14:51:16";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 18:21:16", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 18:21:16', '7', 'addsellBill', '156.164.214.28', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 15:40:12";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 19:10:12", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 19:10:12', '7', 'addAndRetuen', '156.164.214.28', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b0db7c2fa79
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-08 18:21:16', '061b0db7c2fa79', '1', '0.00', '0', '0', '1', '490', '490', '490', '0', '5', '2021-12-08 19:10:12', '', '7', '0', 'نقدي', '5', '0', '3', '0', 'نقدي', '2' ,'0','','','','','-1','0','0','0','0','0','490','0','','0','0','490','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '7' 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','اضافة فاتورة مبيعات','197', '0', '2021-12-08 19:10:12', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '490', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+2 where id = 720;
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','00251', '197', '1', '251', '2', '245.00', '490', '0', '', '2', '2021-12-08 19:10:12', '251', '0.00', '0', '5','0','','','0','0','0','0','0','0','2','0','','720-2,');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 210.00, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 210.00
                where sellbilldetailid = 444;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (251, '2021-12-08', 490, 420, 420
                    , 420, 420, 420, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 2, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+490, sellCostBuyPrice =sellCostBuyPrice+420
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+420, sellCostMeanBuyPrice = sellCostMeanBuyPrice+420
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+420, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+420
                            , 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 (5, '2021-12-08', 490, 420, 420
                    , 420, 420, 420, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+490, sellCostBuyPrice =sellCostBuyPrice+420
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+420, sellCostMeanBuyPrice = sellCostMeanBuyPrice+420
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+420, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+420
                            , 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 = '7', userid = '7', storedetaildate = '2021-12-08 19:10:12' WHERE storedetailid = '911';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('251', '5', '2', '1', '197', 'اضافة فاتورة مبيعات', 'sellbillController.php', '9.00', '7', '7', '2021-12-08 19:10:12','0','0');
UPDATE save SET  savecurrentvalue = '3015',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2525.00','490', '0', '5', 'اضافة فاتورة مبيعات', '197', '3015', '2021-12-08 19:10:12', '7',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-08', 490, 420, 420
                    , 420, 420, 420, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+490, sellCostBuyPrice =sellCostBuyPrice+420
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+420, sellCostMeanBuyPrice = sellCostMeanBuyPrice+420
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+420, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+420
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-08', 490, 420, 420
                    , 420, 420, 420, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+490, sellCostBuyPrice =sellCostBuyPrice+420
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+420, sellCostMeanBuyPrice = sellCostMeanBuyPrice+420
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+420, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+420
                            , 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, 490, 420, 420
                    , 420, 420, 420, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+490, netSellCostBuyPrice = netSellCostBuyPrice+420
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+420
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+420
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+420
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+420
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b0db7c2fa79 and sellbillId = 197 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 15:40:12";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 19:10:12", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 19:10:12', '7', 'addsellBill', '156.164.214.28', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 17:03:25";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 20:33:25", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-08 20:33:25', '7', '', '156.164.214.28', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 17:05:16";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 20:35:16", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-08 20:35:16', '7', '', '156.164.214.28', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 17:05:43";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 20:35:43", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-08 20:35:44', '7', 'add', '156.164.214.28', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('2', 'عبدالله', '', '400', '2021-12-08', '7', '0','-1','5','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '2615',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('3015.00','400', '1', '5', 'إضافة مصروف', '26', '2615', '2021-12-08 20:35:44', '7',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '400', '400', '2021-12-08', '7', '0', '0', '2021-12-08 20:35:44','اضافة اسم مصروف( عبدالله )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('766', '145', '400', '','0');
UPDATE accountstree SET name = 'مرتبات', customName = 'مرتبات', parent = '14', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-08', itemtype2 = '0', theValue = '4150', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '145';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('766', '139', '400', '','0');
UPDATE accountstree SET name = 'خزينة محل عبدالله', customName = 'خزينة محل عبدالله', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-9904', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '139';
UPDATE expenses SET expensestypeid = '2', expensesname = 'عبدالله', expensesdetails = '', expensesValue = '400.00', expensesdate = '2021-12-08', userid = '7', conditions = '0',saveid = '5' , dailyentryid = '766', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '26';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 17:05:44";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 20:35:44", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-08 20:35:44', '7', 'sucess', '156.164.214.28', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 17:05:46";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 20:35:46", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-08 20:35:46', '7', 'show', '156.164.214.28', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 17:05:47";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 20:35:47", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 20:35:47', '7', 'addsellBill', '156.164.214.28', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 18:04:16";
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 18:04:16";
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 18:04:22";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 21:34:22", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-08 21:34:22', '5', '', '197.55.224.197', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 18:04:22";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 18:04:35";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 21:34:35", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-08 21:34:35', '5', '', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 18:04:35";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 21:34:35", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-08 21:34:35', '5', '', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 18:06:00";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 21:36:00", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2021-12-08 21:36:00', '5', '', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 18:07:57";
UPDATE user SET loginip = "197.55.224.197", lastactivetime = "2021-12-08 21:37:58", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 21:37:58', '5', 'addsellBill', '197.55.224.197', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 19:12:26";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 22:42:26", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2021-12-08 22:42:26', '7', '', '156.164.214.28', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-08 19:12:56";
UPDATE user SET loginip = "156.164.214.28", lastactivetime = "2021-12-08 22:42:57", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-08 22:42:57', '7', 'addsellBill', '156.164.214.28', '', 'DESKTOP');
