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-06 07:13:34";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 10:43:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-06 10:43:34', '1', '', '102.45.192.219', '', '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-06',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-06 07:13:35";
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-06 07:14:51";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 10:44:51", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-06 10:44:51', '4', '', '197.61.214.79', '', '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-06 07:14:51";
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-06 07:15:30";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 10:45:30", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 10:45:30', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 07:49:23";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:19:23", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 11:19:23', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 07:49:25";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:19:25", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storedetailController.php', '2021-12-06 11:19:25', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 07:49:28";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:19:28", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 11:19:28', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 07:49:37";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:19:37", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 11:19:37', '4', 'show', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 07:49:46";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:19:46", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 11:19:46', '4', 'addsellBill', '197.61.214.79', '', '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-06 07:51:01";
UPDATE user SET loginip = "197.61.107.31", lastactivetime = "2021-12-06 11:21:02", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-06 11:21:02', '6', '', '197.61.107.31', '', '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-06 07:51:02";
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-06 07:51:04";
UPDATE user SET loginip = "197.61.107.31", lastactivetime = "2021-12-06 11:21:04", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-06 11:21:04', '6', '', '197.61.107.31', '', '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-06 07:51:04";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 07:51:09";
UPDATE user SET loginip = "197.61.107.31", lastactivetime = "2021-12-06 11:21:09", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 11:21:09', '6', '', '197.61.107.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 07:51:15";
UPDATE user SET loginip = "197.61.107.31", lastactivetime = "2021-12-06 11:21:15", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 11:21:15', '6', 'addsellBill', '197.61.107.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:05:17";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:35:17", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 11:35:17', '4', 'addAndRetuen', '197.61.214.79', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061add5b28700b
-- ----------------------------------------------------------------------------------------------------

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-06 11:19:46', '061add5b28700b', '1', '0.00', '0', '0', '1', '230', '230', '230', '0', '7', '2021-12-06 11:35:17', '', '4', '0', 'نقدي', '7', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','230','0','','0','0','230','0','0','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','0','اضافة فاتورة مبيعات','168', '0', '2021-12-06 11:35:17', '4', 'sellbillController.php', 'اضافة فاتورة مبيعات', '230', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1910;
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', '168', '1', '565', '1', '230.00', '230', '0', '', '0', '2021-12-06 11:35:17', '565', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','1910-1,');
UPDATE sellbilldetail SET  lastbuyprice = 150.00 , meanbuyprice = 150.00, lastbuyprice_withDiscount = 150.00, meanbuyprice_withDiscount = 150.00
                where sellbilldetailid = 384;
 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-06', 230, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+230, 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 (7, '2021-12-06', 230, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+230, 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 = '18', userid = '4', storedetaildate = '2021-12-06 11:35:17' WHERE storedetailid = '1514';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '7', '1', '1', '168', 'اضافة فاتورة مبيعات', 'sellbillController.php', '19.00', '18', '4', '2021-12-06 11:35:17','0','0');
UPDATE save SET  savecurrentvalue = '6730',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('6500.00','230', '0', '7', 'اضافة فاتورة مبيعات', '168', '6730', '2021-12-06 11:35:17', '4',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-06', 230, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+230, 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-06', 230, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+230, 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, 230, 150, 150
                    , 150, 150, 150, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+230, netSellCostBuyPrice = netSellCostBuyPrice+150
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+150
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+150
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+150
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+150
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061add5b28700b and sellbillId = 168 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:05:17";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:35:17", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 11:35:17', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:06:02";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:36:02", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 11:36:02', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:06:14";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:36:14", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 11:36:14', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:07:28";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:37:28", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 11:37:28', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:07:38";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:37:38", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 11:37:38', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:08:56";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 11:38:56", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-06 11:38:56', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:09:04";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:39:04", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 11:39:04', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:09:24";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:39:24", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 11:39:24', '4', 'add', '197.61.214.79', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('3', 'الايجار', '', '6500', '2021-12-06', '4', '0','-1','7','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '230',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('6730.00','6500', '1', '7', 'إضافة مصروف', '17', '230', '2021-12-06 11:39:24', '4',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '6500', '6500', '2021-12-06', '4', '0', '0', '2021-12-06 11:39:24','اضافة اسم مصروف( الايجار )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('729', '146', '6500', '','0');
UPDATE accountstree SET name = 'ايجار', customName = 'ايجار', parent = '14', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-08', itemtype2 = '0', theValue = '6500', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '146';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('729', '141', '6500', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-25755', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE expenses SET expensestypeid = '3', expensesname = 'الايجار', expensesdetails = '', expensesValue = '6500.00', expensesdate = '2021-12-06', userid = '4', conditions = '0',saveid = '7' , dailyentryid = '729', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '17';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:09:25";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:39:25", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 11:39:25', '4', 'sucess', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:09:26";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:39:26", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 11:39:26', '4', 'show', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:09:32";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:39:32", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 11:39:32', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:09:33";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 11:39:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 11:39:33', '1', '', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:11:23";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:41:24", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 11:41:24', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:11:34";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:41:35", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 11:41:35', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:11:47";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:41:47", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 11:41:47', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:11:56";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:41:56", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 11:41:56', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:14:25";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 11:44:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 11:44:25', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1581';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('127', '7', '6', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '6.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:14:27";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 11:44:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 11:44:27', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:14:30";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:44:30", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 11:44:30', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:14:45";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:44:45", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 11:44:45', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:15:10";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 11:45:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 11:45:10', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '4', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1514';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '7', '14', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '18.00', '4', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:15:12";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 11:45:12", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 11:45:12', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:15:37";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 11:45:37", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 11:45:37', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '40', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1555';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '7', '5', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '35.00', '40', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:15:38";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 11:45:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 11:45:39', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:15:40";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 11:45:40", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 11:45:40', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 08:55:47";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 12:25:47", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 12:25:47', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:26:02";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 12:56:02", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 12:56:02', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1473';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('556', '7', '21', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '21.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:26:04";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 12:56:04", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 12:56:04', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:26:31";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 12:56:31", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 12:56:31', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1474';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '7', '6', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '6.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:26:33";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 12:56:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 12:56:33', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:27:37";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 12:57:37", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 12:57:37', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1224';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('15', '7', '40', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '40.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:27:39";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 12:57:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 12:57:39', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:27:54";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 12:57:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 12:57:54', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1252';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('81', '7', '15', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '15.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:27:56";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 12:57:56", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 12:57:56', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:30:14";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 13:00:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 13:00:14', '1', '', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:31:03";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 13:01:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 13:01:03', '1', 'add', '102.45.192.219', '', '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(72,4,7,589,6,'2021-12-06',1,0, '' ,0,0,0,0,0,'2021-12-06 13:01:04',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1574';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 4, 589, 0, 0
                    , 230.00, 6, 0, 0, 1, '2021-12-06 13:01:04')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity-6, sellQuantity = sellQuantity-0,
                        del = 0,userid = 1,sysDate = '2021-12-06 13:01:04' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "6*2021-12-01*230.00," WHERE transferproductid = 1026;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '4', '6', '1', '1026', 'تحويل منتجات من المخزن', 'storemovementController.php', '6.00', '0', '1', '2021-12-06','0','0');
UPDATE storedetail SET  productquantity = '8', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1573';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 7, 589, 0, 0
                    , 230.00, 6, 0, 0, 1, '2021-12-06 13:01:04')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+6, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-06 13:01:04' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '7', '6', '0', '1026', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '2.00', '8', '1', '2021-12-06','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:31:04";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 13:01:04", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 13:01:04', '1', 'sucess', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:31:06";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 13:01:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 13:01:06', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:36:38";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:06:38", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 13:06:38', '4', 'addAndRetuen', '197.61.214.79', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061ade52b54103
-- ----------------------------------------------------------------------------------------------------

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-06 12:25:47', '061ade52b54103', '1', '0.00', '0', '60', '1', '940', '880', '880', '0', '7', '2021-12-06 13:06:38', '', '4', '0', 'نقدي', '7', '0', '3', '0', 'نقدي', '4' ,'0','','','','','-1','0','0','0','0','0','880','0','','0','0','880','0','0','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','0','اضافة فاتورة مبيعات','169', '0', '2021-12-06 13:06:38', '4', 'sellbillController.php', 'اضافة فاتورة مبيعات', '880', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+4 where id = 2010;
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', '169', '1', '589', '4', '235.00', '940', '0', '', '0', '2021-12-06 13:06:38', '589', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','2010-4,');
UPDATE sellbilldetail SET  lastbuyprice = 230.00 , meanbuyprice = 230.00, lastbuyprice_withDiscount = 230.00, meanbuyprice_withDiscount = 230.00
                where sellbilldetailid = 385;
 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-06', 880, 920, 920
                    , 920, 920, 920, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 4, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+880, sellCostBuyPrice =sellCostBuyPrice+920
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+920, sellCostMeanBuyPrice = sellCostMeanBuyPrice+920
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+920, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+920
                            , 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+4
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (7, '2021-12-06', 880, 920, 920
                    , 920, 920, 920, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+880, sellCostBuyPrice =sellCostBuyPrice+920
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+920, sellCostMeanBuyPrice = sellCostMeanBuyPrice+920
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+920, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+920
                            , 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 = '4', userid = '4', storedetaildate = '2021-12-06 13:06:38' WHERE storedetailid = '1573';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '7', '4', '1', '169', 'اضافة فاتورة مبيعات', 'sellbillController.php', '8.00', '4', '4', '2021-12-06 13:06:38','0','0');
