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 < "2022-02-12 05:15:09";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 08:45:09", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 08:45:09', '4', '', '102.47.174.252', '', '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 = '2022-02-12',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 < "2022-02-12 05:15:10";
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 < "2022-02-12 05:15:12";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 08:45:12", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 08:45:12', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 05:15:38";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 08:45:38", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 08:45:38', '4', 'addAndRetuen', '102.47.174.252', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 062075778bdf3c
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 08:45:12', '062075778bdf3c', '1', '0.00', '0', '30', '1', '430', '400', '400', '0', '7', '2022-02-12 08:45:38', '', '4', '0', 'نقدي', '7', '0', '3', '0', 'نقدي', '2' ,'0','','','','','-1','0','0','0','0','0','400','0','','0','0','400','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','اضافة فاتورة مبيعات','994', '0', '2022-02-12 08:45:38', '4', 'sellbillController.php', 'اضافة فاتورة مبيعات', '400', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2824;
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', '994', '1', '565', '1', '230', '230', '0', '', '0', '2022-02-12 08:45:38', '565', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','2824-1,');
UPDATE sellbilldetail SET  lastbuyprice = 150.00 , meanbuyprice = 150.00, lastbuyprice_withDiscount = 150.00, meanbuyprice_withDiscount = 150.00
                where sellbilldetailid = 2017;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (565, '2022-02-12', 213.953488372, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+213.953488372, 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, '2022-02-12', 213.953488372, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+213.953488372, 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 = '20', userid = '4', storedetaildate = '2022-02-12 08:45:38' WHERE storedetailid = '1514';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '7', '1', '1', '994', 'اضافة فاتورة مبيعات', 'sellbillController.php', '21.00', '20', '4', '2022-02-12 08: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 ('200','00450', '994', '1', '450', '1', '200', '200', '0', '', '0', '2022-02-12 08:45:38', '450', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 280.00 , meanbuyprice = 233.75, lastbuyprice_withDiscount = 280.00, meanbuyprice_withDiscount = 233.75
                where sellbilldetailid = 2018;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (450, '2022-02-12', 186.046511628, 200, 280
                    , 233.75, 280, 233.75, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+186.046511628, sellCostBuyPrice =sellCostBuyPrice+200
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+280, sellCostMeanBuyPrice = sellCostMeanBuyPrice+233.75
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+280, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+233.75
                            , 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, '2022-02-12', 186.046511628, 200, 280
                    , 233.75, 280, 233.75, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+186.046511628, sellCostBuyPrice =sellCostBuyPrice+200
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+280, sellCostMeanBuyPrice = sellCostMeanBuyPrice+233.75
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+280, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+233.75
                            , 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 = '4', storedetaildate = '2022-02-12 08:45:38' WHERE storedetailid = '1303';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('450', '7', '1', '1', '994', 'اضافة فاتورة مبيعات', 'sellbillController.php', '15.00', '14', '4', '2022-02-12 08:45:38','0','0');
UPDATE save SET  savecurrentvalue = '1885',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1485.00','400', '0', '7', 'اضافة فاتورة مبيعات', '994', '1885', '2022-02-12 08:45:38', '4',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 400, 350, 430
                    , 383.75, 430, 383.75, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+400, sellCostBuyPrice =sellCostBuyPrice+350
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+430, sellCostMeanBuyPrice = sellCostMeanBuyPrice+383.75
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+430, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+383.75
                            , 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, '2022-02-12', 400, 350, 430
                    , 383.75, 430, 383.75, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+400, sellCostBuyPrice =sellCostBuyPrice+350
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+430, sellCostMeanBuyPrice = sellCostMeanBuyPrice+383.75
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+430, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+383.75
                            , 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, 400, 350, 430
                    , 383.75, 430, 383.75, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+400, netSellCostBuyPrice = netSellCostBuyPrice+350
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+430
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+383.75
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+430
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+383.75
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 062075778bdf3c and sellbillId = 994 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 05:15:38";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 08:45:38", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 08:45:38', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 05:15:46";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 08:45:46", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 08:45:46', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 05:15:59";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 08:45:59", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 08:45:59', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 06:22:58";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 09:52:58", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 09:52:58', '4', 'addAndRetuen', '102.47.174.252', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 0620757a797d39
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 08:45:59', '0620757a797d39', '1', '0.00', '0', '60', '1', '810', '750', '750', '0', '7', '2022-02-12 09:52:58', '', '4', '0', 'نقدي', '7', '0', '3', '0', 'نقدي', '4' ,'0','','','','','-1','0','0','0','0','0','750','0','','0','0','750','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','اضافة فاتورة مبيعات','995', '0', '2022-02-12 09:52:58', '4', 'sellbillController.php', 'اضافة فاتورة مبيعات', '750', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+3 where id = 1914;
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 ('190','00463', '995', '1', '463', '3', '200', '600', '0', '', '0', '2022-02-12 09:52:58', '463', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','1914-3,');
UPDATE sellbilldetail SET  lastbuyprice = 190.00 , meanbuyprice = 190.00, lastbuyprice_withDiscount = 190.00, meanbuyprice_withDiscount = 190.00
                where sellbilldetailid = 2019;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (463, '2022-02-12', 555.555555556, 570, 570
                    , 570, 570, 570, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 3, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+555.555555556, sellCostBuyPrice =sellCostBuyPrice+570
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+570, sellCostMeanBuyPrice = sellCostMeanBuyPrice+570
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+570, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+570
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+3
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (7, '2022-02-12', 555.555555556, 570, 570
                    , 570, 570, 570, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+555.555555556, sellCostBuyPrice =sellCostBuyPrice+570
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+570, sellCostMeanBuyPrice = sellCostMeanBuyPrice+570
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+570, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+570
                            , 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 = '59', userid = '4', storedetaildate = '2022-02-12 09:52:58' WHERE storedetailid = '1516';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('463', '7', '3', '1', '995', 'اضافة فاتورة مبيعات', 'sellbillController.php', '62.00', '59', '4', '2022-02-12 09:52:58','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1514;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('195','00126', '995', '1', '126', '1', '210', '210', '0', '', '0', '2022-02-12 09:52:58', '126', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','1514-1,');
UPDATE sellbilldetail SET  lastbuyprice = 195.00 , meanbuyprice = 195.00, lastbuyprice_withDiscount = 195.00, meanbuyprice_withDiscount = 195.00
                where sellbilldetailid = 2020;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (126, '2022-02-12', 194.444444444, 195, 195
                    , 195, 195, 195, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+194.444444444, sellCostBuyPrice =sellCostBuyPrice+195
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+195, sellCostMeanBuyPrice = sellCostMeanBuyPrice+195
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+195, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+195
                            , 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, '2022-02-12', 194.444444444, 195, 195
                    , 195, 195, 195, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+194.444444444, sellCostBuyPrice =sellCostBuyPrice+195
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+195, sellCostMeanBuyPrice = sellCostMeanBuyPrice+195
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+195, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+195
                            , 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 = '2022-02-12 09:52:58' WHERE storedetailid = '1308';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('126', '7', '1', '1', '995', 'اضافة فاتورة مبيعات', 'sellbillController.php', '4.00', '3', '4', '2022-02-12 09:52:58','0','0');
UPDATE save SET  savecurrentvalue = '2635',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1885.00','750', '0', '7', 'اضافة فاتورة مبيعات', '995', '2635', '2022-02-12 09:52:58', '4',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 750, 765, 765
                    , 765, 765, 765, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+750, sellCostBuyPrice =sellCostBuyPrice+765
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+765, sellCostMeanBuyPrice = sellCostMeanBuyPrice+765
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+765, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+765
                            , 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, '2022-02-12', 750, 765, 765
                    , 765, 765, 765, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+750, sellCostBuyPrice =sellCostBuyPrice+765
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+765, sellCostMeanBuyPrice = sellCostMeanBuyPrice+765
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+765, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+765
                            , 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, 750, 765, 765
                    , 765, 765, 765, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+750, netSellCostBuyPrice = netSellCostBuyPrice+765
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+765
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+765
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+765
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+765
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 0620757a797d39 and sellbillId = 995 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 06:22:58";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 09:52:58", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 09:52:58', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 06:33:27";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:03:27", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 10:03:27', '4', 'addAndRetuen', '102.47.174.252', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207675b0ed08
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 09:52:59', '06207675b0ed08', '1', '0.00', '0', '0', '1', '230', '230', '230', '0', '7', '2022-02-12 10:03:27', '', '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','اضافة فاتورة مبيعات','996', '0', '2022-02-12 10:03:27', '4', 'sellbillController.php', 'اضافة فاتورة مبيعات', '230', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2824;
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', '996', '1', '565', '1', '230.00', '230', '0', '', '0', '2022-02-12 10:03:27', '565', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','2824-1,');
UPDATE sellbilldetail SET  lastbuyprice = 150.00 , meanbuyprice = 150.00, lastbuyprice_withDiscount = 150.00, meanbuyprice_withDiscount = 150.00
                where sellbilldetailid = 2021;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (565, '2022-02-12', 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, '2022-02-12', 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 = '19', userid = '4', storedetaildate = '2022-02-12 10:03:28' WHERE storedetailid = '1514';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '7', '1', '1', '996', 'اضافة فاتورة مبيعات', 'sellbillController.php', '20.00', '19', '4', '2022-02-12 10:03:28','0','0');
UPDATE save SET  savecurrentvalue = '2865',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2635.00','230', '0', '7', 'اضافة فاتورة مبيعات', '996', '2865', '2022-02-12 10:03:28', '4',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 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, '2022-02-12', 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 06207675b0ed08 and sellbillId = 996 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 06:33:28";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:03:28", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 10:03:28', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 06:33:35";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:03:35", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 10:03:35', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 06:34:24";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:04:24", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 10:04:24', '4', 'addAndRetuen', '102.47.174.252', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 0620769d76b6cb
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 10:03:35', '0620769d76b6cb', '1', '0.00', '0', '10', '1', '245', '235', '-235', '0', '7', '2022-02-12 10:04:24', '', '4', '0', 'نقدي','7', '0', '5', '0', 'نقدي', '1', '0', '', '','','','-1','0','0','0','','0','-235','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','اضافة فاتورة مردوات مبيعات','299', '0', '2022-02-12 10:04:24', '4', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '235', '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 ('225.00', '00253', '299', '1', '253', '1', '245', '245', '0', '', '1', '0', '253', '0.00', '0','7','0','','','0','0','0','0','0','1');
UPDATE returnsellbilldetail SET  lastbuyprice = 225.00 , meanbuyprice = 189.85, lastbuyprice_withDiscount = 225.00, meanbuyprice_withDiscount = 189.85
                where returnsellbilldetailid = 453;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (253, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 255, 225, 225, 189.85
                    , 225, 189.85, 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+255, returnSellCostBuyPrice = returnSellCostBuyPrice+225, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+225
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+189.85, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+225
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+189.85
                            , 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, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 255, 225, 225, 189.85
                    , 225, 189.85, 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+255, returnSellCostBuyPrice = returnSellCostBuyPrice+225, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+225
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+189.85, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+225
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+189.85
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '10', userid = '4', storedetaildate = '2022-02-12 10:04:24' WHERE storedetailid = '1556';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('253', '7', '1', '0', '299', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '9.00', '10', '4', '2022-02-12 10:04:24','0','0');
UPDATE save SET  savecurrentvalue = '2630',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2865.00','235', '1', '7', 'اضافة فاتورة مردوات مبيعات', '299', '2630', '2022-02-12 10:04:24', '4',  'returnsellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 235, 225, 225, 189.85
                    , 225, 189.85, 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+235, returnSellCostBuyPrice = returnSellCostBuyPrice+225, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+225
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+189.85, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+225
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+189.85
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 235, 225, 225, 189.85
                    , 225, 189.85, 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+235, returnSellCostBuyPrice = returnSellCostBuyPrice+225, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+225
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+189.85, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+225
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+189.85
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -235, -225, -225
                    , -189.85, -225, -189.85, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-235, netSellCostBuyPrice = netSellCostBuyPrice+-225
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-225
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-189.85
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-225
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-189.85
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 0620769d76b6cb and sellbillId = 299 and returnsellbillId = 299
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 06:34:25";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:04:25", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 10:04:25', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 06:39:31";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:09:31", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 10:09:31', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 06:39:38";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:09:38", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 10:09:38', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 07:01:55";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:31:55", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 10:31:55', '4', 'addAndRetuen', '102.47.174.252', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 062076b42889d0
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 10:09:38', '062076b42889d0', '1', '0.00', '0', '0', '1', '905', '905', '905', '0', '7', '2022-02-12 10:31:55', '', '4', '0', 'نقدي', '7', '0', '3', '0', 'نقدي', '4' ,'0','','','','','-1','0','0','0','0','0','905','0','','0','0','905','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','اضافة فاتورة مبيعات','997', '0', '2022-02-12 10:31:55', '4', 'sellbillController.php', 'اضافة فاتورة مبيعات', '905', '0', null, '0', null, null,'', '0','1','1','0','1');
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('200','00450', '997', '1', '450', '1', '200', '200', '0', '', '0', '2022-02-12 10:31:55', '450', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 280.00 , meanbuyprice = 233.75, lastbuyprice_withDiscount = 280.00, meanbuyprice_withDiscount = 233.75
                where sellbilldetailid = 2022;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (450, '2022-02-12', 200, 200, 280
                    , 233.75, 280, 233.75, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+200, sellCostBuyPrice =sellCostBuyPrice+200
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+280, sellCostMeanBuyPrice = sellCostMeanBuyPrice+233.75
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+280, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+233.75
                            , 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, '2022-02-12', 200, 200, 280
                    , 233.75, 280, 233.75, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+200, sellCostBuyPrice =sellCostBuyPrice+200
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+280, sellCostMeanBuyPrice = sellCostMeanBuyPrice+233.75
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+280, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+233.75
                            , 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 = '4', storedetaildate = '2022-02-12 10:31:55' WHERE storedetailid = '1303';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('450', '7', '1', '1', '997', 'اضافة فاتورة مبيعات', 'sellbillController.php', '14.00', '13', '4', '2022-02-12 10:31:55','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1520;
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 ('205','00214', '997', '1', '214', '1', '250', '250', '0', '', '0', '2022-02-12 10:31:55', '214', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','1520-1,');
UPDATE sellbilldetail SET  lastbuyprice = 205.00 , meanbuyprice = 205.00, lastbuyprice_withDiscount = 205.00, meanbuyprice_withDiscount = 205.00
                where sellbilldetailid = 2023;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (214, '2022-02-12', 250, 205, 205
                    , 205, 205, 205, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+250, sellCostBuyPrice =sellCostBuyPrice+205
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+205, sellCostMeanBuyPrice = sellCostMeanBuyPrice+205
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+205, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+205
                            , 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, '2022-02-12', 250, 205, 205
                    , 205, 205, 205, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+250, sellCostBuyPrice =sellCostBuyPrice+205
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+205, sellCostMeanBuyPrice = sellCostMeanBuyPrice+205
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+205, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+205
                            , 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 = '42', userid = '4', storedetaildate = '2022-02-12 10:31:55' WHERE storedetailid = '1311';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('214', '7', '1', '1', '997', 'اضافة فاتورة مبيعات', 'sellbillController.php', '43.00', '42', '4', '2022-02-12 10:31:55','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2826;
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','00560', '997', '1', '560', '1', '225', '225', '0', '', '0', '2022-02-12 10:31:55', '560', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','2826-1,');
UPDATE sellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where sellbilldetailid = 2024;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (560, '2022-02-12', 225, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+225, sellCostBuyPrice =sellCostBuyPrice+220
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+220, sellCostMeanBuyPrice = sellCostMeanBuyPrice+220
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+220, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+220
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (7, '2022-02-12', 225, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+225, sellCostBuyPrice =sellCostBuyPrice+220
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+220, sellCostMeanBuyPrice = sellCostMeanBuyPrice+220
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+220, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+220
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '12', userid = '4', storedetaildate = '2022-02-12 10:31:55' WHERE storedetailid = '1931';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('560', '7', '1', '1', '997', 'اضافة فاتورة مبيعات', 'sellbillController.php', '13.00', '12', '4', '2022-02-12 10:31:55','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2824;
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', '997', '1', '565', '1', '230', '230', '0', '', '0', '2022-02-12 10:31:55', '565', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','2824-1,');
UPDATE sellbilldetail SET  lastbuyprice = 150.00 , meanbuyprice = 150.00, lastbuyprice_withDiscount = 150.00, meanbuyprice_withDiscount = 150.00
                where sellbilldetailid = 2025;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (565, '2022-02-12', 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, '2022-02-12', 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 = '2022-02-12 10:31:55' WHERE storedetailid = '1514';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '7', '1', '1', '997', 'اضافة فاتورة مبيعات', 'sellbillController.php', '19.00', '18', '4', '2022-02-12 10:31:55','0','0');
UPDATE save SET  savecurrentvalue = '3535',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2630.00','905', '0', '7', 'اضافة فاتورة مبيعات', '997', '3535', '2022-02-12 10:31:55', '4',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 905, 775, 855
                    , 808.75, 855, 808.75, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+905, sellCostBuyPrice =sellCostBuyPrice+775
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+855, sellCostMeanBuyPrice = sellCostMeanBuyPrice+808.75
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+855, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+808.75
                            , 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, '2022-02-12', 905, 775, 855
                    , 808.75, 855, 808.75, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+905, sellCostBuyPrice =sellCostBuyPrice+775
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+855, sellCostMeanBuyPrice = sellCostMeanBuyPrice+808.75
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+855, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+808.75
                            , 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, 905, 775, 855
                    , 808.75, 855, 808.75, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+905, netSellCostBuyPrice = netSellCostBuyPrice+775
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+855
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+808.75
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+855
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+808.75
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 062076b42889d0 and sellbillId = 997 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 07:01:56";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:31:56", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 10:31:56', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 07:02:55";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:32:55", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 10:32:55', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 07:02:57";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:32:57", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 10:32:57', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 07:23:35";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:53:35", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 10:53:35', '4', 'addAndRetuen', '102.47.174.252', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 0620770b971f7d
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 10:32:57', '0620770b971f7d', '1', '0.00', '0', '10', '1', '225', '215', '215', '0', '7', '2022-02-12 10:53:36', '', '4', '0', 'نقدي', '7', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','215','0','','0','0','215','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','اضافة فاتورة مبيعات','998', '0', '2022-02-12 10:53:36', '4', 'sellbillController.php', 'اضافة فاتورة مبيعات', '215', '0', null, '0', null, null,'', '0','1','1','0','1');
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','00617', '998', '1', '617', '1', '225', '225', '0', '', '0', '2022-02-12 10:53:36', '617', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where sellbilldetailid = 2026;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (617, '2022-02-12', 215, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+215, 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 (7, '2022-02-12', 215, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+215, 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 = '7', userid = '4', storedetaildate = '2022-02-12 10:53:36' WHERE storedetailid = '1889';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('617', '7', '1', '1', '998', 'اضافة فاتورة مبيعات', 'sellbillController.php', '8.00', '7', '4', '2022-02-12 10:53:36','0','0');
UPDATE save SET  savecurrentvalue = '3750',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('3535.00','215', '0', '7', 'اضافة فاتورة مبيعات', '998', '3750', '2022-02-12 10:53:36', '4',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 215, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+215, 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;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2022-02-12', 215, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+215, 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;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, 215, 220, 220
                    , 220, 220, 220, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+215, netSellCostBuyPrice = netSellCostBuyPrice+220
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+220
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+220
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+220
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+220
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 0620770b971f7d and sellbillId = 998 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 07:23:36";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:53:36", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 10:53:36', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 07:27:03";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:57:03", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 10:57:03', '4', 'addAndRetuen', '102.47.174.252', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207759078ae3
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 10:53:36', '06207759078ae3', '1', '0.00', '0', '0', '1', '215', '215', '215', '0', '7', '2022-02-12 10:57:03', '', '4', '0', 'نقدي', '7', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','215','0','','0','0','215','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','اضافة فاتورة مبيعات','999', '0', '2022-02-12 10:57:03', '4', 'sellbillController.php', 'اضافة فاتورة مبيعات', '215', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2702;
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 ('170','00474', '999', '1', '474', '1', '215.00', '215', '0', '', '0', '2022-02-12 10:57:03', '474', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','2702-1,');
UPDATE sellbilldetail SET  lastbuyprice = 170.00 , meanbuyprice = 170.00, lastbuyprice_withDiscount = 170.00, meanbuyprice_withDiscount = 170.00
                where sellbilldetailid = 2027;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (474, '2022-02-12', 215, 170, 170
                    , 170, 170, 170, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+215, sellCostBuyPrice =sellCostBuyPrice+170
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+170, sellCostMeanBuyPrice = sellCostMeanBuyPrice+170
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+170, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+170
                            , 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, '2022-02-12', 215, 170, 170
                    , 170, 170, 170, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+215, sellCostBuyPrice =sellCostBuyPrice+170
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+170, sellCostMeanBuyPrice = sellCostMeanBuyPrice+170
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+170, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+170
                            , 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 = '32', userid = '4', storedetaildate = '2022-02-12 10:57:03' WHERE storedetailid = '1776';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('474', '7', '1', '1', '999', 'اضافة فاتورة مبيعات', 'sellbillController.php', '33.00', '32', '4', '2022-02-12 10:57:03','0','0');
UPDATE save SET  savecurrentvalue = '3965',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('3750.00','215', '0', '7', 'اضافة فاتورة مبيعات', '999', '3965', '2022-02-12 10:57:03', '4',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 215, 170, 170
                    , 170, 170, 170, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+215, sellCostBuyPrice =sellCostBuyPrice+170
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+170, sellCostMeanBuyPrice = sellCostMeanBuyPrice+170
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+170, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+170
                            , 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, '2022-02-12', 215, 170, 170
                    , 170, 170, 170, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+215, sellCostBuyPrice =sellCostBuyPrice+170
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+170, sellCostMeanBuyPrice = sellCostMeanBuyPrice+170
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+170, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+170
                            , 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, 215, 170, 170
                    , 170, 170, 170, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+215, netSellCostBuyPrice = netSellCostBuyPrice+170
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+170
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+170
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+170
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+170
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207759078ae3 and sellbillId = 999 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 07:27:04";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:57:04", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 10:57:04', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 07:27:09";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:57:09", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 10:57:09', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 07:27:11";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 10:57:11", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 10:57:11', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 07:59:31";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:29:31", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 11:29:31', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 07:59:35";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:29:35", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 11:29:35', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 4;
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 < "2022-02-12 08:00:55";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:30:55", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 11:30:55', '1', '', '102.47.174.252', '', '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 < "2022-02-12 08:00:55";
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 < "2022-02-12 08:03:37";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:33:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 11:33:38', '1', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:07:33";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:37:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 11:37:33', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '31', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1931';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('560', '7', '19', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '12.00', '31', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:07:35";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:37:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 11:37:35', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:08:09";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:38:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 11:38:09', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1555';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '7', '19', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '19.00', '0', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:08:11";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:38:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 11:38:11', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:12:33";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:42:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 11:42:33', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:12:45";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:42:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 11:42:45', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:12:54";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:42:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 11:42:54', '1', 'editsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:13:16";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:43:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 11:43:16', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:13:41";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:43:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 11:43:41', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:13:45";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:43:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 11:43:45', '1', 'showDetail', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:14:01";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:44:01", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 11:44:01', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:14:33";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:44:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 11:44:33', '1', 'showDetail', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:15:17";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:45:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 11:45:17', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:15:21";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:45:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 11:45:22', '1', 'showDetail', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:15:38";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:45:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 11:45:39', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:17:52";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:47:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 11:47:52', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '14', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1303';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('450', '7', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '13.00', '14', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:17:54";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:47:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 11:47:54', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:21:24";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:51:24", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 11:51:24', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '45', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1311';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('214', '7', '3', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '42.00', '45', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:21:26";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:51:26", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 11:51:26', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:27:12";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:57:12", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 11:57:12', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1312';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('129', '7', '85', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '85.00', '0', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:27:13";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:57:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 11:57:14', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:27:32";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:57:32", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 11:57:32', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '89', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1517';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('466', '7', '85', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '4.00', '89', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:27:33";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 11:57:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 11:57:33', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:31:27";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:01:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:01:27', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1307';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('125', '7', '29', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '29.00', '0', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:31:29";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:01:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:01:29', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:32:34";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:02:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:02:34', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '88', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1516';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('463', '7', '29', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '59.00', '88', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:32:35";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:02:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:02:36', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:33:32";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:03:32", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2022-02-12 12:03:32', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:33:35";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:03:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2022-02-12 12:03:35', '1', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:34:04";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:04:04", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2022-02-12 12:04:04', '1', 'add', '102.47.174.252', '', 'DESKTOP');
INSERT INTO impotencetreatmentsuppliersave (typesimpotencetreatmentid, saveid, supplierid, impotencetreatmentsuppliersavetype, impotencetreatmentsuppliersavebefore, impotencetreatmentsuppliersavetamount, impotencetreatmentsuppliersaveafter, impotencetreatmentsuppliersavecomment, conditions, impotencetreatmentsuppliersavedate, userid, tablename) VALUES ('-1', '6', '-1', '0', '2805.00', '60', '2865', '', '0', '2022-02-12 12:04:04', '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', '', '60', '1', ' خصم معالجة عجز  / ', '131', '-60', '2022-02-12', '1', 'supplierPayedDeptController.php', '', '0','6', '0','1','1','60','1');
UPDATE supplier SET  suppliercurrentDebt = '-60', userid = '1', supplierdate = '2022-02-12'   WHERE supplierid = '-1';
UPDATE supplierdebtchange SET supplierid = '-1', supplierdebtchangebefore = '0.00', supplierdebtchangeamount = '60.00', supplierdebtchangetype = '1', processname = ' خصم معالجة عجز  / ', supplierdebtchangemodelid = '131', supplierdebtchangeafter = '-60.00', supplierdebtchangedate = '2022-02-12 00:00:00', userid = '1', tablename = 'supplierPayedDeptController.php', comment = '', dailyentryid = '0',saveid = '6',currencyId='1',conversionFactor='1',payedInCurrency='60',saveConversionFactor='1' WHERE supplierdebtchangeid = '131';
UPDATE save SET  savecurrentvalue = '2865',  userid = '1' WHERE saveid = '6';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2805.00','60', '0', '6', 'تسوية خزنة بالإضافة', '-1', '2865', '2022-02-12 12:04:04', '1',  'settlementsaveController.php','0','');
UPDATE savedaily SET  savedailymodelid = '1899' WHERE savedailyid = '1899';
BEGIN;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '60', '60', '2022-02-12', '1', '0', '0', '2022-02-12 12:04:04','اضافة معالجة عجز ( بالاضافة )','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1390', '140', '60', '','0');
UPDATE accountstree SET name = 'خزينة محل كفر الدوار', customName = 'خزينة محل كفر الدوار', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-41215', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '140';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1390', '27', '60', '','0');
UPDATE accountstree SET name = 'معالجة عجز خزنة', customName = 'معالجة عجز خزنة', parent = '3', itemtype = '0', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-06-15', itemtype2 = '1', theValue = '44496', theOrder = '0', layingOrder = '35',reportid = '1' WHERE id = '27';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:34:05";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:04:05", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2022-02-12 12:04:05', '1', 'sucess', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:34:07";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:04:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('settlementsaveController.php', '2022-02-12 12:04:07', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:36:22";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:06:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:06:22', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '46', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1306';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('124', '7', '16', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '30.00', '46', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:36:24";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:06:24", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:06:24', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:37:14";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:07:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:07:14', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1787';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('391', '7', '16', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '16.00', '0', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:37:16";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:07:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:07:16', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:55:51";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:25:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:25:52', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '41', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1306';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('124', '7', '5', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '46.00', '41', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 08:55:53";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:25:53", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:25:53', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:06:22";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:36:23", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:36:23', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '17', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1296';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('387', '7', '4', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '13.00', '17', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:06:24";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:36:24", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:36:24', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:06:42";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:36:42", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:36:42', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '23', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1295';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('386', '7', '1', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '24.00', '23', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:06:44";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:36:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:36:44', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:07:01";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:37:01", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:37:01', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '25', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1294';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('385', '7', '3', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '28.00', '25', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:07:03";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:37:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:37:03', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:09:21";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:39:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:39:21', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '16', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1293';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('384', '7', '3', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '13.00', '16', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:09:23";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:39:23", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:39:23', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:10:17";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:40:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:40:17', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '10', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1269';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('121', '7', '10', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '10', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:10:19";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:40:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:40:19', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:10:40";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:40:40", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:40:40', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '41', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1291';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('382', '7', '9', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '50.00', '41', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:10:42";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:40:42", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:40:42', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:12:51";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:42:51", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:42:51', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '46', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1291';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('382', '7', '5', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '41.00', '46', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:12:53";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:42:53", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:42:53', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:14:46";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:44:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:44:46', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '24', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1295';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('386', '7', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '23.00', '24', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:14:47";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:44:48", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:44:48', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:15:08";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:45:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:45:08', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '26', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1294';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('385', '7', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '25.00', '26', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:15:10";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:45:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:45:10', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:16:13";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:46:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:46:13', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '21', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1292';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('383', '7', '5', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '16.00', '21', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:16:14";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:46:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:46:15', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:17:10";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:47:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:47:10', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '2', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1769';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('612', '7', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '1.00', '2', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:17:12";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:47:12", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:47:12', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:24:36";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:54:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:54:36', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '23', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1297';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('513', '7', '2', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '21.00', '23', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:24:38";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 12:54:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 12:54:38', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:30:34";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:00:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:00:34', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '38', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1515';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '7', '16', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '22.00', '38', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:30:36";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:00:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:00:36', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:33:58";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:03:58", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:03:58', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '32', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1302';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('518', '7', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '31.00', '32', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:34:00";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:04:00", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:04:00', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:40:30";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:10:30", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2022-02-12 13:10:30', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:53:29";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:23:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:23:29', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '6', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1300';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('516', '7', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '5.00', '6', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 09:53:31";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:23:31", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:23:31', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:03:58";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:33:58", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:33:58', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '3', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1838';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('251', '7', '3', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '3', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:04:01";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:34:01", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:34:01', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:04:16";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:34:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:34:16', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1582';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('403', '7', '3', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '3.00', '0', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:04:17";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:34:18", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:34:18', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:06:18";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:36:18", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:36:18', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '4', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1525';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('567', '7', '4', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '4', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:06:20";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:36:20", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:36:20', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:08:48";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:38:48", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:38:48', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '21', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1310';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('540', '7', '6', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '15.00', '21', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:08:50";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:38:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:38:50', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:09:10";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:39:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:39:10', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1745';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('255', '7', '6', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '6.00', '0', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:09:11";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:39:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:39:11', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:10:54";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:40:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:40:54', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '18', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1310';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('540', '7', '3', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '21.00', '18', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:10:55";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:40:55", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:40:56', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:11:54";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:41:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:41:54', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '14', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1556';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('253', '7', '4', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '10.00', '14', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:11:56";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 13:41:56", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 13:41:56', '1', 'show', '102.47.174.252', '', '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 < "2022-02-12 10:23:20";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 13:53:20", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 13:53:20', '5', '', '154.180.139.62', '', '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 < "2022-02-12 10:23: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 < "2022-02-12 10:23:23";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 13:53:23", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 13:53:23', '5', '', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:23:31";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 13:53:31", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 13:53:31', '5', '', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:23:53";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 13:53:53", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 13:53:53', '5', 'add', '154.180.139.62', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('2', 'مرتب رائد', '', '300', '2022-02-12', '5', '0','-1','3','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '260',  userid = '5' WHERE saveid = '3';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('560.00','300', '1', '3', 'إضافة مصروف', '344', '260', '2022-02-12 13:53:53', '5',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '300', '300', '2022-02-12', '5', '0', '0', '2022-02-12 13:53:53','اضافة اسم مصروف( مرتب رائد )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1391', '145', '300', '','0');
UPDATE accountstree SET name = 'مرتبات', customName = 'مرتبات', parent = '14', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-08', itemtype2 = '0', theValue = '58680', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '145';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1391', '137', '300', '','0');
UPDATE accountstree SET name = 'خزينة رائد', customName = 'خزينة رائد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-56650', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '137';
UPDATE expenses SET expensestypeid = '2', expensesname = 'مرتب رائد', expensesdetails = '', expensesValue = '300.00', expensesdate = '2022-02-12', userid = '5', conditions = '0',saveid = '3' , dailyentryid = '1391', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '344';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:23:53";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 13:53:53", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 13:53:53', '5', 'sucess', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:23:55";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 13:53:55", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 13:53:55', '5', 'show', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:23:56";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 13:53:56", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 13:53:56', '5', '', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 5;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:39:01";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:09:01", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:09:01', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '35', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1752';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('370', '7', '24', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '11.00', '35', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:39:03";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:09:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:09:03', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:41:31";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:11:31", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:11:31', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:41:33";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:11:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:11:33', '1', 'show', '102.47.174.252', '', '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 < "2022-02-12 10:42:03";
UPDATE user SET loginip = "154.176.240.45", lastactivetime = "2022-02-12 14:12:03", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 14:12:03', '8', '', '154.176.240.45', '', '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 < "2022-02-12 10:42: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 < "2022-02-12 10:43:05";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:13:05", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:13:05', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '3', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1553';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '7', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '2.00', '3', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:43:07";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:13:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:13:07', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:43:42";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:13:42", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:13:42', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '5', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1581';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('127', '7', '1', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '6.00', '5', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:43:44";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:13:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:13:44', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:44:05";
UPDATE user SET loginip = "154.176.240.45", lastactivetime = "2022-02-12 14:14:05", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 14:14:05', '8', 'addsellBill', '154.176.240.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:44:05";
UPDATE user SET loginip = "154.176.240.45", lastactivetime = "2022-02-12 14:14:05", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 14:14:06', '8', 'addsellBill', '154.176.240.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:44:06";
UPDATE user SET loginip = "154.176.240.45", lastactivetime = "2022-02-12 14:14:06", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 14:14:06', '8', 'addsellBill', '154.176.240.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:45:15";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:15:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:15:15', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '11', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1779';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('455', '7', '2', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '9.00', '11', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:45:17";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:15:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:15:17', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:49:55";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:19:55", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:19:55', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '3', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1771';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('610', '7', '2', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '1.00', '3', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:49:57";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:19:57", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:19:57', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:59:31";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:29:31", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:29:31', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '27', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1752';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('370', '7', '8', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '35.00', '27', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 10:59:32";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:29:32", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:29:32', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:01:07";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:31:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:31:07', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '14', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1752';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('370', '7', '13', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '27.00', '14', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:01:09";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:31:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:31:09', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:05:22";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:35:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:35:22', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '45', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1680';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('85', '7', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '44.00', '45', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:05:23";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:35:23", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:35:23', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:07:08";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:37:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:37:08', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1816';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('278', '7', '1', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '1.00', '0', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:07:10";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:37:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:37:10', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:07:26";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:37:26", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:37:26', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '36', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1673';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('537', '7', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '35.00', '36', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:07:28";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 14:37:28", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 14:37:28', '1', 'show', '102.47.174.252', '', '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 < "2022-02-12 11:13:55";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 14:43:55", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 14:43:55', '5', '', '154.180.139.62', '', '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 < "2022-02-12 11:13:55";
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 < "2022-02-12 11:14:02";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 14:44:02", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 14:44:02', '5', 'addsellBill', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:15:35";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 14:45:35", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 14:45:35', '5', 'addAndRetuen', '154.180.139.62', '', 'DESKTOP');
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207ab9248b69
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(96,@clientdebt,@clientname);
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2022-02-12 14:44:02', '06207ab9248b69', '96', '95.00', '515', '0', '1', '1120', '1120', '700', '420', '3', '2022-02-12 14:45:35', '', '5', '0', 'ام اسلام المعموره اسكندريه', '3', '1', '3', '0', 'ام اسلام المعموره اسكندريه', '5' ,'0','','','','','-1','0','0','0','0','0','1120','0','','0','0','700','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '515', userid = '5' WHERE clientid = '96';
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 ('96','95.00','420','0','اضافة فاتورة مبيعات','1000', '515', '2022-02-12 14:45:35', '5', 'sellbillController.php', 'اضافة فاتورة مبيعات', '1120', '0', null, '0', null, null,'', '0','1','1','420','1');
UPDATE client SET  inUse = 0 where clientid = 96;
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+4 where id = 2810;
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','00617', '1000', '1', '617', '4', '225.00', '900', '0', '', '0', '2022-02-12 14:45:35', '617', '0.00', '0', '3','0','','','0','0','0','0','0','0','0','0','','2810-4,');
UPDATE sellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where sellbilldetailid = 2028;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (617, '2022-02-12', 900, 880, 880
                    , 880, 880, 880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 4, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+900, sellCostBuyPrice =sellCostBuyPrice+880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+880, sellCostMeanBuyPrice = sellCostMeanBuyPrice+880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+880
                            , 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 (3, '2022-02-12', 900, 880, 880
                    , 880, 880, 880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+900, sellCostBuyPrice =sellCostBuyPrice+880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+880, sellCostMeanBuyPrice = sellCostMeanBuyPrice+880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+880
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '16', userid = '5', storedetaildate = '2022-02-12 14:45:35' WHERE storedetailid = '1884';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('617', '3', '4', '1', '1000', 'اضافة فاتورة مبيعات', 'sellbillController.php', '20.00', '16', '5', '2022-02-12 14:45:35','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1962;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('210','00127', '1000', '1', '127', '1', '220', '220', '0', '', '0', '2022-02-12 14:45:35', '127', '0.00', '0', '3','0','','','0','0','0','0','0','0','0','0','','1962-1,');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 1148.55, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 1148.55
                where sellbilldetailid = 2029;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (127, '2022-02-12', 220, 210, 210
                    , 1148.55, 210, 1148.55, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+220, sellCostBuyPrice =sellCostBuyPrice+210
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+210, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1148.55
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+210, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1148.55
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2022-02-12', 220, 210, 210
                    , 1148.55, 210, 1148.55, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+220, sellCostBuyPrice =sellCostBuyPrice+210
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+210, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1148.55
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+210, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1148.55
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '9', userid = '5', storedetaildate = '2022-02-12 14:45:35' WHERE storedetailid = '1546';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('127', '3', '1', '1', '1000', 'اضافة فاتورة مبيعات', 'sellbillController.php', '10.00', '9', '5', '2022-02-12 14:45:35','0','0');
UPDATE save SET  savecurrentvalue = '960',  userid = '5' WHERE saveid = '3';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('260.00','700', '0', '3', 'اضافة فاتورة مبيعات', '1000', '960', '2022-02-12 14:45:35', '5',  'sellbillController.php','96','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 1120, 1090, 1090
                    , 2028.55, 1090, 2028.55, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1120, sellCostBuyPrice =sellCostBuyPrice+1090
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1090, sellCostMeanBuyPrice = sellCostMeanBuyPrice+2028.55
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1090, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+2028.55
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (96, '2022-02-12', 1120, 1090, 1090
                    , 2028.55, 1090, 2028.55, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1120, sellCostBuyPrice =sellCostBuyPrice+1090
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1090, sellCostMeanBuyPrice = sellCostMeanBuyPrice+2028.55
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1090, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+2028.55
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, 1120, 1090, 1090
                    , 2028.55, 1090, 2028.55, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+1120, netSellCostBuyPrice = netSellCostBuyPrice+1090
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+1090
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+2028.55
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+1090
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+2028.55
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207ab9248b69 and sellbillId = 1000 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:15:35";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 14:45:35", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 14:45:35', '5', 'addsellBill', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:15:49";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 14:45:49", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 14:45:49', '5', 'addsellBill', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:16:37";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 14:46:37", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 14:46:37', '5', 'addAndRetuen', '154.180.139.62', '', 'DESKTOP');
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207abfd369b6
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(96,@clientdebt,@clientname);
INSERT INTO returnsellbill (returnsellbilldate, returnsellbillserial, returnsellbillclientid, returnsellbilltotaldeptbefor, returnsellbilltotaldeptafter, returnsellbilldiscount, returnsellbilldiscounttype, returnsellbilltotalbill, returnsellbillaftertotalbill, returnsellbilltotalpayed, returnsellbillfinalbill, returnsellbillstoreid, returnsellbillsysdate,comment, userid, conditions, returnsellbillclientname, returnsellbillsaveid, returnsellbildirectpayment, billnameid, sellerid, tempclientName, returnsellQuantity,tax, carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,delbyuserid,billReservation,billReservationDate,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal) VALUES ('2022-02-12 14:45:49', '06207abfd369b6', '96', '515.00', '295', '0', '1', '220', '220', '0', '-220', '3', '2022-02-12 14:46:37', '', '5', '0', 'ام اسلام المعموره اسكندريه','3', '1', '5', '0', 'ام اسلام المعموره اسكندريه', '1', '0', '', '','','','-1','0','0','0','','0','0','0','0','0','0','0','0');
UPDATE client SET  clientdebt = '295', userid = '5' WHERE clientid = '96';
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 ('96','515.00','220','1','اضافة فاتورة مردوات مبيعات','300', '295', '2022-02-12 14:46:37', '5', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '220', '0', null, '0', null, null,'', '0','1','1','220','1');
UPDATE client SET  inUse = 0 where clientid = 96;
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 ('195.00', '00556', '300', '1', '556', '1', '220.00', '220', '0', '', '2', '0', '556', '0.00', '0','3','0','','','0','0','0','0','0','2');
UPDATE returnsellbilldetail SET  lastbuyprice = 195.00 , meanbuyprice = 195.00, lastbuyprice_withDiscount = 195.00, meanbuyprice_withDiscount = 195.00
                where returnsellbilldetailid = 454;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (556, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 220, 195, 195, 195
                    , 195, 195, 0, 0, 1)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+220, returnSellCostBuyPrice = returnSellCostBuyPrice+195, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+195
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+195, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+195
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+195
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+0
                        , netQuantityRet = netQuantityRet+1;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 220, 195, 195, 195
                    , 195, 195, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+220, returnSellCostBuyPrice = returnSellCostBuyPrice+195, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+195
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+195, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+195
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+195
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '13', userid = '5', storedetaildate = '2022-02-12 14:46:37' WHERE storedetailid = '1503';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('556', '3', '1', '0', '300', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '12.00', '13', '5', '2022-02-12 14:46:37','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 220, 195, 195, 195
                    , 195, 195, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+220, returnSellCostBuyPrice = returnSellCostBuyPrice+195, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+195
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+195, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+195
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+195
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (96, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 220, 195, 195, 195
                    , 195, 195, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+220, returnSellCostBuyPrice = returnSellCostBuyPrice+195, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+195
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+195, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+195
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+195
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -220, -195, -195
                    , -195, -195, -195, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-220, netSellCostBuyPrice = netSellCostBuyPrice+-195
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-195
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-195
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-195
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-195
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207abfd369b6 and sellbillId = 300 and returnsellbillId = 300
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:16:37";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 14:46:37", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 14:46:37', '5', 'addsellBill', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:16:44";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 14:46:44", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 14:46:44', '5', '', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 5;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:45:33";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:15:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:15:33', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '24', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1671';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('38', '7', '7', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '17.00', '24', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:45:35";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:15:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:15:35', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:48:22";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:18:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:18:22', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1289';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('523', '7', '9', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '9.00', '0', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:48:23";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:18:24", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:18:24', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:51:10";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:21:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:21:10', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1285';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('447', '7', '60', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '60.00', '0', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:51:11";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:21:12", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:21:12', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:51:36";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:21:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:21:36', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1275';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('303', '7', '10', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '10.00', '0', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:51:38";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:21:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:21:38', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:52:02";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:22:02", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:22:02', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1274';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('313', '7', '15', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '15.00', '0', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:52:04";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:22:04", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:22:04', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:57:05";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:27:05", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:27:05', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '50', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1258';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('90', '7', '2', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '48.00', '50', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 11:57:07";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:27:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:27:07', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:05:00";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:35:00", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:35:00', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '70', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1273';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('311', '7', '35', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '105.00', '70', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:05:02";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:35:02", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:35:02', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:19:11";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:49:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:49:11', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1772';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('587', '7', '18', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '18.00', '0', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:19:13";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:49:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:49:13', '1', 'show', '102.47.174.252', '', '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 < "2022-02-12 12:24:39";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 15:54:39", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 15:54:39', '5', '', '154.180.139.62', '', '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 < "2022-02-12 12:24:39";
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 < "2022-02-12 12:24:41";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 15:54:41", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 15:54:41', '5', 'addsellBill', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 5;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:26:13";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:56:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:56:13', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1774';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('571', '7', '27', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '27.00', '0', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:26:15";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 15:56:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 15:56:15', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:32:00";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:02:00", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 16:02:00', '1', 'add', '102.47.174.252', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '4', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1746';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('402', '7', '2', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '6.00', '4', '1', '2022-02-12','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:32:02";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:02:02", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 16:02:02', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 1;
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:33:09";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:03:09", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 16:03:09', '4', '', '102.47.174.252', '', '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 < "2022-02-12 12:33:09";
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 < "2022-02-12 12:33:14";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:03:14", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 16:03:15', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:33:21";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:03:21", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 16:03:21', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:33:35";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:03:35", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:03:35', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:34:12";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:04:12", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:04:12', '4', 'add', '102.47.174.252', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('2', 'العميد', '', '800', '2022-02-12', '4', '0','-1','7','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '3165',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('3965.00','800', '1', '7', 'إضافة مصروف', '345', '3165', '2022-02-12 16:04:12', '4',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '800', '800', '2022-02-12', '4', '0', '0', '2022-02-12 16:04:12','اضافة اسم مصروف( العميد )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1392', '145', '800', '','0');
UPDATE accountstree SET name = 'مرتبات', customName = 'مرتبات', parent = '14', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-08', itemtype2 = '0', theValue = '59480', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '145';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1392', '141', '800', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-102560', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE expenses SET expensestypeid = '2', expensesname = 'العميد', expensesdetails = '', expensesValue = '800.00', expensesdate = '2022-02-12', userid = '4', conditions = '0',saveid = '7' , dailyentryid = '1392', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '345';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:34:12";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:04:12", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:04:12', '4', 'sucess', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:34:13";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:04:13", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:04:14', '4', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:34:14";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:04:14", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:04:14', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:34:32";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:04:32", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:04:32', '4', 'add', '102.47.174.252', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('2', 'العجوز', '', '800', '2022-02-12', '4', '0','-1','7','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '2365',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('3165.00','800', '1', '7', 'إضافة مصروف', '346', '2365', '2022-02-12 16:04:32', '4',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '800', '800', '2022-02-12', '4', '0', '0', '2022-02-12 16:04:32','اضافة اسم مصروف( العجوز )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1393', '145', '800', '','0');
UPDATE accountstree SET name = 'مرتبات', customName = 'مرتبات', parent = '14', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-08', itemtype2 = '0', theValue = '60280', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '145';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1393', '141', '800', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-103360', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE expenses SET expensestypeid = '2', expensesname = 'العجوز', expensesdetails = '', expensesValue = '800.00', expensesdate = '2022-02-12', userid = '4', conditions = '0',saveid = '7' , dailyentryid = '1393', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '346';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:34:32";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:04:33", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:04:33', '4', 'sucess', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:34:34";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:04:34", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:04:34', '4', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:35:02";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:05:02", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 16:05:02', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:35:14";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:05:14", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:05:14', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:36:21";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:06:21", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:06:21', '4', 'add', '102.47.174.252', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('7', 'ضيافه', '', '20', '2022-02-12', '4', '0','-1','7','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '2345',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2365.00','20', '1', '7', 'إضافة مصروف', '347', '2345', '2022-02-12 16:06:21', '4',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '20', '20', '2022-02-12', '4', '0', '0', '2022-02-12 16:06:21','اضافة اسم مصروف( ضيافه )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1394', '150', '20', '','0');
UPDATE accountstree SET name = 'ضيافة', customName = 'ضيافة', parent = '14', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-08', itemtype2 = '0', theValue = '510', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '150';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1394', '141', '20', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-103380', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE expenses SET expensestypeid = '7', expensesname = 'ضيافه', expensesdetails = '', expensesValue = '20.00', expensesdate = '2022-02-12', userid = '4', conditions = '0',saveid = '7' , dailyentryid = '1394', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '347';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:36:21";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:06:21", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:06:21', '4', 'sucess', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:36:23";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:06:23", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:06:23', '4', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:36:25";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:06:25", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 16:06:25', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:37:14";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:07:14", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:07:14', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:37:16";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:07:16", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2022-02-12 16:07:16', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:37:23";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:07:23", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:07:23', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:37:57";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:07:57", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:07:57', '4', 'add', '102.47.174.252', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('-1', 'اكياس شمعه', '', '1500', '2022-02-12', '4', '0','-1','7','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '845',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2345.00','1500', '1', '7', 'إضافة مصروف', '348', '845', '2022-02-12 16:07:57', '4',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '1500', '1500', '2022-02-12', '4', '0', '0', '2022-02-12 16:07:57','اضافة اسم مصروف( اكياس شمعه )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1395', '160', '1500', '','0');
UPDATE accountstree SET name = '', customName = '', parent = '10', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-12-01', itemtype2 = '1', theValue = '-77175', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '160';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1395', '141', '1500', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-104880', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE expenses SET expensestypeid = '-1', expensesname = 'اكياس شمعه', expensesdetails = '', expensesValue = '1500.00', expensesdate = '2022-02-12', userid = '4', conditions = '0',saveid = '7' , dailyentryid = '1395', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '348';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:37:57";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:07:57", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:07:57', '4', 'sucess', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:37:59";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:07:59", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 16:07:59', '4', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:38:00";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:08:00", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 16:08:00', '4', '', '102.47.174.252', '', '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 < "2022-02-12 12:39:02";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:09:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 16:09:03', '1', '', '102.47.174.252', '', '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 < "2022-02-12 12:39:03";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:39:11";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:09:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2022-02-12 16:09:11', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:39:44";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:09:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2022-02-12 16:09:45', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:39:47";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:09:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2022-02-12 16:09:47', '1', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:40:11";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:10:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2022-02-12 16:10:11', '1', 'add', '102.47.174.252', '', 'DESKTOP');
BEGIN;
INSERT INTO transfermoney (saveidfrom, saveidto, transfermoneyvalue, transfermoneydate, userid, conditions, dailyentryid , comment) VALUES ('7','9', '845.00', '2022-02-12', '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 ('845.00','845.00', '1', '7', 'تحويل امول الى الخزنة  [ الشيخ وليد ] ', '49', '0', '2022-02-12 16:10:11', '1',  'transfermoneyController.php','0','');
UPDATE save SET  savecurrentvalue = '130545',  userid = '1' WHERE saveid = '9';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('129700.00','845.00', '0', '9', 'تحويل امول من الخزنة  [ خزينة محل العميد ] ', '49', '130545', '2022-02-12 16:10:11', '1',  'transfermoneyController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '845', '845', '2022-02-12', '1', '0', '0', '2022-02-12 16:10:11','اضافة تحويل من خزينة محل العميد الى الشيخ وليد','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1396', '156', '845.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 = '130545', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '156';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1396', '141', '845.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 = '-105725', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE transfermoney SET saveidfrom = '7', saveidto = '9', transfermoneyvalue = '845.00', transfermoneydate = '2022-02-12', userid = '1', conditions = '0' , dailyentryid = '1396' , comment = '' WHERE transfermoneyid = '49';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:40:16";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:10:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2022-02-12 16:10:16', '1', 'sucess', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:40:18";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:10:18", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2022-02-12 16:10:18', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:40:21";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:10:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2022-02-12 16:10:21', '1', 'show', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 1;
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:42:40";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 16:12:40", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 16:12:40', '7', '', '197.192.232.226', '', '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 < "2022-02-12 12:42:40";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:42:42";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 16:12:42", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 16:12:43', '7', 'addsellBill', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:43:06";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 16:13:06", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 16:13:06', '7', 'addAndRetuen', '197.192.232.226', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207c05b1a901
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 16:12:43', '06207c05b1a901', '1', '0.00', '0', '0', '1', '230', '230', '230', '0', '5', '2022-02-12 16:13:07', '', '7', '0', 'نقدي', '5', '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 = '7' WHERE clientid = '1';
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('1','0.00','0','0','اضافة فاتورة مبيعات','1001', '0', '2022-02-12 16:13:07', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '230', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1970;
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', '1001', '1', '563', '1', '230.00', '230', '0', '', '2', '2022-02-12 16:13:07', '563', '0.00', '0', '5','0','','','0','0','0','0','0','0','2','0','','1970-1,');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 210.00, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 210.00
                where sellbilldetailid = 2030;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (563, '2022-02-12', 230, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+230, 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 (5, '2022-02-12', 230, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+230, 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 = '3', userid = '7', storedetaildate = '2022-02-12 16:13:07' WHERE storedetailid = '1550';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '5', '1', '1', '1001', 'اضافة فاتورة مبيعات', 'sellbillController.php', '4.00', '3', '7', '2022-02-12 16:13:07','0','0');
UPDATE save SET  savecurrentvalue = '1135',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('905.00','230', '0', '5', 'اضافة فاتورة مبيعات', '1001', '1135', '2022-02-12 16:13:07', '7',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 230, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+230, 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;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2022-02-12', 230, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+230, 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;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, 230, 210, 210
                    , 210, 210, 210, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+230, netSellCostBuyPrice = netSellCostBuyPrice+210
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+210
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+210
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+210
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+210
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207c05b1a901 and sellbillId = 1001 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:43:07";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 16:13:07", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 16:13:07', '7', 'addsellBill', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:43:15";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 16:13:15", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 16:13:15', '7', '', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 7;
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 < "2022-02-12 12:57:17";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 16:27:17", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 16:27:17', '7', '', '197.192.232.226', '', '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 < "2022-02-12 12:57:17";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:57:28";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 16:27:28", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 16:27:28', '7', 'addsellBill', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:58:04";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 16:28:04", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 16:28:04', '7', 'addAndRetuen', '197.192.232.226', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207c3d0c8faa
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 16:27:28', '06207c3d0c8faa', '1', '0.00', '0', '20', '1', '195', '175', '175', '0', '5', '2022-02-12 16:28:04', '', '7', '0', 'نقدي', '5', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','175','0','','0','0','175','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '7' WHERE clientid = '1';
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('1','0.00','0','0','اضافة فاتورة مبيعات','1002', '0', '2022-02-12 16:28:04', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '175', '0', null, '0', null, null,'', '0','1','1','0','1');
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','00310', '1002', '1', '310', '1', '195', '195', '0', '', '1', '2022-02-12 16:28:04', '310', '0.00', '0', '5','0','','','0','0','0','0','0','0','1','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 150.00 , meanbuyprice = 150.00, lastbuyprice_withDiscount = 150.00, meanbuyprice_withDiscount = 150.00
                where sellbilldetailid = 2031;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (310, '2022-02-12', 175, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+175, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+150, sellCostMeanBuyPrice = sellCostMeanBuyPrice+150
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+150, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+150
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (5, '2022-02-12', 175, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+175, 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 = '2', userid = '7', storedetaildate = '2022-02-12 16:28:04' WHERE storedetailid = '886';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('310', '5', '1', '1', '1002', 'اضافة فاتورة مبيعات', 'sellbillController.php', '3.00', '2', '7', '2022-02-12 16:28:04','0','0');
UPDATE save SET  savecurrentvalue = '1310',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1135.00','175', '0', '5', 'اضافة فاتورة مبيعات', '1002', '1310', '2022-02-12 16:28:04', '7',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 175, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+175, 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, '2022-02-12', 175, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+175, 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, 175, 150, 150
                    , 150, 150, 150, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+175, netSellCostBuyPrice = netSellCostBuyPrice+150
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+150
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+150
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+150
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+150
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207c3d0c8faa and sellbillId = 1002 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:58:05";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 16:28:05", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 16:28:05', '7', 'addsellBill', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 12:58:12";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 16:28:12", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 16:28:12', '7', '', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 7;
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 < "2022-02-12 13:08:01";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 16:38:01", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 16:38:01', '7', '', '197.192.232.226', '', '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 < "2022-02-12 13:08: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 < "2022-02-12 13:08:05";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 16:38:05", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 16:38:05', '7', 'addsellBill', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:08:49";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 16:38:49", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 16:38:49', '7', 'addAndRetuen', '197.192.232.226', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207c64d6bed1
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 16:38:05', '06207c64d6bed1', '1', '0.00', '0', '0', '1', '675', '675', '675', '0', '5', '2022-02-12 16:38:49', '', '7', '0', 'نقدي', '5', '0', '3', '0', 'نقدي', '3' ,'0','','','','','-1','0','0','0','0','0','675','0','','0','0','675','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '7' WHERE clientid = '1';
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('1','0.00','0','0','اضافة فاتورة مبيعات','1003', '0', '2022-02-12 16:38:49', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '675', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2734;
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','00617', '1003', '1', '617', '1', '225.00', '225', '0', '', '0', '2022-02-12 16:38:49', '617', '0.00', '0', '5','0','','','0','0','0','0','0','0','0','0','','2734-1,');
UPDATE sellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where sellbilldetailid = 2032;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (617, '2022-02-12', 225, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+225, sellCostBuyPrice =sellCostBuyPrice+220
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+220, sellCostMeanBuyPrice = sellCostMeanBuyPrice+220
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+220, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+220
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (5, '2022-02-12', 225, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+225, sellCostBuyPrice =sellCostBuyPrice+220
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+220, sellCostMeanBuyPrice = sellCostMeanBuyPrice+220
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+220, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+220
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '13', userid = '7', storedetaildate = '2022-02-12 16:38:49' WHERE storedetailid = '1887';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('617', '5', '1', '1', '1003', 'اضافة فاتورة مبيعات', 'sellbillController.php', '14.00', '13', '7', '2022-02-12 16:38:49','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2670;
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', '1003', '1', '465', '1', '220.00', '220', '0', '', '0', '2022-02-12 16:38:49', '465', '0.00', '0', '5','0','','','0','0','0','0','0','0','0','0','','2670-1,');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 210.00, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 210.00
                where sellbilldetailid = 2033;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (465, '2022-02-12', 220, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+220, sellCostBuyPrice =sellCostBuyPrice+210
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+210, sellCostMeanBuyPrice = sellCostMeanBuyPrice+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 (5, '2022-02-12', 220, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+220, 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 = '7', storedetaildate = '2022-02-12 16:38:49' WHERE storedetailid = '1885';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('465', '5', '1', '1', '1003', 'اضافة فاتورة مبيعات', 'sellbillController.php', '12.00', '11', '7', '2022-02-12 16:38:49','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1864;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('150','00565', '1003', '1', '565', '1', '230.00', '230', '0', '', '0', '2022-02-12 16:38:49', '565', '0.00', '0', '5','0','','','0','0','0','0','0','0','0','0','','1864-1,');
UPDATE sellbilldetail SET  lastbuyprice = 150.00 , meanbuyprice = 150.00, lastbuyprice_withDiscount = 150.00, meanbuyprice_withDiscount = 150.00
                where sellbilldetailid = 2034;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (565, '2022-02-12', 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 (5, '2022-02-12', 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 = '16', userid = '7', storedetaildate = '2022-02-12 16:38:49' WHERE storedetailid = '1494';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '5', '1', '1', '1003', 'اضافة فاتورة مبيعات', 'sellbillController.php', '17.00', '16', '7', '2022-02-12 16:38:49','0','0');
UPDATE save SET  savecurrentvalue = '1985',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1310.00','675', '0', '5', 'اضافة فاتورة مبيعات', '1003', '1985', '2022-02-12 16:38:49', '7',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 675, 580, 580
                    , 580, 580, 580, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+675, sellCostBuyPrice =sellCostBuyPrice+580
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+580, sellCostMeanBuyPrice = sellCostMeanBuyPrice+580
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+580, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+580
                            , 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, '2022-02-12', 675, 580, 580
                    , 580, 580, 580, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+675, sellCostBuyPrice =sellCostBuyPrice+580
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+580, sellCostMeanBuyPrice = sellCostMeanBuyPrice+580
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+580, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+580
                            , 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, 675, 580, 580
                    , 580, 580, 580, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+675, netSellCostBuyPrice = netSellCostBuyPrice+580
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+580
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+580
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+580
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+580
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207c64d6bed1 and sellbillId = 1003 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:08:50";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 16:38:50", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 16:38:50', '7', 'addsellBill', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:09:01";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 16:39:01", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 16:39:01', '7', '', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 7;
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 < "2022-02-12 13:12:42";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 16:42:42", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 16:42:42', '5', '', '154.180.139.62', '', '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 < "2022-02-12 13:12:42";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:12:45";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 16:42:45", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 16:42:45', '5', '', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 5;
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 < "2022-02-12 13:19:42";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 16:49:42", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 16:49:42', '5', '', '154.180.139.62', '', '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 < "2022-02-12 13:19:42";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE userid = 5;
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 < "2022-02-12 13:28:10";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:58:10", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 16:58:10', '4', '', '102.47.174.252', '', '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 < "2022-02-12 13:28:11";
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 < "2022-02-12 13:28:14";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:58:14", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 16:58:15', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:28:51";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:58:51", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 16:58:51', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:29:15";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:59:15", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 16:59:15', '4', 'addAndRetuen', '102.47.174.252', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207cb2b514d4
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 16:58:51', '06207cb2b514d4', '1', '0.00', '0', '0', '1', '175', '175', '-175', '0', '7', '2022-02-12 16:59:15', '', '4', '0', 'نقدي','7', '0', '5', '0', 'نقدي', '1', '0', '', '','','','-1','0','0','0','','0','-175','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','اضافة فاتورة مردوات مبيعات','301', '0', '2022-02-12 16:59:15', '4', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '175', '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 ('170.00', '00587', '301', '1', '587', '1', '175.00', '175', '0', '', '0', '0', '587', '0.00', '0','7','0','','','0','0','0','0','0','0');
UPDATE returnsellbilldetail SET  lastbuyprice = 170.00 , meanbuyprice = 170.00, lastbuyprice_withDiscount = 170.00, meanbuyprice_withDiscount = 170.00
                where returnsellbilldetailid = 455;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (587, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 175, 170, 170, 170
                    , 170, 170, 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+175, returnSellCostBuyPrice = returnSellCostBuyPrice+170, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+170
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+170, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+170
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+170
                            , 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, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 175, 170, 170, 170
                    , 170, 170, 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+175, returnSellCostBuyPrice = returnSellCostBuyPrice+170, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+170
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+170, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+170
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+170
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '1', userid = '4', storedetaildate = '2022-02-12 16:59:15' WHERE storedetailid = '1772';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('587', '7', '1', '0', '301', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '0.00', '1', '4', '2022-02-12 16:59:15','0','0');
UPDATE save SET  savecurrentvalue = '-175',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('0.00','175', '1', '7', 'اضافة فاتورة مردوات مبيعات', '301', '-175', '2022-02-12 16:59:15', '4',  'returnsellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 175, 170, 170, 170
                    , 170, 170, 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+175, returnSellCostBuyPrice = returnSellCostBuyPrice+170, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+170
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+170, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+170
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+170
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 175, 170, 170, 170
                    , 170, 170, 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+175, returnSellCostBuyPrice = returnSellCostBuyPrice+170, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+170
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+170, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+170
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+170
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -175, -170, -170
                    , -170, -170, -170, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-175, netSellCostBuyPrice = netSellCostBuyPrice+-170
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-170
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-170
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-170
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-170
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207cb2b514d4 and sellbillId = 301 and returnsellbillId = 301
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:29:16";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 16:59:16", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 16:59:16', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:32:38";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 17:02:38", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 17:02:38', '4', 'addAndRetuen', '102.47.174.252', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207cb0719fdb
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 16:58:15', '06207cb0719fdb', '1', '0.00', '0', '0', '1', '630', '630', '630', '0', '7', '2022-02-12 17:02:39', '', '4', '0', 'نقدي', '7', '0', '3', '0', 'نقدي', '3' ,'0','','','','','-1','0','0','0','0','0','630','0','','0','0','630','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','اضافة فاتورة مبيعات','1004', '0', '2022-02-12 17:02:39', '4', 'sellbillController.php', 'اضافة فاتورة مبيعات', '630', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+2 where id = 1914;
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 ('190','00463', '1004', '1', '463', '2', '200.00', '400', '0', '', '0', '2022-02-12 17:02:39', '463', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','1914-2,');
UPDATE sellbilldetail SET  lastbuyprice = 190.00 , meanbuyprice = 190.00, lastbuyprice_withDiscount = 190.00, meanbuyprice_withDiscount = 190.00
                where sellbilldetailid = 2035;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (463, '2022-02-12', 400, 380, 380
                    , 380, 380, 380, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 2, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+400, sellCostBuyPrice =sellCostBuyPrice+380
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+380, sellCostMeanBuyPrice = sellCostMeanBuyPrice+380
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+380, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+380
                            , 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 (7, '2022-02-12', 400, 380, 380
                    , 380, 380, 380, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+400, sellCostBuyPrice =sellCostBuyPrice+380
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+380, sellCostMeanBuyPrice = sellCostMeanBuyPrice+380
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+380, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+380
                            , 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 = '86', userid = '4', storedetaildate = '2022-02-12 17:02:39' WHERE storedetailid = '1516';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('463', '7', '2', '1', '1004', 'اضافة فاتورة مبيعات', 'sellbillController.php', '88.00', '86', '4', '2022-02-12 17:02:39','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2824;
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', '1004', '1', '565', '1', '230.00', '230', '0', '', '0', '2022-02-12 17:02:39', '565', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','2824-1,');
UPDATE sellbilldetail SET  lastbuyprice = 150.00 , meanbuyprice = 150.00, lastbuyprice_withDiscount = 150.00, meanbuyprice_withDiscount = 150.00
                where sellbilldetailid = 2036;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (565, '2022-02-12', 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, '2022-02-12', 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 = '17', userid = '4', storedetaildate = '2022-02-12 17:02:39' WHERE storedetailid = '1514';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '7', '1', '1', '1004', 'اضافة فاتورة مبيعات', 'sellbillController.php', '18.00', '17', '4', '2022-02-12 17:02:39','0','0');
UPDATE save SET  savecurrentvalue = '455',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('-175.00','630', '0', '7', 'اضافة فاتورة مبيعات', '1004', '455', '2022-02-12 17:02:39', '4',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 630, 530, 530
                    , 530, 530, 530, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+630, 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, '2022-02-12', 630, 530, 530
                    , 530, 530, 530, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+630, 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, 630, 530, 530
                    , 530, 530, 530, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+630, netSellCostBuyPrice = netSellCostBuyPrice+530
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+530
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+530
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+530
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+530
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207cb0719fdb and sellbillId = 1004 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:32:39";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 17:02:39", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 17:02:39', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:33:48";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 17:03:48", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 17:03:48', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:33:56";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 17:03:56", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 17:03:56', '4', 'showDetail', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:34:07";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 17:04:07", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 17:04:07', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:34:42";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 17:04:42", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 17:04:42', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:35:02";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 17:05:02", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 17:05:02', '4', 'addsellBill', '102.47.174.252', '', '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 < "2022-02-12 13:44:46";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 17:14:46", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 17:14:46', '4', '', '102.47.174.252', '', '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 < "2022-02-12 13:44: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 < "2022-02-12 13:44:50";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 17:14:50", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 17:14:50', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:44:53";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 17:14:53", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 17:14:53', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:45:42";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 17:15:42", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 17:15:42', '4', 'addAndRetuen', '102.47.174.252', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207ceedad791
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 17:14:53', '06207ceedad791', '1', '0.00', '0', '0', '1', '470', '470', '-470', '0', '7', '2022-02-12 17:15:42', '', '4', '0', 'نقدي','7', '0', '5', '0', 'نقدي', '2', '0', '', '','','','-1','0','0','0','','0','-470','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','اضافة فاتورة مردوات مبيعات','302', '0', '2022-02-12 17:15:42', '4', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '470', '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 ('200.00', '00450', '302', '1', '450', '1', '230', '230', '0', '', '1', '0', '450', '0.00', '0','7','0','','','0','0','0','0','0','1');
UPDATE returnsellbilldetail SET  lastbuyprice = 280.00 , meanbuyprice = 233.75, lastbuyprice_withDiscount = 280.00, meanbuyprice_withDiscount = 233.75
                where returnsellbilldetailid = 456;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (450, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 230, 200, 280, 233.75
                    , 280, 233.75, 0, 0, 1)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+230, returnSellCostBuyPrice = returnSellCostBuyPrice+200, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+280
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+233.75, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+280
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+233.75
                            , 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, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 230, 200, 280, 233.75
                    , 280, 233.75, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+230, returnSellCostBuyPrice = returnSellCostBuyPrice+200, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+280
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+233.75, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+280
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+233.75
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '15', userid = '4', storedetaildate = '2022-02-12 17:15:42' WHERE storedetailid = '1303';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('450', '7', '1', '0', '302', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '14.00', '15', '4', '2022-02-12 17:15:42','0','0');
INSERT INTO returnsellbilldetail (buyprice, parcode, returnsellbillid, returnsellbilldetailcatid, returnsellbilldetailproductid, returnsellbilldetailquantity, returnsellbilldetailprice, returnsellbilldetailtotalprice, conditions, note, pricetype, discountvalue, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,pricetypepro) VALUES ('220.00', '00515', '302', '1', '515', '1', '240', '240', '0', '', '1', '0', '515', '0.00', '0','7','0','','','0','0','0','0','0','1');
UPDATE returnsellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where returnsellbilldetailid = 457;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (515, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 240, 220, 220, 220
                    , 220, 220, 0, 0, 1)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+240, returnSellCostBuyPrice = returnSellCostBuyPrice+220, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+220
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+220, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+220
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+220
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+0
                        , netQuantityRet = netQuantityRet+1;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (7, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 240, 220, 220, 220
                    , 220, 220, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+240, returnSellCostBuyPrice = returnSellCostBuyPrice+220, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+220
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+220, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+220
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+220
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '23', userid = '4', storedetaildate = '2022-02-12 17:15:42' WHERE storedetailid = '1299';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('515', '7', '1', '0', '302', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '22.00', '23', '4', '2022-02-12 17:15:42','0','0');
UPDATE save SET  savecurrentvalue = '-15',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('455.00','470', '1', '7', 'اضافة فاتورة مردوات مبيعات', '302', '-15', '2022-02-12 17:15:42', '4',  'returnsellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 470, 420, 500, 453.75
                    , 500, 453.75, 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+470, returnSellCostBuyPrice = returnSellCostBuyPrice+420, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+500
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+453.75, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+500
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+453.75
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 470, 420, 500, 453.75
                    , 500, 453.75, 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+470, returnSellCostBuyPrice = returnSellCostBuyPrice+420, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+500
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+453.75, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+500
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+453.75
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -470, -420, -500
                    , -453.75, -500, -453.75, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-470, netSellCostBuyPrice = netSellCostBuyPrice+-420
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-500
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-453.75
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-500
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-453.75
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207ceedad791 and sellbillId = 302 and returnsellbillId = 302
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:45:42";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 17:15:42", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 17:15:42', '4', 'addsellBill', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:47:15";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 17:17:15", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 17:17:15', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:47:17";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 17:17:17", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2022-02-12 17:17:17', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:47:19";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 17:17:19", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 17:17:19', '4', '', '102.47.174.252', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 13:48:22";
UPDATE user SET loginip = "102.47.174.252", lastactivetime = "2022-02-12 17:18:22", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 17:18:22', '4', 'addsellBill', '102.47.174.252', '', '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 < "2022-02-12 14:17:08";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 17:47:08", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 17:47:08', '7', '', '197.192.232.226', '', '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 < "2022-02-12 14:17:09";
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 < "2022-02-12 14:17:27";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 17:47:27", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 17:47:27', '7', 'addsellBill', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 7;
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 < "2022-02-12 14:42:03";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 18:12:03", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 18:12:03', '7', '', '197.192.232.226', '', '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 < "2022-02-12 14:42: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 < "2022-02-12 14:42:06";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 18:12:06", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 18:12:06', '7', 'addsellBill', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 7;
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 < "2022-02-12 14:42:32";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 18:12:32", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 18:12:32', '7', '', '197.192.232.226', '', '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 < "2022-02-12 14:42:32";
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 < "2022-02-12 14:42:33";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 18:12:33", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 18:12:33', '7', '', '197.192.232.226', '', '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 < "2022-02-12 14:42: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 < "2022-02-12 14:42:37";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 18:12:37", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 18:12:37', '7', 'addsellBill', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 14:46:37";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 18:16:37", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 18:16:37', '7', '', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 7;
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 < "2022-02-12 14:49:26";
UPDATE user SET loginip = "197.56.178.207", lastactivetime = "2022-02-12 18:19:26", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 18:19:26', '1', '', '197.56.178.207', '', '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 < "2022-02-12 14:49:27";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 14:49:54";
UPDATE user SET loginip = "197.56.178.207", lastactivetime = "2022-02-12 18:19:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2022-02-12 18:19:54', '1', '', '197.56.178.207', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 14:50:15";
UPDATE user SET loginip = "197.56.178.207", lastactivetime = "2022-02-12 18:20:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2022-02-12 18:20:16', '1', 'add', '197.56.178.207', '', '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 =1595
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(24,@clientdebt,@clientname);
UPDATE client SET  clientdebt = '6089' , clientdate = '2022-02-12 18:20:16', userid = '1' WHERE clientid = '24';
UPDATE client SET  inUse = 0 where clientid = 24;
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 ('24','11089.00','5000','1','ايصال تحصيل (( قبض من عميل ))','1595', '6089', '2022-02-12 18:19:54', '1', 'clientPayedDeptController.php', '   ', '5000', '0', null, '0', null, null,'', '-1','1','1','1','1');
UPDATE save SET  savecurrentvalue = '377615',  userid = '1' WHERE saveid = '1';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('372615.00','5000', '0', '1', 'ايصال تحصيل (( قبض من عميل ))', '1595', '377615', '2022-02-12 18:20:16', '1',  'clientPayedDeptController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '5000', '5000', '2022-02-12', '1', '0', '0', '2022-02-12 18:20:16','اضافة ايصال سداد للعميل محمود غانم','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1397', '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 = '382724', theOrder = '0', layingOrder = '1221',reportid = '2' WHERE id = '54';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1397', '77', '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 = '-37050', theOrder = '0', layingOrder = '',reportid = '0' WHERE id = '77';
UPDATE clientdebtchange SET clientid = '24', clientdebtchangebefore = '11089.00', clientdebtchangeamount = '5000.00', clientdebtchangetype = '1', processname = 'ايصال تحصيل (( قبض من عميل ))', clientdebtchangemodelid = '1595', clientdebtchangeafter = '6089.00', clientdebtchangedate = '2022-02-12 18:19:54', userid = '1', tablename = 'clientPayedDeptController.php', comment = '   ', totalOperationCost = '5000.00',discount='', reciptid=null, dailyentryid = '1397',seller = '0',currencyId='1',conversionFactor='1',payedInCurrency='1',saveConversionFactor='1' WHERE clientdebtchangeid = '1595';
COMMIT;

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

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 14:50:16";
UPDATE user SET loginip = "197.56.178.207", lastactivetime = "2022-02-12 18:20:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2022-02-12 18:20:16', '1', 'sucess', '197.56.178.207', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 14:50:18";
UPDATE user SET loginip = "197.56.178.207", lastactivetime = "2022-02-12 18:20:18", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2022-02-12 18:20:18', '1', 'show', '197.56.178.207', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 14:51:39";
UPDATE user SET loginip = "197.56.178.207", lastactivetime = "2022-02-12 18:21:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2022-02-12 18:21:39', '1', '', '197.56.178.207', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 14:53:29";
UPDATE user SET loginip = "197.56.178.207", lastactivetime = "2022-02-12 18:23:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2022-02-12 18:23:29', '1', 'add', '197.56.178.207', '', '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(248,3,5,310,2,'2022-02-12',1,0, '' ,0,0,0,0,0,'2022-02-12 18:23:29',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1409';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-08', 3, 310, 0, 0
                    , 150.00, 2, 0, 0, 1, '2022-02-12 18:23:29')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity-2, sellQuantity = sellQuantity-0,
                        del = 0,userid = 1,sysDate = '2022-02-12 18:23:29' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "2*2021-11-08*150.00," WHERE transferproductid = 1506;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('310', '3', '2', '1', '1506', 'تحويل منتجات من المخزن', 'storemovementController.php', '2.00', '0', '1', '2022-02-12','0','0');
UPDATE storedetail SET  productquantity = '4', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '886';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-08', 5, 310, 0, 0
                    , 150.00, 2, 0, 0, 1, '2022-02-12 18:23:29')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+2, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2022-02-12 18:23:29' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('310', '5', '2', '0', '1506', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '2.00', '4', '1', '2022-02-12','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('3', '5', '304', '3', '2022-02-12', '1', '0','248',null,null,'2022-02-12 18:23:29',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '28', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1406';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-08', 3, 304, 0, 0
                    , 145.00, 3, 0, 0, 1, '2022-02-12 18:23:29')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity-3, sellQuantity = sellQuantity-0,
                        del = 0,userid = 1,sysDate = '2022-02-12 18:23:29' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "3*2021-11-08*145.00," WHERE transferproductid = 1507;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('304', '3', '3', '1', '1507', 'تحويل منتجات من المخزن', 'storemovementController.php', '31.00', '28', '1', '2022-02-12','0','0');
UPDATE storedetail SET  productquantity = '10', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '891';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-08', 5, 304, 0, 0
                    , 145.00, 3, 0, 0, 1, '2022-02-12 18:23:29')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+3, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2022-02-12 18:23:29' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('304', '5', '3', '0', '1507', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '7.00', '10', '1', '2022-02-12','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('3', '5', '306', '10', '2022-02-12', '1', '0','248',null,null,'2022-02-12 18:23:29',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '23', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1405';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-08', 3, 306, 0, 0
                    , 145.00, 10, 0, 0, 1, '2022-02-12 18:23:29')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity-10, sellQuantity = sellQuantity-0,
                        del = 0,userid = 1,sysDate = '2022-02-12 18:23:29' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "10*2021-11-08*145.00," WHERE transferproductid = 1508;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('306', '3', '10', '1', '1508', 'تحويل منتجات من المخزن', 'storemovementController.php', '33.00', '23', '1', '2022-02-12','0','0');
UPDATE storedetail SET  productquantity = '23', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '890';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-08', 5, 306, 0, 0
                    , 145.00, 10, 0, 0, 1, '2022-02-12 18:23:29')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+10, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2022-02-12 18:23:29' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('306', '5', '10', '0', '1508', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '13.00', '23', '1', '2022-02-12','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('3', '5', '305', '3', '2022-02-12', '1', '0','248',null,null,'2022-02-12 18:23:29',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '7', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '1457';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-08', 3, 305, 0, 0
                    , 145.00, 3, 0, 0, 1, '2022-02-12 18:23:29')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity-3, sellQuantity = sellQuantity-0,
                        del = 0,userid = 1,sysDate = '2022-02-12 18:23:29' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "3*2021-11-08*145.00," WHERE transferproductid = 1509;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('305', '3', '3', '1', '1509', 'تحويل منتجات من المخزن', 'storemovementController.php', '10.00', '7', '1', '2022-02-12','0','0');
UPDATE storedetail SET  productquantity = '9', userid = '1', storedetaildate = '2022-02-12' WHERE storedetailid = '897';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-11-08', 5, 305, 0, 0
                    , 145.00, 3, 0, 0, 1, '2022-02-12 18:23:29')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+3, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2022-02-12 18:23:29' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('305', '5', '3', '0', '1509', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '6.00', '9', '1', '2022-02-12','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 14:53:30";
UPDATE user SET loginip = "197.56.178.207", lastactivetime = "2022-02-12 18:23:30", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2022-02-12 18:23:30', '1', 'sucess', '197.56.178.207', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 14:53:31";
UPDATE user SET loginip = "197.56.178.207", lastactivetime = "2022-02-12 18:23:31", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2022-02-12 18:23:31', '1', 'show', '197.56.178.207', '', '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 < "2022-02-12 14:58:14";
UPDATE user SET loginip = "154.176.240.45", lastactivetime = "2022-02-12 18:28:14", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 18:28:14', '8', '', '154.176.240.45', '', '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 < "2022-02-12 14:58:14";
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 < "2022-02-12 14:58:20";
UPDATE user SET loginip = "154.176.240.45", lastactivetime = "2022-02-12 18:28:20", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 18:28:20', '8', '', '154.176.240.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 14:59:28";
UPDATE user SET loginip = "154.176.240.45", lastactivetime = "2022-02-12 18:29:28", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 18:29:28', '8', 'add', '154.176.240.45', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('-1', 'فطار', '', '10', '2022-02-12', '8', '0','-1','6','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '2855',  userid = '8' WHERE saveid = '6';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2865.00','10', '1', '6', 'إضافة مصروف', '349', '2855', '2022-02-12 18:29:28', '8',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '10', '10', '2022-02-12', '8', '0', '0', '2022-02-12 18:29:28','اضافة اسم مصروف( فطار )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1398', '160', '10', '','0');
UPDATE accountstree SET name = '', customName = '', parent = '10', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-12-01', itemtype2 = '1', theValue = '-77185', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '160';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1398', '140', '10', '','0');
UPDATE accountstree SET name = 'خزينة محل كفر الدوار', customName = 'خزينة محل كفر الدوار', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-41225', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '140';
UPDATE expenses SET expensestypeid = '-1', expensesname = 'فطار', expensesdetails = '', expensesValue = '10.00', expensesdate = '2022-02-12', userid = '8', conditions = '0',saveid = '6' , dailyentryid = '1398', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '349';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 14:59:29";
UPDATE user SET loginip = "154.176.240.45", lastactivetime = "2022-02-12 18:29:29", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 18:29:29', '8', 'sucess', '154.176.240.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 14:59:33";
UPDATE user SET loginip = "154.176.240.45", lastactivetime = "2022-02-12 18:29:33", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 18:29:33', '8', 'show', '154.176.240.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 14:59:36";
UPDATE user SET loginip = "154.176.240.45", lastactivetime = "2022-02-12 18:29:36", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 18:29:36', '8', '', '154.176.240.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 15:04:10";
UPDATE user SET loginip = "154.176.240.45", lastactivetime = "2022-02-12 18:34:10", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 18:34:10', '8', '', '154.176.240.45', '', '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 < "2022-02-12 15:04:11";
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 < "2022-02-12 15:04:19";
UPDATE user SET loginip = "154.176.240.45", lastactivetime = "2022-02-12 18:34:19", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 18:34:19', '8', '', '154.176.240.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 15:04:22";
UPDATE user SET loginip = "197.56.178.207", lastactivetime = "2022-02-12 18:34:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('cashflowsController.php', '2022-02-12 18:34:22', '1', '', '197.56.178.207', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 15:04:44";
UPDATE user SET loginip = "197.56.178.207", lastactivetime = "2022-02-12 18:34:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('cashflowsController.php', '2022-02-12 18:34:44', '1', 'show', '197.56.178.207', '', '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 < "2022-02-12 15:33:02";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 19:03:02", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 19:03:02', '5', '', '154.180.139.62', '', '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 < "2022-02-12 15:33: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 < "2022-02-12 15:33:26";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 19:03:26", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 19:03:26', '5', 'addsellBill', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 15:37:56";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 19:07:56", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 19:07:56', '5', 'addAndRetuen', '154.180.139.62', '', 'DESKTOP');
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207e85ee13db
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(98,@clientdebt,@clientname);
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2022-02-12 19:03:26', '06207e85ee13db', '98', '-50.00', '0', '0', '1', '460', '460', '410', '50', '3', '2022-02-12 19:07:56', '', '5', '0', 'ام رمضان العوايد', '3', '1', '3', '0', 'ام رمضان العوايد', '2' ,'0','','','','','-1','0','0','0','0','0','460','0','','0','0','410','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '5' WHERE clientid = '98';
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 ('98','-50.00','50','0','اضافة فاتورة مبيعات','1005', '0', '2022-02-12 19:07:56', '5', 'sellbillController.php', 'اضافة فاتورة مبيعات', '460', '0', null, '0', null, null,'', '0','1','1','50','1');
UPDATE client SET  inUse = 0 where clientid = 98;
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+2 where id = 2664;
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', '1005', '1', '565', '2', '230.00', '460', '0', '', '0', '2022-02-12 19:07:56', '565', '0.00', '0', '3','0','','','0','0','0','0','0','0','0','0','','2664-2,');
UPDATE sellbilldetail SET  lastbuyprice = 150.00 , meanbuyprice = 150.00, lastbuyprice_withDiscount = 150.00, meanbuyprice_withDiscount = 150.00
                where sellbilldetailid = 2037;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (565, '2022-02-12', 460, 300, 300
                    , 300, 300, 300, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 2, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+460, 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 (3, '2022-02-12', 460, 300, 300
                    , 300, 300, 300, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+460, 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 = '27', userid = '5', storedetaildate = '2022-02-12 19:07:56' WHERE storedetailid = '1500';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '3', '2', '1', '1005', 'اضافة فاتورة مبيعات', 'sellbillController.php', '29.00', '27', '5', '2022-02-12 19:07:56','0','0');
UPDATE save SET  savecurrentvalue = '1370',  userid = '5' WHERE saveid = '3';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('960.00','410', '0', '3', 'اضافة فاتورة مبيعات', '1005', '1370', '2022-02-12 19:07:56', '5',  'sellbillController.php','98','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 460, 300, 300
                    , 300, 300, 300, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+460, 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;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (98, '2022-02-12', 460, 300, 300
                    , 300, 300, 300, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+460, 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;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, 460, 300, 300
                    , 300, 300, 300, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+460, netSellCostBuyPrice = netSellCostBuyPrice+300
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+300
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+300
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+300
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+300
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207e85ee13db and sellbillId = 1005 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 15:37:56";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 19:07:56", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 19:07:56', '5', 'addsellBill', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 15:38:13";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 19:08:13", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 19:08:13', '5', '', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 15:38:22";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 19:08:22", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 19:08:22', '5', 'showDetail', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 15:38:43";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 19:08:43", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2022-02-12 19:08:43', '5', '', '154.180.139.62', '', '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 < "2022-02-12 15:39:05";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 19:09:05", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 19:09:05', '7', '', '197.192.232.226', '', '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 < "2022-02-12 15:39:06";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE userid = 5;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 15:50:26";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 19:20:26", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 19:20:26', '7', 'addsellBill', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 15:54:55";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 19:24:55", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 19:24:55', '7', 'addAndRetuen', '197.192.232.226', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207ec5a5d7d4
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 19:20:26', '06207ec5a5d7d4', '1', '0.00', '0', '20', '1', '260', '240', '240', '0', '5', '2022-02-12 19:24:55', '', '7', '0', 'نقدي', '5', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','240','0','','0','0','240','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '7' WHERE clientid = '1';
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('1','0.00','0','0','اضافة فاتورة مبيعات','1006', '0', '2022-02-12 19:24:55', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '240', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2068;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('195','00555', '1006', '1', '555', '1', '260', '260', '0', '', '1', '2022-02-12 19:24:55', '555', '0.00', '0', '5','0','','','0','0','0','0','0','0','1','0','','2068-1,');
UPDATE sellbilldetail SET  lastbuyprice = 195.00 , meanbuyprice = 195.00, lastbuyprice_withDiscount = 195.00, meanbuyprice_withDiscount = 195.00
                where sellbilldetailid = 2038;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (555, '2022-02-12', 240, 195, 195
                    , 195, 195, 195, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+240, sellCostBuyPrice =sellCostBuyPrice+195
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+195, sellCostMeanBuyPrice = sellCostMeanBuyPrice+195
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+195, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+195
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (5, '2022-02-12', 240, 195, 195
                    , 195, 195, 195, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+240, sellCostBuyPrice =sellCostBuyPrice+195
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+195, sellCostMeanBuyPrice = sellCostMeanBuyPrice+195
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+195, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+195
                            , 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 = '7', storedetaildate = '2022-02-12 19:24:55' WHERE storedetailid = '1496';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '5', '1', '1', '1006', 'اضافة فاتورة مبيعات', 'sellbillController.php', '5.00', '4', '7', '2022-02-12 19:24:55','0','0');
UPDATE save SET  savecurrentvalue = '2225',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1985.00','240', '0', '5', 'اضافة فاتورة مبيعات', '1006', '2225', '2022-02-12 19:24:55', '7',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 240, 195, 195
                    , 195, 195, 195, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+240, sellCostBuyPrice =sellCostBuyPrice+195
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+195, sellCostMeanBuyPrice = sellCostMeanBuyPrice+195
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+195, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+195
                            , 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, '2022-02-12', 240, 195, 195
                    , 195, 195, 195, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+240, sellCostBuyPrice =sellCostBuyPrice+195
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+195, sellCostMeanBuyPrice = sellCostMeanBuyPrice+195
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+195, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+195
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, 240, 195, 195
                    , 195, 195, 195, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+240, netSellCostBuyPrice = netSellCostBuyPrice+195
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+195
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+195
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+195
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+195
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207ec5a5d7d4 and sellbillId = 1006 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 15:54:56";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 19:24:56", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 19:24:56', '7', 'addsellBill', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 7;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:12:25";
UPDATE user SET loginip = "197.56.178.207", lastactivetime = "2022-02-12 19:42:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2022-02-12 19:42:25', '1', '', '197.56.178.207', '', '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 < "2022-02-12 16:32:28";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 20:02:28", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 20:02:28', '7', '', '197.192.232.226', '', '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 < "2022-02-12 16:32:29";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:32:31";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 20:02:31", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:02:31', '7', 'addsellBill', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 7;
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 < "2022-02-12 16:45:31";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 20:15:31", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 20:15:31', '5', '', '154.180.139.62', '', '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 < "2022-02-12 16:45:31";
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 < "2022-02-12 16:45:34";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 20:15:34", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 20:15:34', '5', '', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:45:49";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 20:15:49", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 20:15:49', '5', '', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:46:03";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 20:16:03", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 20:16:03', '5', '', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:46:32";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 20:16:32", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 20:16:32', '5', 'add', '154.180.139.62', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('4', 'بخور المحل', '', '5', '2022-02-12', '5', '0','-1','3','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '1365',  userid = '5' WHERE saveid = '3';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1370.00','5', '1', '3', 'إضافة مصروف', '350', '1365', '2022-02-12 20:16:32', '5',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '5', '5', '2022-02-12', '5', '0', '0', '2022-02-12 20:16:32','اضافة اسم مصروف( بخور المحل )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1399', '147', '5', '','0');
UPDATE accountstree SET name = 'نظافة', customName = 'نظافة', parent = '14', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-08', itemtype2 = '0', theValue = '750', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '147';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1399', '137', '5', '','0');
UPDATE accountstree SET name = 'خزينة رائد', customName = 'خزينة رائد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-56655', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '137';
UPDATE expenses SET expensestypeid = '4', expensesname = 'بخور المحل', expensesdetails = '', expensesValue = '5.00', expensesdate = '2022-02-12', userid = '5', conditions = '0',saveid = '3' , dailyentryid = '1399', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '350';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:46:33";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 20:16:33", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 20:16:33', '5', 'sucess', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:46:34";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 20:16:34", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 20:16:34', '5', 'show', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:47:27";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 20:17:27", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 20:17:27', '5', '', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 5;
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 < "2022-02-12 16:49:40";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:19:40", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 20:19:40', '3', '', '41.34.73.148', '', '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 < "2022-02-12 16:49:40";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:50:15";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:20:15", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:20:15', '3', 'addsellBill', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:51:16";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:21:16", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:21:16', '3', 'addAndRetuen', '41.34.73.148', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207fa5f6ed8b
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 20:20:15', '06207fa5f6ed8b', '1', '0.00', '0', '0', '1', '880', '880', '880', '0', '8', '2022-02-12 20:21:16', '', '3', '0', 'نقدي', '8', '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 = '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','اضافة فاتورة مبيعات','1007', '0', '2022-02-12 20:21:16', '3', 'sellbillController.php', 'اضافة فاتورة مبيعات', '880', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1058;
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 ('145','00039', '1007', '1', '39', '1', '220.00', '220', '0', '', '0', '2022-02-12 20:21:16', '39', '0.00', '0', '8','0','','','0','0','0','0','0','0','0','0','','1058-1,');
UPDATE sellbilldetail SET  lastbuyprice = 145.00 , meanbuyprice = 145.00, lastbuyprice_withDiscount = 145.00, meanbuyprice_withDiscount = 145.00
                where sellbilldetailid = 2039;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (39, '2022-02-12', 220, 145, 145
                    , 145, 145, 145, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+220, sellCostBuyPrice =sellCostBuyPrice+145
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+145, sellCostMeanBuyPrice = sellCostMeanBuyPrice+145
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+145, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+145
                            , 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, '2022-02-12', 220, 145, 145
                    , 145, 145, 145, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+220, sellCostBuyPrice =sellCostBuyPrice+145
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+145, sellCostMeanBuyPrice = sellCostMeanBuyPrice+145
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+145, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+145
                            , 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 = '15', userid = '3', storedetaildate = '2022-02-12 20:21:16' WHERE storedetailid = '1080';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('39', '8', '1', '1', '1007', 'اضافة فاتورة مبيعات', 'sellbillController.php', '16.00', '15', '3', '2022-02-12 20:21:16','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1922;
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','00561', '1007', '1', '561', '1', '200', '200', '0', '', '0', '2022-02-12 20:21:16', '561', '0.00', '0', '8','0','','','0','0','0','0','0','0','0','0','','1922-1,');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 210.00, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 210.00
                where sellbilldetailid = 2040;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (561, '2022-02-12', 200, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+200, 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, '2022-02-12', 200, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+200, 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 = '20', userid = '3', storedetaildate = '2022-02-12 20:21:16' WHERE storedetailid = '1520';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '8', '1', '1', '1007', 'اضافة فاتورة مبيعات', 'sellbillController.php', '21.00', '20', '3', '2022-02-12 20:21:16','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+2 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', '1007', '1', '562', '2', '230', '460', '0', '', '0', '2022-02-12 20:21:16', '562', '0.00', '0', '8','0','','','0','0','0','0','0','0','0','0','','1918-2,');
UPDATE sellbilldetail SET  lastbuyprice = 225.00 , meanbuyprice = 225.00, lastbuyprice_withDiscount = 225.00, meanbuyprice_withDiscount = 225.00
                where sellbilldetailid = 2041;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (562, '2022-02-12', 460, 450, 450
                    , 450, 450, 450, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 2, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+460, sellCostBuyPrice =sellCostBuyPrice+450
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+450, sellCostMeanBuyPrice = sellCostMeanBuyPrice+450
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+450, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+450
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+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, '2022-02-12', 460, 450, 450
                    , 450, 450, 450, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+460, sellCostBuyPrice =sellCostBuyPrice+450
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+450, sellCostMeanBuyPrice = sellCostMeanBuyPrice+450
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+450, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+450
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '18', userid = '3', storedetaildate = '2022-02-12 20:21:16' WHERE storedetailid = '1518';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '8', '2', '1', '1007', 'اضافة فاتورة مبيعات', 'sellbillController.php', '20.00', '18', '3', '2022-02-12 20:21:16','0','0');
UPDATE save SET  savecurrentvalue = '950',  userid = '3' WHERE saveid = '8';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('70.00','880', '0', '8', 'اضافة فاتورة مبيعات', '1007', '950', '2022-02-12 20:21:16', '3',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 880, 805, 805
                    , 805, 805, 805, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+880, sellCostBuyPrice =sellCostBuyPrice+805
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+805, sellCostMeanBuyPrice = sellCostMeanBuyPrice+805
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+805, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+805
                            , 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, '2022-02-12', 880, 805, 805
                    , 805, 805, 805, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+880, sellCostBuyPrice =sellCostBuyPrice+805
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+805, sellCostMeanBuyPrice = sellCostMeanBuyPrice+805
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+805, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+805
                            , 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, 805, 805
                    , 805, 805, 805, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+880, netSellCostBuyPrice = netSellCostBuyPrice+805
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+805
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+805
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+805
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+805
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207fa5f6ed8b and sellbillId = 1007 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:51:16";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:21:16", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:21:16', '3', 'addsellBill', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:51:55";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:21:55", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:21:56', '3', 'addAndRetuen', '41.34.73.148', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207fa9ce5edb
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 20:21:16', '06207fa9ce5edb', '1', '0.00', '0', '0', '1', '320', '320', '320', '0', '8', '2022-02-12 20:21:56', '', '3', '0', 'نقدي', '8', '0', '3', '0', 'نقدي', '2' ,'0','','','','','-1','0','0','0','0','0','320','0','','0','0','320','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','اضافة فاتورة مبيعات','1008', '0', '2022-02-12 20:21:56', '3', 'sellbillController.php', 'اضافة فاتورة مبيعات', '320', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1260;
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 ('185','00385', '1008', '1', '385', '1', '160.00', '160', '0', '', '2', '2022-02-12 20:21:56', '385', '0.00', '0', '8','0','','','0','0','0','0','0','0','2','0','','1260-1,');
UPDATE sellbilldetail SET  lastbuyprice = 185.00 , meanbuyprice = 167.50, lastbuyprice_withDiscount = 185.00, meanbuyprice_withDiscount = 167.50
                where sellbilldetailid = 2042;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (385, '2022-02-12', 160, 150, 185
                    , 167.5, 185, 167.5, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+160, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+185, sellCostMeanBuyPrice = sellCostMeanBuyPrice+167.5
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+185, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+167.5
                            , 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, '2022-02-12', 160, 150, 185
                    , 167.5, 185, 167.5, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+160, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+185, sellCostMeanBuyPrice = sellCostMeanBuyPrice+167.5
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+185, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+167.5
                            , 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 = '12', userid = '3', storedetaildate = '2022-02-12 20:21:56' WHERE storedetailid = '1180';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('385', '8', '1', '1', '1008', 'اضافة فاتورة مبيعات', 'sellbillController.php', '13.00', '12', '3', '2022-02-12 20:21:56','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1254;
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 ('190','00382', '1008', '1', '382', '1', '160.00', '160', '0', '', '2', '2022-02-12 20:21:56', '382', '0.00', '0', '8','0','','','0','0','0','0','0','0','2','0','','1254-1,');
UPDATE sellbilldetail SET  lastbuyprice = 190.00 , meanbuyprice = 170.00, lastbuyprice_withDiscount = 190.00, meanbuyprice_withDiscount = 170.00
                where sellbilldetailid = 2043;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (382, '2022-02-12', 160, 150, 190
                    , 170, 190, 170, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+160, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+190, sellCostMeanBuyPrice = sellCostMeanBuyPrice+170
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+190, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+170
                            , 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, '2022-02-12', 160, 150, 190
                    , 170, 190, 170, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+160, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+190, sellCostMeanBuyPrice = sellCostMeanBuyPrice+170
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+190, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+170
                            , 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 = '9', userid = '3', storedetaildate = '2022-02-12 20:21:56' WHERE storedetailid = '1177';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('382', '8', '1', '1', '1008', 'اضافة فاتورة مبيعات', 'sellbillController.php', '10.00', '9', '3', '2022-02-12 20:21:56','0','0');
UPDATE save SET  savecurrentvalue = '1270',  userid = '3' WHERE saveid = '8';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('950.00','320', '0', '8', 'اضافة فاتورة مبيعات', '1008', '1270', '2022-02-12 20:21:56', '3',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 320, 300, 375
                    , 337.5, 375, 337.5, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+320, sellCostBuyPrice =sellCostBuyPrice+300
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+375, sellCostMeanBuyPrice = sellCostMeanBuyPrice+337.5
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+375, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+337.5
                            , 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, '2022-02-12', 320, 300, 375
                    , 337.5, 375, 337.5, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+320, sellCostBuyPrice =sellCostBuyPrice+300
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+375, sellCostMeanBuyPrice = sellCostMeanBuyPrice+337.5
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+375, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+337.5
                            , 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, 320, 300, 375
                    , 337.5, 375, 337.5, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+320, netSellCostBuyPrice = netSellCostBuyPrice+300
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+375
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+337.5
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+375
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+337.5
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207fa9ce5edb and sellbillId = 1008 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:51:56";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:21:56", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:21:56', '3', 'addsellBill', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:53:12";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:23:12", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:23:12', '3', 'addAndRetuen', '41.34.73.148', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207fac488c4d
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 20:21:56', '06207fac488c4d', '1', '0.00', '0', '0', '1', '500', '500', '500', '0', '8', '2022-02-12 20:23:12', '', '3', '0', 'نقدي', '8', '0', '3', '0', 'نقدي', '3' ,'0','','','','','-1','0','0','0','0','0','500','0','','0','0','500','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','اضافة فاتورة مبيعات','1009', '0', '2022-02-12 20:23:12', '3', 'sellbillController.php', 'اضافة فاتورة مبيعات', '500', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1260;
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 ('185','00385', '1009', '1', '385', '1', '150.00', '150', '0', '', '0', '2022-02-12 20:23:12', '385', '0.00', '0', '8','0','','','0','0','0','0','0','0','0','0','','1260-1,');
UPDATE sellbilldetail SET  lastbuyprice = 185.00 , meanbuyprice = 167.50, lastbuyprice_withDiscount = 185.00, meanbuyprice_withDiscount = 167.50
                where sellbilldetailid = 2044;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (385, '2022-02-12', 150, 150, 185
                    , 167.5, 185, 167.5, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+150, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+185, sellCostMeanBuyPrice = sellCostMeanBuyPrice+167.5
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+185, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+167.5
                            , 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, '2022-02-12', 150, 150, 185
                    , 167.5, 185, 167.5, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+150, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+185, sellCostMeanBuyPrice = sellCostMeanBuyPrice+167.5
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+185, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+167.5
                            , 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 = '2022-02-12 20:23:12' WHERE storedetailid = '1180';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('385', '8', '1', '1', '1009', 'اضافة فاتورة مبيعات', 'sellbillController.php', '12.00', '11', '3', '2022-02-12 20:23:12','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1258;
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 ('185','00384', '1009', '1', '384', '1', '150', '150', '0', '', '0', '2022-02-12 20:23:12', '384', '0.00', '0', '8','0','','','0','0','0','0','0','0','0','0','','1258-1,');
UPDATE sellbilldetail SET  lastbuyprice = 185.00 , meanbuyprice = 167.50, lastbuyprice_withDiscount = 185.00, meanbuyprice_withDiscount = 167.50
                where sellbilldetailid = 2045;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (384, '2022-02-12', 150, 150, 185
                    , 167.5, 185, 167.5, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+150, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+185, sellCostMeanBuyPrice = sellCostMeanBuyPrice+167.5
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+185, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+167.5
                            , 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, '2022-02-12', 150, 150, 185
                    , 167.5, 185, 167.5, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+150, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+185, sellCostMeanBuyPrice = sellCostMeanBuyPrice+167.5
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+185, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+167.5
                            , 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 = '1', userid = '3', storedetaildate = '2022-02-12 20:23:12' WHERE storedetailid = '1179';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('384', '8', '1', '1', '1009', 'اضافة فاتورة مبيعات', 'sellbillController.php', '2.00', '1', '3', '2022-02-12 20:23:12','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1284;
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 ('190','00462', '1009', '1', '462', '1', '200', '200', '0', '', '0', '2022-02-12 20:23:12', '462', '0.00', '0', '8','0','','','0','0','0','0','0','0','0','0','','1284-1,');
UPDATE sellbilldetail SET  lastbuyprice = 190.00 , meanbuyprice = 195.00, lastbuyprice_withDiscount = 190.00, meanbuyprice_withDiscount = 195.00
                where sellbilldetailid = 2046;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (462, '2022-02-12', 200, 195, 190
                    , 195, 190, 195, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+200, sellCostBuyPrice =sellCostBuyPrice+195
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+190, sellCostMeanBuyPrice = sellCostMeanBuyPrice+195
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+190, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+195
                            , 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, '2022-02-12', 200, 195, 190
                    , 195, 190, 195, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+200, sellCostBuyPrice =sellCostBuyPrice+195
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+190, sellCostMeanBuyPrice = sellCostMeanBuyPrice+195
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+190, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+195
                            , 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 = '9', userid = '3', storedetaildate = '2022-02-12 20:23:12' WHERE storedetailid = '1192';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('462', '8', '1', '1', '1009', 'اضافة فاتورة مبيعات', 'sellbillController.php', '10.00', '9', '3', '2022-02-12 20:23:12','0','0');
UPDATE save SET  savecurrentvalue = '1770',  userid = '3' WHERE saveid = '8';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1270.00','500', '0', '8', 'اضافة فاتورة مبيعات', '1009', '1770', '2022-02-12 20:23:12', '3',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 500, 495, 560
                    , 530, 560, 530, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+500, sellCostBuyPrice =sellCostBuyPrice+495
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+560, sellCostMeanBuyPrice = sellCostMeanBuyPrice+530
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+560, 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, '2022-02-12', 500, 495, 560
                    , 530, 560, 530, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+500, sellCostBuyPrice =sellCostBuyPrice+495
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+560, sellCostMeanBuyPrice = sellCostMeanBuyPrice+530
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+560, 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, 500, 495, 560
                    , 530, 560, 530, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+500, netSellCostBuyPrice = netSellCostBuyPrice+495
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+560
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+530
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+560
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+530
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207fac488c4d and sellbillId = 1009 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:53:13";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:23:13", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:23:13', '3', 'addsellBill', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:53:17";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:23:17", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:23:17', '3', 'addsellBill', '41.34.73.148', '', '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 < "2022-02-12 16:53:45";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 20:23:45", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 20:23:45', '7', '', '197.192.232.226', '', '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 < "2022-02-12 16:53:46";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:53:47";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 20:23:47", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 20:23:47', '7', '', '197.192.232.226', '', '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 < "2022-02-12 16:53: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 < "2022-02-12 16:53:57";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 20:23:57", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 20:23:57', '7', '', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:54:09";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:24:09", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:24:09', '3', 'addAndRetuen', '41.34.73.148', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207fb153c6bd
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 20:23:17', '06207fb153c6bd', '1', '0.00', '0', '0', '1', '455', '455', '-455', '0', '8', '2022-02-12 20:24:09', '', '3', '0', 'نقدي','8', '0', '5', '0', 'نقدي', '2', '0', '', '','','','-1','0','0','0','','0','-455','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','1','اضافة فاتورة مردوات مبيعات','303', '0', '2022-02-12 20:24:09', '3', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '455', '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 ('195.00', '00555', '303', '1', '555', '1', '230.00', '230', '0', '', '0', '0', '555', '0.00', '0','8','0','','','0','0','0','0','0','0');
UPDATE returnsellbilldetail SET  lastbuyprice = 195.00 , meanbuyprice = 195.00, lastbuyprice_withDiscount = 195.00, meanbuyprice_withDiscount = 195.00
                where returnsellbilldetailid = 458;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (555, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 230, 195, 195, 195
                    , 195, 195, 0, 0, 1)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+230, returnSellCostBuyPrice = returnSellCostBuyPrice+195, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+195
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+195, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+195
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+195
                            , 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 (8, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 230, 195, 195, 195
                    , 195, 195, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+230, returnSellCostBuyPrice = returnSellCostBuyPrice+195, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+195
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+195, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+195
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+195
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '1', userid = '3', storedetaildate = '2022-02-12 20:24:09' WHERE storedetailid = '1478';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '8', '1', '0', '303', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '0.00', '1', '3', '2022-02-12 20:24:09','0','0');
INSERT INTO returnsellbilldetail (buyprice, parcode, returnsellbillid, returnsellbilldetailcatid, returnsellbilldetailproductid, returnsellbilldetailquantity, returnsellbilldetailprice, returnsellbilldetailtotalprice, conditions, note, pricetype, discountvalue, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,pricetypepro) VALUES ('220.00', '00617', '303', '1', '617', '1', '225', '225', '0', '', '0', '0', '617', '0.00', '0','8','0','','','0','0','0','0','0','0');
UPDATE returnsellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where returnsellbilldetailid = 459;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (617, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 225, 220, 220, 220
                    , 220, 220, 0, 0, 1)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+225, returnSellCostBuyPrice = returnSellCostBuyPrice+220, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+220
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+220, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+220
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+220
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+0
                        , netQuantityRet = netQuantityRet+1;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (8, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 225, 220, 220, 220
                    , 220, 220, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+225, returnSellCostBuyPrice = returnSellCostBuyPrice+220, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+220
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+220, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+220
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+220
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '11', userid = '3', storedetaildate = '2022-02-12 20:24:09' WHERE storedetailid = '1890';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('617', '8', '1', '0', '303', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '10.00', '11', '3', '2022-02-12 20:24:09','0','0');
UPDATE save SET  savecurrentvalue = '1315',  userid = '3' WHERE saveid = '8';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1770.00','455', '1', '8', 'اضافة فاتورة مردوات مبيعات', '303', '1315', '2022-02-12 20:24:09', '3',  'returnsellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 455, 415, 415, 415
                    , 415, 415, 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+455, returnSellCostBuyPrice = returnSellCostBuyPrice+415, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+415
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+415, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+415
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+415
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2022-02-12', 0, 0, 0
                    , 0, 0, 0, 0
                    , 455, 415, 415, 415
                    , 415, 415, 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+455, returnSellCostBuyPrice = returnSellCostBuyPrice+415, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+415
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+415, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+415
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+415
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -455, -415, -415
                    , -415, -415, -415, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-455, netSellCostBuyPrice = netSellCostBuyPrice+-415
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-415
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-415
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-415
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-415
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207fb153c6bd and sellbillId = 303 and returnsellbillId = 303
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:54:10";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:24:10", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:24:10', '3', 'addsellBill', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:54:14";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:24:14", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 20:24:14', '3', '', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:54:18";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:24:18", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:24:19', '3', 'showDetail', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:54:33";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:24:33", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:24:33', '3', 'addsellBill', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:55:04";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:25:04", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:25:04', '3', 'addAndRetuen', '41.34.73.148', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207fb6170fd0
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 20:24:33', '06207fb6170fd0', '1', '0.00', '0', '0', '1', '200', '200', '200', '0', '8', '2022-02-12 20:25:04', '', '3', '0', 'نقدي', '8', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','200','0','','0','0','200','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','اضافة فاتورة مبيعات','1010', '0', '2022-02-12 20:25:04', '3', 'sellbillController.php', 'اضافة فاتورة مبيعات', '200', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1284;
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 ('190','00462', '1010', '1', '462', '1', '200.00', '200', '0', '', '0', '2022-02-12 20:25:04', '462', '0.00', '0', '8','0','','','0','0','0','0','0','0','0','0','','1284-1,');
UPDATE sellbilldetail SET  lastbuyprice = 190.00 , meanbuyprice = 195.00, lastbuyprice_withDiscount = 190.00, meanbuyprice_withDiscount = 195.00
                where sellbilldetailid = 2047;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (462, '2022-02-12', 200, 195, 190
                    , 195, 190, 195, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+200, sellCostBuyPrice =sellCostBuyPrice+195
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+190, sellCostMeanBuyPrice = sellCostMeanBuyPrice+195
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+190, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+195
                            , 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, '2022-02-12', 200, 195, 190
                    , 195, 190, 195, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+200, sellCostBuyPrice =sellCostBuyPrice+195
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+190, sellCostMeanBuyPrice = sellCostMeanBuyPrice+195
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+190, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+195
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '8', userid = '3', storedetaildate = '2022-02-12 20:25:04' WHERE storedetailid = '1192';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('462', '8', '1', '1', '1010', 'اضافة فاتورة مبيعات', 'sellbillController.php', '9.00', '8', '3', '2022-02-12 20:25:04','0','0');
UPDATE save SET  savecurrentvalue = '1515',  userid = '3' WHERE saveid = '8';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1315.00','200', '0', '8', 'اضافة فاتورة مبيعات', '1010', '1515', '2022-02-12 20:25:04', '3',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 200, 195, 190
                    , 195, 190, 195, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+200, sellCostBuyPrice =sellCostBuyPrice+195
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+190, sellCostMeanBuyPrice = sellCostMeanBuyPrice+195
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+190, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+195
                            , 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, '2022-02-12', 200, 195, 190
                    , 195, 190, 195, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+200, sellCostBuyPrice =sellCostBuyPrice+195
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+190, sellCostMeanBuyPrice = sellCostMeanBuyPrice+195
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+190, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+195
                            , 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, 200, 195, 190
                    , 195, 190, 195, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+200, netSellCostBuyPrice = netSellCostBuyPrice+195
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+190
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+195
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+190
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+195
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207fb6170fd0 and sellbillId = 1010 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:55:05";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:25:05", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:25:05', '3', 'addsellBill', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:55:08";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:25:08", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 20:25:08', '3', '', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 1;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:56:02";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:26:02", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:26:02', '3', 'addsellBill', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:56:55";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:26:55", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:26:55', '3', 'addAndRetuen', '41.34.73.148', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 06207fbbaef88b
-- ----------------------------------------------------------------------------------------------------

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 ('2022-02-12 20:26:02', '06207fbbaef88b', '1', '0.00', '0', '0', '1', '225', '225', '225', '0', '8', '2022-02-12 20:26:55', '', '3', '0', 'نقدي', '8', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','225','0','','0','0','225','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','اضافة فاتورة مبيعات','1011', '0', '2022-02-12 20:26:55', '3', 'sellbillController.php', 'اضافة فاتورة مبيعات', '225', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2786;
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','00617', '1011', '1', '617', '1', '225.00', '225', '0', '', '0', '2022-02-12 20:26:55', '617', '0.00', '0', '8','0','','','0','0','0','0','0','0','0','0','','2786-1,');
UPDATE sellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where sellbilldetailid = 2048;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (617, '2022-02-12', 225, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+225, sellCostBuyPrice =sellCostBuyPrice+220
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+220, sellCostMeanBuyPrice = sellCostMeanBuyPrice+220
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+220, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+220
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (8, '2022-02-12', 225, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+225, sellCostBuyPrice =sellCostBuyPrice+220
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+220, sellCostMeanBuyPrice = sellCostMeanBuyPrice+220
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+220, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+220
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '10', userid = '3', storedetaildate = '2022-02-12 20:26:55' WHERE storedetailid = '1890';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('617', '8', '1', '1', '1011', 'اضافة فاتورة مبيعات', 'sellbillController.php', '11.00', '10', '3', '2022-02-12 20:26:55','0','0');
UPDATE save SET  savecurrentvalue = '1740',  userid = '3' WHERE saveid = '8';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1515.00','225', '0', '8', 'اضافة فاتورة مبيعات', '1011', '1740', '2022-02-12 20:26:55', '3',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2022-02-12', 225, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+225, sellCostBuyPrice =sellCostBuyPrice+220
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+220, sellCostMeanBuyPrice = sellCostMeanBuyPrice+220
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+220, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+220
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2022-02-12', 225, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+225, sellCostBuyPrice =sellCostBuyPrice+220
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+220, sellCostMeanBuyPrice = sellCostMeanBuyPrice+220
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+220, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+220
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, 225, 220, 220
                    , 220, 220, 220, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+225, netSellCostBuyPrice = netSellCostBuyPrice+220
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+220
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+220
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+220
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+220
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 06207fbbaef88b and sellbillId = 1011 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:56:56";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:26:56", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:26:56', '3', 'addsellBill', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:57:18";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:27:18", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 20:27:18', '3', '', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 7;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:57:27";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:27:27", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 20:27:27', '3', 'add', '41.34.73.148', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('-1', 'القبض بدون النسبه', '', '750', '2022-02-12', '3', '0','-1','8','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '990',  userid = '3' WHERE saveid = '8';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1740.00','750', '1', '8', 'إضافة مصروف', '351', '990', '2022-02-12 20:27:27', '3',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '750', '750', '2022-02-12', '3', '0', '0', '2022-02-12 20:27:27','اضافة اسم مصروف( القبض بدون النسبه )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1400', '160', '750', '','0');
UPDATE accountstree SET name = '', customName = '', parent = '10', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-12-01', itemtype2 = '1', theValue = '-77935', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '160';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1400', '142', '750', '','0');
UPDATE accountstree SET name = 'خزينة محل ابو كريم', customName = 'خزينة محل ابو كريم', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-112848', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '142';
UPDATE expenses SET expensestypeid = '-1', expensesname = 'القبض بدون النسبه', expensesdetails = '', expensesValue = '750.00', expensesdate = '2022-02-12', userid = '3', conditions = '0',saveid = '8' , dailyentryid = '1400', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '351';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:57:27";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:27:27", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 20:27:27', '3', 'sucess', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:57:29";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:27:29", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 20:27:29', '3', 'show', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:58:01";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:28:01", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:28:01', '3', 'addsellBill', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:58:04";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:28:04", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 20:28:04', '3', '', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:58:42";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:28:42", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 20:28:42', '3', 'add', '41.34.73.148', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('-1', 'توكتك وملح', '', '20', '2022-02-12', '3', '0','-1','8','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '970',  userid = '3' WHERE saveid = '8';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('990.00','20', '1', '8', 'إضافة مصروف', '352', '970', '2022-02-12 20:28:42', '3',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '20', '20', '2022-02-12', '3', '0', '0', '2022-02-12 20:28:42','اضافة اسم مصروف( توكتك وملح )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1401', '160', '20', '','0');
UPDATE accountstree SET name = '', customName = '', parent = '10', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-12-01', itemtype2 = '1', theValue = '-77955', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '160';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1401', '142', '20', '','0');
UPDATE accountstree SET name = 'خزينة محل ابو كريم', customName = 'خزينة محل ابو كريم', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-112868', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '142';
UPDATE expenses SET expensestypeid = '-1', expensesname = 'توكتك وملح', expensesdetails = '', expensesValue = '20.00', expensesdate = '2022-02-12', userid = '3', conditions = '0',saveid = '8' , dailyentryid = '1401', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '352';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:58:43";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:28:43", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 20:28:43', '3', 'sucess', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:58:44";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:28:44", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2022-02-12 20:28:44', '3', 'show', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:58:46";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:28:46", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:28:46', '3', 'addsellBill', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 16:58:48";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:28:48", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 20:28:48', '3', '', '41.34.73.148', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 17:03:55";
UPDATE user SET loginip = "41.34.73.148", lastactivetime = "2022-02-12 20:33:55", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 20:33:55', '3', 'addsellBill', '41.34.73.148', '', '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 < "2022-02-12 17:50:16";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 21:20:16", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 21:20:16', '7', '', '197.192.232.226', '', '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 < "2022-02-12 17:50:16";
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 < "2022-02-12 17:50:25";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 21:20:25", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('supplierPayedDeptController.php', '2022-02-12 21:20:25', '7', '', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 17:50:54";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 21:20:54", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('supplierPayedDeptController.php', '2022-02-12 21:20:54', '7', 'add', '197.192.232.226', '', 'DESKTOP');
BEGIN;
INSERT INTO supplierdebtchange (supplierid, supplierdebtchangebefore, supplierdebtchangeamount, supplierdebtchangetype, processname, supplierdebtchangemodelid, supplierdebtchangeafter, supplierdebtchangedate, userid, tablename, comment, dailyentryid,saveid, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor) VALUES ('1', '-137600.00', '2000', '1', 'ايصال دفع لمورد', '132', '-139600', '2022-02-12 21:20:25', '7', 'supplierPayedDeptController.php', 'جمعيه ادوي', '0','5', '-1','1','1','1','1');
UPDATE supplier SET  suppliercurrentDebt = '-139600', userid = '7', supplierdate = '2022-02-12 21:20:54'   WHERE supplierid = '1';
UPDATE save SET  savecurrentvalue = '225',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2225.00','2000', '1', '5', 'ايصال دفع لمورد', '132', '225', '2022-02-12 21:20:54', '7',  'supplierPayedDeptController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '2000', '2000', '2022-02-12', '7', '0', '0', '2022-02-12 21:20:54','ايصال دفع لمورد ( مباشر ) ','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1402', '168', '2000', '','0');
UPDATE accountstree SET name = 'مباشر', customName = 'مباشر', parent = '10', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '7', mydate = '2021-12-11', itemtype2 = '1', theValue = '-139600', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '168';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('1402', '139', '2000', '','0');
UPDATE accountstree SET name = 'خزينة محل عبدالله', customName = 'خزينة محل عبدالله', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-92349', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '139';
UPDATE supplierdebtchange SET supplierid = '1', supplierdebtchangebefore = '-137600.00', supplierdebtchangeamount = '2000.00', supplierdebtchangetype = '1', processname = 'ايصال دفع لمورد', supplierdebtchangemodelid = '132', supplierdebtchangeafter = '-139600.00', supplierdebtchangedate = '2022-02-12 21:20:25', userid = '7', tablename = 'supplierPayedDeptController.php', comment = 'جمعيه ادوي', dailyentryid = '1402',saveid = '5',currencyId='1',conversionFactor='1',payedInCurrency='1',saveConversionFactor='1' WHERE supplierdebtchangeid = '132';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 17:50:55";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 21:20:55", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('supplierPayedDeptController.php', '2022-02-12 21:20:55', '7', 'sucess', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 17:50:58";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 21:20:58", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('supplierPayedDeptController.php', '2022-02-12 21:20:58', '7', 'show', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 17:50:59";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 21:20:59", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('supplierReportsController.php', '2022-02-12 21:20:59', '7', '', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 17:52:17";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 21:22:17", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 21:22:17', '7', '', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 7;
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 < "2022-02-12 18:02:23";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 21:32:23", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 21:32:23', '5', '', '154.180.139.62', '', '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 < "2022-02-12 18:02:23";
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 < "2022-02-12 18:02:27";
UPDATE user SET loginip = "154.180.139.62", lastactivetime = "2022-02-12 21:32:27", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 21:32:28', '5', 'addsellBill', '154.180.139.62', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 5;
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 < "2022-02-12 18:42:23";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 22:12:23", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 22:12:23', '7', '', '197.192.232.226', '', '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 < "2022-02-12 18:42:23";
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 < "2022-02-12 18:42:27";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 22:12:27", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 22:12:27', '7', 'addsellBill', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 7;
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 < "2022-02-12 18:56:52";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 22:26:52", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 22:26:52', '7', '', '197.192.232.226', '', '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 < "2022-02-12 18:56:52";
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 < "2022-02-12 18:56:55";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 22:26:55", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 22:26:55', '7', '', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 7;
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 < "2022-02-12 19:23:36";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 22:53:36", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 22:53:36', '7', '', '197.192.232.226', '', '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 < "2022-02-12 19:23:36";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 19:23:37";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 22:53:37", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 22:53:37', '7', '', '197.192.232.226', '', '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 < "2022-02-12 19:23:37";
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 < "2022-02-12 19:23:42";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 22:53:42", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 22:53:42', '7', 'addsellBill', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 7;
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 < "2022-02-12 19:33:05";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 23:03:05", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2022-02-12 23:03:05', '7', '', '197.192.232.226', '', '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 < "2022-02-12 19:33:05";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 19:33:23";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 23:03:23", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2022-02-12 23:03:23', '7', 'addsellBill', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2022-02-12 19:33:42";
UPDATE user SET loginip = "197.192.232.226", lastactivetime = "2022-02-12 23:03:42", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2022-02-12 23:03:42', '7', '', '197.192.232.226', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 7;