UPDATE save SET  savecurrentvalue = '1110',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('230.00','880', '0', '7', 'اضافة فاتورة مبيعات', '169', '1110', '2021-12-06 13:06:38', '4',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-06', 880, 920, 920
                    , 920, 920, 920, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+880, sellCostBuyPrice =sellCostBuyPrice+920
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+920, sellCostMeanBuyPrice = sellCostMeanBuyPrice+920
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+920, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+920
                            , 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-06', 880, 920, 920
                    , 920, 920, 920, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+880, sellCostBuyPrice =sellCostBuyPrice+920
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+920, sellCostMeanBuyPrice = sellCostMeanBuyPrice+920
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+920, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+920
                            , 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, 880, 920, 920
                    , 920, 920, 920, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+880, netSellCostBuyPrice = netSellCostBuyPrice+920
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+920
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+920
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+920
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+920
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061ade52b54103 and sellbillId = 169 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:36:38";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:06:38", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 13:06:38', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:36:53";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:06:53", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 13:06:53', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:37:08";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:07:08", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 13:07:08', '4', 'show', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:37:29";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:07:29", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 13:07:29', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:37:47";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:07:48", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 13:07:48', '4', 'add', '197.61.214.79', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('3', 'الايجار', '', '6500', '2021-12-06', '4', '0','-1','7','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '-5390',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1110.00','6500', '1', '7', 'إضافة مصروف', '18', '-5390', '2021-12-06 13:07:48', '4',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '6500', '6500', '2021-12-06', '4', '0', '0', '2021-12-06 13:07:48','اضافة اسم مصروف( الايجار )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('730', '146', '6500', '','0');
UPDATE accountstree SET name = 'ايجار', customName = 'ايجار', parent = '14', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-08', itemtype2 = '0', theValue = '13000', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '146';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('730', '141', '6500', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-32255', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE expenses SET expensestypeid = '3', expensesname = 'الايجار', expensesdetails = '', expensesValue = '6500.00', expensesdate = '2021-12-06', userid = '4', conditions = '0',saveid = '7' , dailyentryid = '730', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '18';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:37:57";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:07:57", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 13:07:57', '4', 'show', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:38:09";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:08:09", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 13:08:09', '4', 'delete', '197.61.214.79', '', 'DESKTOP');
BEGIN;
DELETE FROM expenses WHERE expensesid = '18';
UPDATE dailyentry SET totalcreditor = '6500.00', totaldebtor = '6500.00', thedate = '2021-12-06', userid = '4', `condition` = '0', reverseofid = '-10', dDateTime = '2021-12-06 13:07:48', entryComment = 'اضافة اسم مصروف( الايجار )', fromFlag = '1',related='0' WHERE id = '730';
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '6500.00', '6500.00', '2021-12-06', '4', '0', '730', '2021-12-06 13:08:09','تم عكس القيد رقم 730 ','1','0','-1');
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('731', '146', '6500.00', '','0');
UPDATE accountstree SET name = 'ايجار', customName = 'ايجار', parent = '14', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-08', itemtype2 = '0', theValue = '6500', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '146';
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('731', '141', '6500.00', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-25755', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE costcenterdetail SET del = 1 WHERE type in( 6) and  modelid = 18;
UPDATE save SET  savecurrentvalue = '1110',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('-5390.00','6500.00', '0', '7', 'حذف مصروف', '18', '1110', '2021-12-06 13:08:09', '4',  'expensesController.php','0','');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:38:09";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:08:09", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 13:08:09', '4', 'sucess', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:38:11";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:08:11", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 13:08:11', '4', 'show', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:38:15";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:08:15", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 13:08:15', '4', 'delete', '197.61.214.79', '', 'DESKTOP');
BEGIN;
DELETE FROM expenses WHERE expensesid = '17';
UPDATE dailyentry SET totalcreditor = '6500.00', totaldebtor = '6500.00', thedate = '2021-12-06', userid = '4', `condition` = '0', reverseofid = '-10', dDateTime = '2021-12-06 11:39:24', entryComment = 'اضافة اسم مصروف( الايجار )', fromFlag = '1',related='0' WHERE id = '729';
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '6500.00', '6500.00', '2021-12-06', '4', '0', '729', '2021-12-06 13:08:15','تم عكس القيد رقم 729 ','1','0','-1');
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('732', '146', '6500.00', '','0');
UPDATE accountstree SET name = 'ايجار', customName = 'ايجار', parent = '14', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-08', itemtype2 = '0', theValue = '0', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '146';
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('732', '141', '6500.00', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-19255', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE costcenterdetail SET del = 1 WHERE type in( 6) and  modelid = 17;
UPDATE save SET  savecurrentvalue = '7610',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1110.00','6500.00', '0', '7', 'حذف مصروف', '17', '7610', '2021-12-06 13:08:15', '4',  'expensesController.php','0','');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:38:16";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:08:16", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 13:08:16', '4', 'sucess', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:38:17";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:08:17", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 13:08:17', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:38:29";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:08:29", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 13:08:29', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:38:42";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:08:42", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 13:08:42', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:39:52";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:09:52", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 13:09:52', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:40:32";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:10:32", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 13:10:32', '4', 'addAndRetuen', '197.61.214.79', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061adef80d24ad
-- ----------------------------------------------------------------------------------------------------

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-06 13:09:52', '061adef80d24ad', '1', '0.00', '0', '0', '1', '235', '235', '235', '0', '7', '2021-12-06 13:10:32', '', '4', '0', 'نقدي', '7', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','235','0','','0','0','235','0','0','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','0','اضافة فاتورة مبيعات','170', '0', '2021-12-06 13:10:32', '4', 'sellbillController.php', 'اضافة فاتورة مبيعات', '235', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2010;
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', '170', '1', '589', '1', '235.00', '235', '0', '', '0', '2021-12-06 13:10:32', '589', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','2010-1,');
UPDATE sellbilldetail SET  lastbuyprice = 230.00 , meanbuyprice = 230.00, lastbuyprice_withDiscount = 230.00, meanbuyprice_withDiscount = 230.00
                where sellbilldetailid = 386;
 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-06', 235, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+235, 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 (7, '2021-12-06', 235, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+235, 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 = '3', userid = '4', storedetaildate = '2021-12-06 13:10:32' WHERE storedetailid = '1573';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '7', '1', '1', '170', 'اضافة فاتورة مبيعات', 'sellbillController.php', '4.00', '3', '4', '2021-12-06 13:10:32','0','0');
UPDATE save SET  savecurrentvalue = '7845',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('7610.00','235', '0', '7', 'اضافة فاتورة مبيعات', '170', '7845', '2021-12-06 13:10:32', '4',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-06', 235, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+235, 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;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-06', 235, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+235, 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;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, 235, 230, 230
                    , 230, 230, 230, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+235, netSellCostBuyPrice = netSellCostBuyPrice+230
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+230
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+230
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+230
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+230
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061adef80d24ad and sellbillId = 170 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:40:33";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:10:33", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 13:10:33', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:40:36";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:10:36", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 13:10:36', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:40:54";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:10:54", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 13:10:54', '4', 'addAndRetuen', '197.61.214.79', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061adeface7067
-- ----------------------------------------------------------------------------------------------------

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-06 13:10:36', '061adeface7067', '1', '0.00', '0', '0', '1', '250', '250', '-250', '0', '7', '2021-12-06 13:10:54', '', '4', '0', 'نقدي','7', '0', '5', '0', 'نقدي', '1', '0', '', '','','','-1','0','0','0','','0','-250','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','اضافة فاتورة مردوات مبيعات','40', '0', '2021-12-06 13:10:54', '4', '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', '40', '1', '129', '1', '250', '250', '0', '', '0', '0', '129', '0.00', '0','7','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 = 67;
 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-06', 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 (7, '2021-12-06', 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 = '43', userid = '4', storedetaildate = '2021-12-06 13:10:54' WHERE storedetailid = '1312';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('129', '7', '1', '0', '40', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '42.00', '43', '4', '2021-12-06 13:10:54','0','0');
UPDATE save SET  savecurrentvalue = '7595',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('7845.00','250', '1', '7', 'اضافة فاتورة مردوات مبيعات', '40', '7595', '2021-12-06 13:10:54', '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-06', 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-06', 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 061adeface7067 and sellbillId = 40 and returnsellbillId = 40
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:40:54";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:10:54", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 13:10:54', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:40:59";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:10:59", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 13:10:59', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:41:07";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:11:08", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 13:11:08', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:41:15";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:11:15", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 13:11:15', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:52:34";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:22:34", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 13:22:34', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:52:39";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:22:39", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storedetailController.php', '2021-12-06 13:22:39', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 09:52:48";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:22:48", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storedetailController.php', '2021-12-06 13:22:48', '4', 'show', '197.61.214.79', '', '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-06 09:54:20";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:24:20", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-06 13:24:20', '4', '', '197.61.214.79', '', '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-06 09:54: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 lastactivetime < "2021-12-06 10:03:10";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 13:33:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storeController.php', '2021-12-06 13:33:10', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:03:33";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:33:33", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 13:33:33', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:10:48";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 13:40:48", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 13:40:48', '4', 'addsellBill', '197.61.214.79', '', '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-06 10:23:50";
UPDATE user SET loginip = "156.164.178.238", lastactivetime = "2021-12-06 13:53:50", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-06 13:53:50', '7', '', '156.164.178.238', '', '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-06 10:23:50";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:24:25";
UPDATE user SET loginip = "156.164.178.238", lastactivetime = "2021-12-06 13:54:25", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-06 13:54:25', '7', '', '156.164.178.238', '', '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-06 10:24:25";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:24:28";
UPDATE user SET loginip = "156.164.178.238", lastactivetime = "2021-12-06 13:54:28", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 13:54:28', '7', 'addsellBill', '156.164.178.238', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:34:23";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:04:23", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:04:23', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1237';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('29', '7', '1', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '1.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:34:25";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:04:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:04:25', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:36:53";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:06:53", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:06:53', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1238';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('30', '7', '5', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '5.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:36:55";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:06:55", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:06:55', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:37:25";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:07:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:07:25', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1240';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('32', '7', '3', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '3.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:37:27";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:07:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:07:27', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:37:53";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:07:53", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:07:53', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1241';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('33', '7', '1', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '1.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:37:55";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:07:55", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:07:55', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:38:12";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:08:12", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:08:12', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1243';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('34', '7', '1', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '1.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:38:14";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:08:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:08:15', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:38:38";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:08:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:08:38', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1242';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('35', '7', '1', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '1.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:38:40";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:08:40", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:08:40', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:39:03";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:09:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:09:03', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1260';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('102', '7', '23', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '23.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:39:05";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:09:05", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:09:05', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:39:40";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:09:40", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:09:40', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1261';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('103', '7', '22', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '22.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:39:42";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:09:43", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:09:43', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:40:07";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:10:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:10:07', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1262';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('104', '7', '12', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '12.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:40:08";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:10:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:10:09', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:41:03";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:11:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:11:04', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1276';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('317', '7', '3', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '3.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:41:05";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:11:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:11:06', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:43:19";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:13:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:13:19', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1277';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('316', '7', '3', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '3.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:43:20";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:13:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:13:21', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:44:04";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:14:04", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:14:04', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1245';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('74', '7', '27', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '27.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:44:06";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:14:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:14:06', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:45:08";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:15:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:15:08', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1244';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('73', '7', '20', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '20.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:45:10";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:15:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:15:10', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:46:09";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:16:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:16:09', '1', 'add', '102.45.192.219', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1246';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('75', '7', '10', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '10.00', '0', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:46:11";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:16:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 14:16:11', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:57:47";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:27:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 14:27:47', '1', '', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:58:12";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:28:12", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 14:28:12', '1', 'add', '102.45.192.219', '', '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(73,6,7,589,28,'2021-12-06',1,0, '' ,0,0,0,0,0,'2021-12-06 14:28:12',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1578';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 6, 589, 0, 0
                    , 230.00, 28, 0, 0, 1, '2021-12-06 14:28:12')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity-28, sellQuantity = sellQuantity-0,
                        del = 0,userid = 1,sysDate = '2021-12-06 14:28:12' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "28*2021-12-01*230.00," WHERE transferproductid = 1027;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '6', '28', '1', '1027', 'تحويل منتجات من المخزن', 'storemovementController.php', '28.00', '0', '1', '2021-12-06','0','0');
UPDATE storedetail SET  productquantity = '31', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1573';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-01', 7, 589, 0, 0
                    , 230.00, 28, 0, 0, 1, '2021-12-06 14:28:12')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-06 14:28:12' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '7', '28', '0', '1027', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '3.00', '31', '1', '2021-12-06','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:58:13";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:28:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 14:28:13', '1', 'sucess', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:58:15";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:28:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 14:28:16', '1', 'show', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:58:29";
UPDATE user SET loginip = "102.45.192.219", lastactivetime = "2021-12-06 14:28:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 14:28:29', '1', 'editorder', '102.45.192.219', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:59:01";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 14:29:01", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 14:29:01', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 10:59:05";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 14:29:05", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 14:29:05', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 1;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 11:04:04";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 14:34:04", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storedetailController.php', '2021-12-06 14:34:04', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 11:04:10";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 14:34:10", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storedetailController.php', '2021-12-06 14:34:10', '4', 'show', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 11:04:38";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 14:34:38", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storedetailController.php', '2021-12-06 14:34:38', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 11:04:41";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 14:34:41", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 14:34:41', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 11:04:51";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 14:34:51", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 14:34:51', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 11:04:58";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 14:34:58", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-06 14:34:58', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 11:05:29";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 14:35:29", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 14:35:29', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 11:05:32";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 14:35:32", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 14:35:32', '4', '', '197.61.214.79', '', 'DESKTOP');
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 11:06:12";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 14:36:12", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-06 14:36:12', '4', '', '197.61.214.79', '', '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-06 11:06:12";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 11:06:15";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 14:36:15", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storedetailController.php', '2021-12-06 14:36:15', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 11:06:20";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 14:36:20", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storedetailController.php', '2021-12-06 14:36:20', '4', 'show', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 11:08:02";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 14:38:02", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 14:38:02', '4', 'addsellBill', '197.61.214.79', '', '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-06 11:27:33";
UPDATE user SET loginip = "197.41.18.32", lastactivetime = "2021-12-06 14:57:33", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-06 14:57:33', '3', '', '197.41.18.32', '', '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-06 11:27:33";
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-06 11:27:37";
UPDATE user SET loginip = "197.41.18.32", lastactivetime = "2021-12-06 14:57:37", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 14:57:37', '3', 'addsellBill', '197.41.18.32', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 11:51:27";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 15:21:27", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 15:21:27', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 11:51:46";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 15:21:46", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 15:21:46', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 12:03:21";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 15:33:21", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 15:33:21', '4', '', '197.61.214.79', '', '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-06 12:47:46";
UPDATE user SET loginip = "154.176.185.18", lastactivetime = "2021-12-06 16:17:46", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-06 16:17:46', '8', '', '154.176.185.18', '', '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-06 12:47:47";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 12:47:55";
UPDATE user SET loginip = "154.176.185.18", lastactivetime = "2021-12-06 16:17:55", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 16:17:55', '8', 'addsellBill', '154.176.185.18', '', '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-06 12:52:34";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 16:22:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-06 16:22:34', '1', '', '102.45.245.74', '', '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-06 12:52:34";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 12:58:17";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 16:28:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 16:28:17', '1', 'showdetails', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 12:58:26";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 16:28:26", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 16:28:26', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 12:58:34";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 16:28:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 16:28:34', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:01:24";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 16:31:24", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2021-12-06 16:31:24', '1', '', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:04:26";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 16:34:26", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2021-12-06 16:34:26', '1', 'add', '102.45.245.74', '', '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

;

-- ----------------------------------------------------------------------------------------------------
-- clientPayedDeptController add - with modelid =336
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(12,@clientdebt,@clientname);
UPDATE client SET  clientdebt = '66671' , clientdate = '2021-12-06 16:34:27', userid = '1' WHERE clientid = '12';
UPDATE client SET  inUse = 0 where clientid = 12;
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 ('12','71671.00','5000','1','ايصال تحصيل (( قبض من عميل ))','336', '66671', '2021-12-06 16:31:24', '1', 'clientPayedDeptController.php', '   ', '5000', '0', null, '0', null, null,'', '-1','1','1','1','1');
UPDATE save SET  savecurrentvalue = '91776',  userid = '1' WHERE saveid = '1';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('86776.00','5000', '0', '1', 'ايصال تحصيل (( قبض من عميل ))', '336', '91776', '2021-12-06 16:34:27', '1',  'clientPayedDeptController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '5000', '5000', '2021-12-06', '1', '0', '0', '2021-12-06 16:34:27','اضافة ايصال سداد للعميل احمد العسوى','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('733', '54', '5000', '','0');
UPDATE accountstree SET name = 'الخزنة الرئيسية', customName = 'الخزنة الرئيسية', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2018-04-21', itemtype2 = '1', theValue = '111885', theOrder = '0', layingOrder = '1221',reportid = '2' WHERE id = '54';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('733', '65', '5000', '','0');
UPDATE accountstree SET name = 'احمد العسوى', customName = 'احمد العسوى', parent = '23', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-14000', theOrder = '0', layingOrder = '',reportid = '0' WHERE id = '65';
UPDATE clientdebtchange SET clientid = '12', clientdebtchangebefore = '71671.00', clientdebtchangeamount = '5000.00', clientdebtchangetype = '1', processname = 'ايصال تحصيل (( قبض من عميل ))', clientdebtchangemodelid = '336', clientdebtchangeafter = '66671.00', clientdebtchangedate = '2021-12-06 16:31:24', userid = '1', tablename = 'clientPayedDeptController.php', comment = '   ', totalOperationCost = '5000.00',discount='', reciptid=null, dailyentryid = '733',seller = '0',currencyId='1',conversionFactor='1',payedInCurrency='1',saveConversionFactor='1' WHERE clientdebtchangeid = '336';
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- clientPayedDeptController add end - with modelid =336 -clientdebtchangeId = 336
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:04:27";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 16:34:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2021-12-06 16:34:27', '1', 'sucess', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:04:31";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 16:34:31", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2021-12-06 16:34:32', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:28:11";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 16:58:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-06 16:58:11', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:31:57";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:01:57", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 17:01:57', '1', '', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:32:00";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:02:00", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 17:02:00', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:32:15";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:02:15", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 17:02:15', '4', 'add', '197.61.214.79', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('3', 'الايجار', '', '6500', '2021-12-06', '4', '0','-1','7','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '1095',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('7595.00','6500', '1', '7', 'إضافة مصروف', '19', '1095', '2021-12-06 17:02:15', '4',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '6500', '6500', '2021-12-06', '4', '0', '0', '2021-12-06 17:02:15','اضافة اسم مصروف( الايجار )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('734', '146', '6500', '','0');
UPDATE accountstree SET name = 'ايجار', customName = 'ايجار', parent = '14', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-08', itemtype2 = '0', theValue = '6500', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '146';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('734', '141', '6500', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-25755', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE expenses SET expensestypeid = '3', expensesname = 'الايجار', expensesdetails = '', expensesValue = '6500.00', expensesdate = '2021-12-06', userid = '4', conditions = '0',saveid = '7' , dailyentryid = '734', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '19';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:32:15";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:02:15", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 17:02:15', '4', 'sucess', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:32:17";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:02:17", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 17:02:17', '4', 'show', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:32:18";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:02:18", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 17:02:18', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:32:26";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:02:26", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-06 17:02:26', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:32:54";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:02:54", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 17:02:54', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:33:43";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:03:43", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-06 17:03:43', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:33:49";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:03:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-06 17:03:49', '1', '', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:33:54";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:03:54", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 17:03:54', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:34:06";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:04:06", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 17:04:06', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:34:15";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:04:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-06 17:04:15', '1', 'add', '102.45.245.74', '', 'DESKTOP');
INSERT INTO impotencetreatmentsuppliersave (typesimpotencetreatmentid, saveid, supplierid, impotencetreatmentsuppliersavetype, impotencetreatmentsuppliersavebefore, impotencetreatmentsuppliersavetamount, impotencetreatmentsuppliersaveafter, impotencetreatmentsuppliersavecomment, conditions, impotencetreatmentsuppliersavedate, userid, tablename) VALUES ('-1', '7', '-1', '0', '1095.00', '5000', '6095', 'دفعة من احمد العيسوي', '0', '2021-12-06 17:04:15', '1', 'settlementsaveController.php');
INSERT INTO supplierdebtchange (supplierid, supplierdebtchangebefore, supplierdebtchangeamount, supplierdebtchangetype, processname, supplierdebtchangemodelid, supplierdebtchangeafter, supplierdebtchangedate, userid, tablename, comment, dailyentryid,saveid, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor) VALUES ('-1', '', '5000', '1', ' خصم معالجة عجز  / دفعة من احمد العيسوي', '6', '-5000', '2021-12-06', '1', 'supplierPayedDeptController.php', 'دفعة من احمد العيسوي', '0','7', '0','1','1','5000','1');
UPDATE supplier SET  suppliercurrentDebt = '-5000', userid = '1', supplierdate = '2021-12-06'   WHERE supplierid = '-1';
UPDATE supplierdebtchange SET supplierid = '-1', supplierdebtchangebefore = '0.00', supplierdebtchangeamount = '5000.00', supplierdebtchangetype = '1', processname = ' خصم معالجة عجز  / دفعة من احمد العيسوي', supplierdebtchangemodelid = '6', supplierdebtchangeafter = '-5000.00', supplierdebtchangedate = '2021-12-06 00:00:00', userid = '1', tablename = 'supplierPayedDeptController.php', comment = 'دفعة من احمد العيسوي', dailyentryid = '0',saveid = '7',currencyId='1',conversionFactor='1',payedInCurrency='5000',saveConversionFactor='1' WHERE supplierdebtchangeid = '6';
UPDATE save SET  savecurrentvalue = '6095',  userid = '1' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1095.00','5000', '0', '7', 'تسوية خزنة بالإضافة', '-1', '6095', '2021-12-06 17:04:15', '1',  'settlementsaveController.php','0','دفعة من احمد العيسوي');
UPDATE savedaily SET  savedailymodelid = '274' WHERE savedailyid = '274';
BEGIN;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '5000', '5000', '2021-12-06', '1', '0', '0', '2021-12-06 17:04:15','اضافة معالجة عجز ( بالاضافة )','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('735', '141', '5000', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-20755', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('735', '27', '5000', '','0');
UPDATE accountstree SET name = 'معالجة عجز خزنة', customName = 'معالجة عجز خزنة', parent = '3', itemtype = '0', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-06-15', itemtype2 = '1', theValue = '52708', theOrder = '0', layingOrder = '35',reportid = '1' WHERE id = '27';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:34:15";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:04:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-06 17:04:15', '1', 'sucess', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:34:18";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:04:18", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2021-12-06 17:04:18', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:34:20";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:04:20", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 17:04:20', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:34:23";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:04:23", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-06 17:04:23', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:34:45";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:04:45", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 17:04:45', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:34:48";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:04:48", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 17:04:48', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:35:00";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:05:00", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesTypeController.php', '2021-12-06 17:05:00', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:35:07";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:05:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesTypeController.php', '2021-12-06 17:05:07', '1', '', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:35:22";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:05:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 17:05:22', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:35:47";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:05:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-06 17:05:47', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:36:16";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:06:16", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 17:06:16', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:36:46";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:06:46", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 17:06:46', '4', 'add', '197.61.214.79', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('-1', 'اكياس', '', '1800', '2021-12-06', '4', '0','-1','7','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '4295',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('6095.00','1800', '1', '7', 'إضافة مصروف', '20', '4295', '2021-12-06 17:06:46', '4',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '1800', '1800', '2021-12-06', '4', '0', '0', '2021-12-06 17:06:46','اضافة اسم مصروف( اكياس )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('736', '160', '1800', '','0');
UPDATE accountstree SET name = '', customName = '', parent = '10', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-12-01', itemtype2 = '1', theValue = '-9050', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '160';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('736', '141', '1800', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-22555', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE expenses SET expensestypeid = '-1', expensesname = 'اكياس', expensesdetails = '', expensesValue = '1800.00', expensesdate = '2021-12-06', userid = '4', conditions = '0',saveid = '7' , dailyentryid = '736', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '20';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:36:47";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:06:47", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 17:06:47', '4', 'sucess', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:36:48";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:06:48", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 17:06:49', '4', 'show', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:36:49";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:06:49", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 17:06:49', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:36:53";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:06:53", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-06 17:06:53', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:37:06";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:07:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-06 17:07:06', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:37:13";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:07:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-06 17:07:13', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:37:15";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:07:15", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 17:07:15', '4', 'add', '197.61.214.79', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('-1', 'شحن رصيد', '', '710', '2021-12-06', '4', '0','-1','7','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '3585',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('4295.00','710', '1', '7', 'إضافة مصروف', '21', '3585', '2021-12-06 17:07:15', '4',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '710', '710', '2021-12-06', '4', '0', '0', '2021-12-06 17:07:15','اضافة اسم مصروف( شحن رصيد )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('737', '160', '710', '','0');
UPDATE accountstree SET name = '', customName = '', parent = '10', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-12-01', itemtype2 = '1', theValue = '-9760', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '160';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('737', '141', '710', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-23265', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE expenses SET expensestypeid = '-1', expensesname = 'شحن رصيد', expensesdetails = '', expensesValue = '710.00', expensesdate = '2021-12-06', userid = '4', conditions = '0',saveid = '7' , dailyentryid = '737', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '21';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:37:15";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:07:15", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 17:07:15', '4', 'sucess', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:37:17";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:07:17", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-06 17:07:17', '4', 'show', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:37:21";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:07:21", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 17:07:21', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:37:27";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:07:27", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 17:07:27', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:37:38";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:07:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storeController.php', '2021-12-06 17:07:38', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:37:50";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:07:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-06 17:07:50', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:38:41";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:08:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 17:08:41', '1', 'showdetails', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:38:44";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:08:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 17:08:44', '1', '', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:38:58";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:08:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2021-12-06 17:08:59', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:39:03";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:09:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2021-12-06 17:09:03', '1', '', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:39:43";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:09:43", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2021-12-06 17:09:43', '1', 'add', '102.45.245.74', '', 'DESKTOP');
BEGIN;
INSERT INTO transfermoney (saveidfrom, saveidto, transfermoneyvalue, transfermoneydate, userid, conditions, dailyentryid , comment) VALUES ('7','9', '3585.00', '2021-12-06', '1', '0', '0','');
UPDATE save SET  savecurrentvalue = '0',  userid = '1' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('3585.00','3585.00', '1', '7', 'تحويل امول الى الخزنة  [ الشيخ وليد ] ', '6', '0', '2021-12-06 17:09:43', '1',  'transfermoneyController.php','0','');
UPDATE save SET  savecurrentvalue = '4875',  userid = '1' WHERE saveid = '9';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1290.00','3585.00', '0', '9', 'تحويل امول من الخزنة  [ خزينة محل العميد ] ', '6', '4875', '2021-12-06 17:09:43', '1',  'transfermoneyController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '3585', '3585', '2021-12-06', '1', '0', '0', '2021-12-06 17:09:43','اضافة تحويل من خزينة محل العميد الى الشيخ وليد','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('738', '156', '3585.00', '','0');
UPDATE accountstree SET name = 'الشيخ وليد', customName = 'الشيخ وليد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-09', itemtype2 = '1', theValue = '4875', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '156';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('738', '141', '3585.00', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-26850', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE transfermoney SET saveidfrom = '7', saveidto = '9', transfermoneyvalue = '3585.00', transfermoneydate = '2021-12-06', userid = '1', conditions = '0' , dailyentryid = '738' , comment = '' WHERE transfermoneyid = '6';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:39:44";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:09:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2021-12-06 17:09:44', '1', 'sucess', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:39:46";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:09:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2021-12-06 17:09:46', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:39:50";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:09:50", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 17:09:50', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:39:56";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:09:56", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-06 17:09:56', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:40:27";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:10:27", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 17:10:28', '4', 'addsellBill', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 13:40:31";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:10:31", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 17:10:32', '4', '', '197.61.214.79', '', '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-06 13:40:53";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:10:53", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-06 17:10:53', '4', '', '197.61.214.79', '', '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-06 13:40:53";
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-06 13:40:55";
UPDATE user SET loginip = "197.61.214.79", lastactivetime = "2021-12-06 17:10:55", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 17:10:55', '4', '', '197.61.214.79', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 14:01:45";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:31:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-06 17:31:45', '1', '', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 14:01:54";
UPDATE user SET loginip = "102.45.245.74", lastactivetime = "2021-12-06 17:31:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-06 17:31:54', '1', 'show', '102.45.245.74', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 15:56:10";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 19:26:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-06 19:26:10', '1', 'show', '102.46.57.147', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 15:56:19";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 19:26:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-06 19:26:19', '1', 'show', '102.46.57.147', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 15:56:38";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 19:26:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-06 19:26:38', '1', '', '102.46.57.147', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 15:57:27";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 19:27:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-06 19:27:27', '1', 'add', '102.46.57.147', '', '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 ('820','','1','230','235', '265','245', '2021-12-06', '0', '1', '0', '', '0', '0', '0', '0', '0', '230','230','230','230','230','0','2.17','6.52','15.22','.','0','0','0','0','0','','','0','0','0');
UPDATE product SET productName = '820', productDescription = '', productCatId = '1', productBuyPrice = '230', productSellAllPrice = '235', productSellUnitPrice = '265', productSellHalfPrice = '245', productDate = '2021-12-06', conditions = '0', userId = '1', limitamount = '0', parcode = '00590',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '230',lastbuyprice_withDiscount = '230',meanbuyprice = '230',meanbuyprice_withDiscount = '230' , productbuypricereal = '230' , buypricereal_precentage = '0' , buytotal_precentage = '2.17' , buyhalf_precentage = '6.52' , buypart_precentage = '15.22',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '590';
INSERT INTO productunit (unitid, productid, productnumber, productunitdate, userid, conditions,proUnitParcode,proUnitSellAllPrice,proUnitSellHalfPrice,proUnitSellUnitPrice,proUnitBuyPrice) VALUES ('1', '590', '1', '2021-12-06', '1', '0','0059001','235','245','265','230');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('590', '1', '196', '1', '2021-12-06');
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '1', '196', '0', '590', 'إضافة منتج', 'productController.php', '0', '196', '1', '2021-12-06','0','0');
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (590, 1,'2021-12-06 19:27:27',1)
                ON DUPLICATE KEY UPDATE productid = 590, edited = 1, sysdate = '2021-12-06 19:27:27', userid = 1;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '45080', '45080', '2021-12-06', '1', '0', '0', '2021-12-06 19:27:27','إضافة منتج 820 الكمية 196','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('739', '19', '45080', '','0');
UPDATE accountstree SET name = 'البضاعة (بضاعة أول المدة)', customName = 'البضاعة (بضاعة أول المدة)', parent = '6', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '6112947.5', theOrder = '0', layingOrder = '121',reportid = '0' WHERE id = '19';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('739', '7', '45080', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '6964018.3', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
UPDATE product SET productName = '820', productDescription = '', productCatId = '1', productBuyPrice = '230.00', productSellAllPrice = '235.00', productSellUnitPrice = '265.00', productSellHalfPrice = '245.00', productDate = '2021-12-06', conditions = '0', userId = '1', limitamount = '0', parcode = '00590',type ='0', expireDate = '0' , dailyentryId = '739',isService = '0',isOptic = '0',lastbuyprice = '230',lastbuyprice_withDiscount = '230',meanbuyprice = '230',meanbuyprice_withDiscount = '230' , productbuypricereal = '230' , buypricereal_precentage = '0' , buytotal_precentage = '2.17' , buyhalf_precentage = '6.52' , buypart_precentage = '15.22',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '590';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 15:57:29";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 19:27:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-06 19:27:29', '1', '', '102.46.57.147', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 15:57:44";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 19:27:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 19:27:44', '1', '', '102.46.57.147', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 16:15:39";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 19:45:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 19:45:39', '1', '', '102.46.57.147', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 16:16:36";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 19:46:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 19:46:36', '1', 'add', '102.46.57.147', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '160', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1468';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '1', '160', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '160', '1', '2021-12-06','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 16:16:38";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 19:46:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-06 19:46:38', '1', 'show', '102.46.57.147', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 16:18:19";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 19:48:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-06 19:48:19', '1', '', '102.46.57.147', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 16:19:25";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 19:49:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 19:49:25', '1', '', '102.46.57.147', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 16:33:54";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 20:03:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 20:03:54', '1', 'add', '102.46.57.147', '', '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(74,1,6,590,24,'2021-12-06',1,0, '' ,0,0,0,0,0,'2021-12-06 20:03:54',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '172', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1583';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-06', 1, 590, 0, 0
                    , 230.00, -24, 0, 0, 1, '2021-12-06 20:03:54')
                ON DUPLICATE KEY UPDATE buyprice = 230.00,
                        buyQuantity =buyQuantity+-24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-06 20:03:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "24*2021-12-06*230.00," WHERE transferproductid = 1028;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '1', '24', '1', '1028', 'تحويل منتجات من المخزن', 'storemovementController.php', '196.00', '172', '1', '2021-12-06','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('590', '6', '24', '1', '2021-12-06');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-06', 6, 590, 0, 0
                    , 230.00, 24, 0, 0, 1, '2021-12-06 20:03:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-06 20:03:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '6', '24', '0', '1028', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '24', '1', '2021-12-06','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 16:33:54";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 20:03:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 20:03:54', '1', 'editshow', '102.46.57.147', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 16:34:10";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 20:04:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 20:04:10', '1', '', '102.46.57.147', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 16:34:37";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 20:04:37", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 20:04:37', '1', 'add', '102.46.57.147', '', '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(75,1,3,590,32,'2021-12-06',1,0, '' ,0,0,0,0,0,'2021-12-06 20:04:37',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '140', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1583';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-06', 1, 590, 0, 0
                    , 230.00, -32, 0, 0, 1, '2021-12-06 20:04:37')
                ON DUPLICATE KEY UPDATE buyprice = 230.00,
                        buyQuantity =buyQuantity+-32, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-06 20:04:37' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "32*2021-12-06*230.00," WHERE transferproductid = 1029;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '1', '32', '1', '1029', 'تحويل منتجات من المخزن', 'storemovementController.php', '172.00', '140', '1', '2021-12-06','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('590', '3', '32', '1', '2021-12-06');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-06', 3, 590, 0, 0
                    , 230.00, 32, 0, 0, 1, '2021-12-06 20:04:37')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+32, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-06 20:04:37' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '3', '32', '0', '1029', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '32', '1', '2021-12-06','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 16:34:38";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 20:04:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 20:04:38', '1', 'editshow', '102.46.57.147', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 16:34:50";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 20:04:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 20:04:51', '1', '', '102.46.57.147', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 16:35:10";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 20:05:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 20:05:10', '1', 'add', '102.46.57.147', '', '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(76,1,5,590,32,'2021-12-06',1,0, '' ,0,0,0,0,0,'2021-12-06 20:05:10',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '108', userid = '1', storedetaildate = '2021-12-06' WHERE storedetailid = '1583';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-06', 1, 590, 0, 0
                    , 230.00, -32, 0, 0, 1, '2021-12-06 20:05:10')
                ON DUPLICATE KEY UPDATE buyprice = 230.00,
                        buyQuantity =buyQuantity+-32, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-06 20:05:10' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "32*2021-12-06*230.00," WHERE transferproductid = 1030;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '1', '32', '1', '1030', 'تحويل منتجات من المخزن', 'storemovementController.php', '140.00', '108', '1', '2021-12-06','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('590', '5', '32', '1', '2021-12-06');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-06', 5, 590, 0, 0
                    , 230.00, 32, 0, 0, 1, '2021-12-06 20:05:10')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+32, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-06 20:05:10' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '5', '32', '0', '1030', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '32', '1', '2021-12-06','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 16:35:10";
UPDATE user SET loginip = "102.46.57.147", lastactivetime = "2021-12-06 20:05:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-06 20:05:10', '1', 'editshow', '102.46.57.147', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 1;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 17:14:47";

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061ae08c1bdcd2
-- ----------------------------------------------------------------------------------------------------

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-06 14:57:37', '061ae08c1bdcd2', '1', '0.00', '0', '0', '1', '1020', '1020', '1020', '0', '8', '2021-12-06 20:44:48', '', null, '0', 'نقدي', '8', '0', '3', '0', 'نقدي', '4' ,'0','','','','','-1','0','0','0','0','0','1020','0','','0','0','1020','0','0','0','0','0','0','0','0','');
ROLLBACK;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061ae08c1bdcd2 and sellbillId = 0 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 17:14:48";
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-06 17:14:53";
UPDATE user SET loginip = "197.41.18.32", lastactivetime = "2021-12-06 20:44:53", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-06 20:44:53', '3', '', '197.41.18.32', '', '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-06 17:14:53";
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-06 17:14:56";
UPDATE user SET loginip = "197.41.18.32", lastactivetime = "2021-12-06 20:44:56", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 20:44:56', '3', 'addsellBill', '197.41.18.32', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 17:14:59";
UPDATE user SET loginip = "197.41.18.32", lastactivetime = "2021-12-06 20:44:59", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 20:44:59', '3', '', '197.41.18.32', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 17:15:02";
UPDATE user SET loginip = "197.41.18.32", lastactivetime = "2021-12-06 20:45:02", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 20:45:02', '3', 'addsellBill', '197.41.18.32', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 17:15:38";
UPDATE user SET loginip = "197.41.18.32", lastactivetime = "2021-12-06 20:45:38", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 20:45:38', '3', 'addAndRetuen', '197.41.18.32', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061ae5a2e39a19
-- ----------------------------------------------------------------------------------------------------

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-06 20:45:02', '061ae5a2e39a19', '1', '0.00', '0', '0', '1', '1020', '1020', '1020', '0', '8', '2021-12-06 20:45:38', '', '3', '0', 'نقدي', '8', '0', '3', '0', 'نقدي', '4' ,'0','','','','','-1','0','0','0','0','0','1020','0','','0','0','1020','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '3' 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','اضافة فاتورة مبيعات','171', '0', '2021-12-06 20:45:38', '3', 'sellbillController.php', 'اضافة فاتورة مبيعات', '1020', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1310;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('220','00515', '171', '1', '515', '1', '260', '260', '0', '', '1', '2021-12-06 20:45:38', '515', '0.00', '0', '8','0','','','0','0','0','0','0','0','1','0','','1310-1,');
UPDATE sellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where sellbilldetailid = 387;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (515, '2021-12-06', 260, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+260, sellCostBuyPrice =sellCostBuyPrice+220
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+220, sellCostMeanBuyPrice = sellCostMeanBuyPrice+220
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+220, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+220
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (8, '2021-12-06', 260, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+260, sellCostBuyPrice =sellCostBuyPrice+220
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+220, sellCostMeanBuyPrice = sellCostMeanBuyPrice+220
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+220, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+220
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '28', userid = '3', storedetaildate = '2021-12-06 20:45:38' WHERE storedetailid = '1205';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('515', '8', '1', '1', '171', 'اضافة فاتورة مبيعات', 'sellbillController.php', '29.00', '28', '3', '2021-12-06 20:45:38','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1290;
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','00465', '171', '1', '465', '1', '250', '250', '0', '', '1', '2021-12-06 20:45:38', '465', '0.00', '0', '8','0','','','0','0','0','0','0','0','1','0','','1290-1,');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 210.00, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 210.00
                where sellbilldetailid = 388;
 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-06', 250, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+250, sellCostBuyPrice =sellCostBuyPrice+210
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+210, sellCostMeanBuyPrice = sellCostMeanBuyPrice+210
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+210, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+210
                            , 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 (8, '2021-12-06', 250, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+250, sellCostBuyPrice =sellCostBuyPrice+210
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+210, sellCostMeanBuyPrice = sellCostMeanBuyPrice+210
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+210, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+210
                            , 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 = '11', userid = '3', storedetaildate = '2021-12-06 20:45:38' WHERE storedetailid = '1195';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('465', '8', '1', '1', '171', 'اضافة فاتورة مبيعات', 'sellbillController.php', '12.00', '11', '3', '2021-12-06 20:45:38','0','0');
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', '171', '1', '563', '1', '250', '250', '0', '', '1', '2021-12-06 20:45:38', '563', '0.00', '0', '8','0','','','0','0','0','0','0','0','1','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 210.00, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 210.00
                where sellbilldetailid = 389;
 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-06', 250, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+250, sellCostBuyPrice =sellCostBuyPrice+210
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+210, sellCostMeanBuyPrice = sellCostMeanBuyPrice+210
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+210, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+210
                            , 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 (8, '2021-12-06', 250, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+250, sellCostBuyPrice =sellCostBuyPrice+210
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+210, sellCostMeanBuyPrice = sellCostMeanBuyPrice+210
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+210, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+210
                            , 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 = '3', storedetaildate = '2021-12-06 20:45:38' WHERE storedetailid = '1487';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '8', '1', '1', '171', 'اضافة فاتورة مبيعات', 'sellbillController.php', '17.00', '16', '3', '2021-12-06 20:45:38','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1918;
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 ('225','00562', '171', '1', '562', '1', '260', '260', '0', '', '1', '2021-12-06 20:45:38', '562', '0.00', '0', '8','0','','','0','0','0','0','0','0','1','0','','1918-1,');
UPDATE sellbilldetail SET  lastbuyprice = 225.00 , meanbuyprice = 225.00, lastbuyprice_withDiscount = 225.00, meanbuyprice_withDiscount = 225.00
                where sellbilldetailid = 390;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (562, '2021-12-06', 260, 225, 225
                    , 225, 225, 225, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+260, sellCostBuyPrice =sellCostBuyPrice+225
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+225, sellCostMeanBuyPrice = sellCostMeanBuyPrice+225
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+225, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+225
                            , 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 (8, '2021-12-06', 260, 225, 225
                    , 225, 225, 225, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+260, sellCostBuyPrice =sellCostBuyPrice+225
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+225, sellCostMeanBuyPrice = sellCostMeanBuyPrice+225
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+225, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+225
                            , 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 = '24', userid = '3', storedetaildate = '2021-12-06 20:45:38' WHERE storedetailid = '1518';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '8', '1', '1', '171', 'اضافة فاتورة مبيعات', 'sellbillController.php', '25.00', '24', '3', '2021-12-06 20:45:38','0','0');
UPDATE save SET  savecurrentvalue = '4740',  userid = '3' WHERE saveid = '8';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('3720.00','1020', '0', '8', 'اضافة فاتورة مبيعات', '171', '4740', '2021-12-06 20:45:38', '3',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-06', 1020, 865, 865
                    , 865, 865, 865, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1020, sellCostBuyPrice =sellCostBuyPrice+865
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+865, sellCostMeanBuyPrice = sellCostMeanBuyPrice+865
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+865, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+865
                            , 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-06', 1020, 865, 865
                    , 865, 865, 865, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1020, sellCostBuyPrice =sellCostBuyPrice+865
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+865, sellCostMeanBuyPrice = sellCostMeanBuyPrice+865
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+865, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+865
                            , 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, 1020, 865, 865
                    , 865, 865, 865, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+1020, netSellCostBuyPrice = netSellCostBuyPrice+865
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+865
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+865
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+865
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+865
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061ae5a2e39a19 and sellbillId = 171 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 17:15:39";
UPDATE user SET loginip = "197.41.18.32", lastactivetime = "2021-12-06 20:45:39", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 20:45:39', '3', 'addsellBill', '197.41.18.32', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 17:16:51";
UPDATE user SET loginip = "197.41.18.32", lastactivetime = "2021-12-06 20:46:51", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 20:46:51', '3', 'addAndRetuen', '197.41.18.32', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061ae5a5372825
-- ----------------------------------------------------------------------------------------------------

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-06 20:45:39', '061ae5a5372825', '1', '0.00', '0', '0', '1', '725', '725', '725', '0', '8', '2021-12-06 20:46:51', '', '3', '0', 'نقدي', '8', '0', '3', '0', 'نقدي', '3' ,'0','','','','','-1','0','0','0','0','0','725','0','','0','0','725','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '3' 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','اضافة فاتورة مبيعات','172', '0', '2021-12-06 20:46:51', '3', 'sellbillController.php', 'اضافة فاتورة مبيعات', '725', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+2 where id = 1920;
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', '172', '1', '565', '2', '240.00', '480', '0', '', '2', '2021-12-06 20:46:51', '565', '0.00', '0', '8','0','','','0','0','0','0','0','0','2','0','','1920-2,');
UPDATE sellbilldetail SET  lastbuyprice = 150.00 , meanbuyprice = 150.00, lastbuyprice_withDiscount = 150.00, meanbuyprice_withDiscount = 150.00
                where sellbilldetailid = 391;
 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-06', 480, 300, 300
                    , 300, 300, 300, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 2, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+480, sellCostBuyPrice =sellCostBuyPrice+300
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+300, sellCostMeanBuyPrice = sellCostMeanBuyPrice+300
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+300, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+300
                            , 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 (8, '2021-12-06', 480, 300, 300
                    , 300, 300, 300, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+480, sellCostBuyPrice =sellCostBuyPrice+300
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+300, sellCostMeanBuyPrice = sellCostMeanBuyPrice+300
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+300, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+300
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '13', userid = '3', storedetaildate = '2021-12-06 20:46:51' WHERE storedetailid = '1519';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '8', '2', '1', '172', 'اضافة فاتورة مبيعات', 'sellbillController.php', '15.00', '13', '3', '2021-12-06 20:46:51','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2006;
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', '172', '1', '589', '1', '245', '245', '0', '', '2', '2021-12-06 20:46:51', '589', '0.00', '0', '8','0','','','0','0','0','0','0','0','2','0','','2006-1,');
UPDATE sellbilldetail SET  lastbuyprice = 230.00 , meanbuyprice = 230.00, lastbuyprice_withDiscount = 230.00, meanbuyprice_withDiscount = 230.00
                where sellbilldetailid = 392;
 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-06', 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 (8, '2021-12-06', 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 = '26', userid = '3', storedetaildate = '2021-12-06 20:46:51' WHERE storedetailid = '1572';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '8', '1', '1', '172', 'اضافة فاتورة مبيعات', 'sellbillController.php', '27.00', '26', '3', '2021-12-06 20:46:51','0','0');
UPDATE save SET  savecurrentvalue = '5465',  userid = '3' WHERE saveid = '8';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('4740.00','725', '0', '8', 'اضافة فاتورة مبيعات', '172', '5465', '2021-12-06 20:46:51', '3',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-06', 725, 530, 530
                    , 530, 530, 530, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+725, sellCostBuyPrice =sellCostBuyPrice+530
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+530, sellCostMeanBuyPrice = sellCostMeanBuyPrice+530
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+530, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+530
                            , 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-06', 725, 530, 530
                    , 530, 530, 530, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+725, sellCostBuyPrice =sellCostBuyPrice+530
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+530, sellCostMeanBuyPrice = sellCostMeanBuyPrice+530
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+530, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+530
                            , 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, 725, 530, 530
                    , 530, 530, 530, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+725, netSellCostBuyPrice = netSellCostBuyPrice+530
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+530
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+530
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+530
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+530
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061ae5a5372825 and sellbillId = 172 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 17:16:52";
UPDATE user SET loginip = "197.41.18.32", lastactivetime = "2021-12-06 20:46:52", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 20:46:52', '3', 'addsellBill', '197.41.18.32', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 17:17:06";
UPDATE user SET loginip = "197.41.18.32", lastactivetime = "2021-12-06 20:47:06", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 20:47:06', '3', 'addAndRetuen', '197.41.18.32', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061ae5a9c41d15
-- ----------------------------------------------------------------------------------------------------

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-06 20:46:52', '061ae5a9c41d15', '1', '0.00', '0', '0', '1', '290', '290', '290', '0', '8', '2021-12-06 20:47:06', '', '3', '0', 'نقدي', '8', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','290','0','','0','0','290','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '3' 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','اضافة فاتورة مبيعات','173', '0', '2021-12-06 20:47:06', '3', 'sellbillController.php', 'اضافة فاتورة مبيعات', '290', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1264;
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 ('280','00388', '173', '1', '388', '1', '290.00', '290', '0', '', '0', '2021-12-06 20:47:06', '388', '0.00', '0', '8','0','','','0','0','0','0','0','0','0','0','','1264-1,');
UPDATE sellbilldetail SET  lastbuyprice = 280.00 , meanbuyprice = 280.00, lastbuyprice_withDiscount = 280.00, meanbuyprice_withDiscount = 280.00
                where sellbilldetailid = 393;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (388, '2021-12-06', 290, 280, 280
                    , 280, 280, 280, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+290, sellCostBuyPrice =sellCostBuyPrice+280
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+280, sellCostMeanBuyPrice = sellCostMeanBuyPrice+280
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+280, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+280
                            , 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 (8, '2021-12-06', 290, 280, 280
                    , 280, 280, 280, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+290, sellCostBuyPrice =sellCostBuyPrice+280
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+280, sellCostMeanBuyPrice = sellCostMeanBuyPrice+280
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+280, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+280
                            , 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 = '14', userid = '3', storedetaildate = '2021-12-06 20:47:06' WHERE storedetailid = '1182';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('388', '8', '1', '1', '173', 'اضافة فاتورة مبيعات', 'sellbillController.php', '15.00', '14', '3', '2021-12-06 20:47:06','0','0');
UPDATE save SET  savecurrentvalue = '5755',  userid = '3' WHERE saveid = '8';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('5465.00','290', '0', '8', 'اضافة فاتورة مبيعات', '173', '5755', '2021-12-06 20:47:06', '3',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-06', 290, 280, 280
                    , 280, 280, 280, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+290, sellCostBuyPrice =sellCostBuyPrice+280
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+280, sellCostMeanBuyPrice = sellCostMeanBuyPrice+280
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+280, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+280
                            , 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-06', 290, 280, 280
                    , 280, 280, 280, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+290, sellCostBuyPrice =sellCostBuyPrice+280
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+280, sellCostMeanBuyPrice = sellCostMeanBuyPrice+280
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+280, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+280
                            , 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, 290, 280, 280
                    , 280, 280, 280, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+290, netSellCostBuyPrice = netSellCostBuyPrice+280
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+280
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+280
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+280
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+280
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061ae5a9c41d15 and sellbillId = 173 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 17:17:06";
UPDATE user SET loginip = "197.41.18.32", lastactivetime = "2021-12-06 20:47:06", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 20:47:06', '3', 'addsellBill', '197.41.18.32', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 17:17:09";
UPDATE user SET loginip = "197.41.18.32", lastactivetime = "2021-12-06 20:47:09", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-06 20:47:09', '3', '', '197.41.18.32', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-06 17:19:30";
UPDATE user SET loginip = "197.41.18.32", lastactivetime = "2021-12-06 20:49:30", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-06 20:49:30', '3', 'addsellBill', '197.41.18.32', '', 'DESKTOP');
