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

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 07:02:20";
UPDATE user SET loginip = "197.35.97.126", lastactivetime = "2021-12-15 10:32:20", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 10:32:20', '8', 'addsellBill', '197.35.97.126', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 07:02:20";
UPDATE user SET loginip = "197.35.97.126", lastactivetime = "2021-12-15 10:32:20", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 10:32:20', '8', 'addsellBill', '197.35.97.126', '', 'DESKTOP');
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 07:15:52";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 10:45:52", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-15 10:45:52', '4', '', '197.61.178.123', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 07:15: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 < "2021-12-15 07:15:55";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 10:45:55", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 10:45:55', '4', 'addsellBill', '197.61.178.123', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 07:16:55";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 10:46:55", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 10:46:55', '4', 'addsellBill', '197.61.178.123', '', 'DESKTOP');
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 07:24:56";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 10:54:57", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-15 10:54:57', '1', '', '197.56.115.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 < "2021-12-15 07:24:57";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 07:31:11";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 11:01:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-15 11:01:11', '1', 'show', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 07:31:15";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 11:01:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 11:01:15', '1', '', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 07:32:51";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 11:02:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 11:02:52', '1', 'add', '197.56.115.45', '', '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(170,4,7,590,3,'2021-12-15',1,0, '' ,0,0,0,0,0,'2021-12-15 11:02:52',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '9', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '1669';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-09', 4, 590, 0, 0
                    , 230.00, 3, 0, 0, 1, '2021-12-15 11:02:52')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity-3, sellQuantity = sellQuantity-0,
                        del = 0,userid = 1,sysDate = '2021-12-15 11:02:52' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "3*2021-12-09*230.00," WHERE transferproductid = 1157;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '4', '3', '1', '1157', 'تحويل منتجات من المخزن', 'storemovementController.php', '12.00', '9', '1', '2021-12-15','0','0');
UPDATE storedetail SET  productquantity = '9', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '1670';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-09', 7, 590, 0, 0
                    , 230.00, 3, 0, 0, 1, '2021-12-15 11:02:52')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+3, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 11:02:52' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '7', '3', '0', '1157', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '6.00', '9', '1', '2021-12-15','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 07:32:52";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 11:02:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 11:02:52', '1', 'sucess', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 07:32:54";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 11:02:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 11:02:54', '1', 'show', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 07:33:17";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 11:03:17", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 11:03:17', '4', 'addAndRetuen', '197.61.178.123', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b9ab7fa335c
-- ----------------------------------------------------------------------------------------------------

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

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9ab7fa335c and sellbillId = 317 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 07:33:17";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 11:03:17", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 11:03:18', '4', 'addsellBill', '197.61.178.123', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 07:41:33";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 11:11:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 11:11:33', '1', '', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 07:41:35";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 11:11:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 11:11:35', '1', '', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 07:41:38";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 11:11:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 11:11:38', '1', '', '197.56.115.45', '', 'DESKTOP');
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 08:13:59";
UPDATE user SET loginip = "197.41.125.146", lastactivetime = "2021-12-15 11:43:59", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-15 11:43:59', '3', '', '197.41.125.146', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 08:13:59";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 08:14:03";
UPDATE user SET loginip = "197.41.125.146", lastactivetime = "2021-12-15 11:44:03", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 11:44:03', '3', 'addsellBill', '197.41.125.146', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 09:08:19";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 12:38:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-15 12:38:19', '1', '', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 09:08:31";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 12:38:31", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-15 12:38:31', '1', 'show', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 09:11:22";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 12:41:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-15 12:41:22', '1', 'show', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 09:18:16";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 12:48:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 12:48:16', '1', '', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 09:25:04";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 12:55:04", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 12:55:04', '4', 'addAndRetuen', '197.61.178.123', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b9af5624190
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-15 11:03:18', '061b9af5624190', '1', '0.00', '0', '10', '1', '710', '700', '700', '0', '7', '2021-12-15 12:55:04', '', '4', '0', 'نقدي', '7', '0', '3', '0', 'نقدي', '3' ,'0','','','','','-1','0','0','0','0','0','700','0','','0','0','700','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','اضافة فاتورة مبيعات','318', '0', '2021-12-15 12:55:05', '4', 'sellbillController.php', 'اضافة فاتورة مبيعات', '700', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2224;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('230','00590', '318', '1', '590', '1', '235.00', '235', '0', '', '0', '2021-12-15 12:55:05', '590', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','2224-1,');
UPDATE sellbilldetail SET  lastbuyprice = 230.00 , meanbuyprice = 230.00, lastbuyprice_withDiscount = 230.00, meanbuyprice_withDiscount = 230.00
                where sellbilldetailid = 664;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (590, '2021-12-15', 231.690140845, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+231.690140845, sellCostBuyPrice =sellCostBuyPrice+230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+230
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (7, '2021-12-15', 231.690140845, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+231.690140845, sellCostBuyPrice =sellCostBuyPrice+230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+230
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '7', userid = '4', storedetaildate = '2021-12-15 12:55:05' WHERE storedetailid = '1670';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '7', '1', '1', '318', 'اضافة فاتورة مبيعات', 'sellbillController.php', '8.00', '7', '4', '2021-12-15 12:55:05','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1522;
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 ('235','00129', '318', '1', '129', '1', '250', '250', '0', '', '0', '2021-12-15 12:55:05', '129', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','1522-1,');
UPDATE sellbilldetail SET  lastbuyprice = 235.00 , meanbuyprice = 235.00, lastbuyprice_withDiscount = 235.00, meanbuyprice_withDiscount = 235.00
                where sellbilldetailid = 665;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (129, '2021-12-15', 246.478873239, 235, 235
                    , 235, 235, 235, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+246.478873239, sellCostBuyPrice =sellCostBuyPrice+235
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+235, sellCostMeanBuyPrice = sellCostMeanBuyPrice+235
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+235, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+235
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (7, '2021-12-15', 246.478873239, 235, 235
                    , 235, 235, 235, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+246.478873239, sellCostBuyPrice =sellCostBuyPrice+235
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+235, sellCostMeanBuyPrice = sellCostMeanBuyPrice+235
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+235, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+235
                            , 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 = '55', userid = '4', storedetaildate = '2021-12-15 12:55:05' WHERE storedetailid = '1312';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('129', '7', '1', '1', '318', 'اضافة فاتورة مبيعات', 'sellbillController.php', '56.00', '55', '4', '2021-12-15 12:55:05','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2008;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('220','00585', '318', '1', '585', '1', '225', '225', '0', '', '0', '2021-12-15 12:55:05', '585', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','2008-1,');
UPDATE sellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where sellbilldetailid = 666;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (585, '2021-12-15', 221.830985915, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+221.830985915, 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, '2021-12-15', 221.830985915, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+221.830985915, 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 = '24', userid = '4', storedetaildate = '2021-12-15 12:55:05' WHERE storedetailid = '1555';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '7', '1', '1', '318', 'اضافة فاتورة مبيعات', 'sellbillController.php', '25.00', '24', '4', '2021-12-15 12:55:05','0','0');
UPDATE save SET  savecurrentvalue = '935',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('235.00','700', '0', '7', 'اضافة فاتورة مبيعات', '318', '935', '2021-12-15 12:55:05', '4',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 700, 685, 685
                    , 685, 685, 685, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+700, sellCostBuyPrice =sellCostBuyPrice+685
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+685, sellCostMeanBuyPrice = sellCostMeanBuyPrice+685
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+685, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+685
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-15', 700, 685, 685
                    , 685, 685, 685, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+700, sellCostBuyPrice =sellCostBuyPrice+685
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+685, sellCostMeanBuyPrice = sellCostMeanBuyPrice+685
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+685, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+685
                            , 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, 700, 685, 685
                    , 685, 685, 685, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+700, netSellCostBuyPrice = netSellCostBuyPrice+685
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+685
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+685
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+685
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+685
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9af5624190 and sellbillId = 318 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 09:25:05";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 12:55:05", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 12:55:05', '4', 'addsellBill', '197.61.178.123', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 09:29:29";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 12:59:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 12:59:29', '1', '', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 09:58:45";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 13:28:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 13:28:45', '1', 'add', '197.56.115.45', '', 'DESKTOP');
BEGIN;
INSERT INTO product (productName, productDescription, productCatId, productBuyPrice, productSellAllPrice, productSellUnitPrice, productSellHalfPrice, productDate, conditions, userId, limitamount, parcode,type, expireDate, dailyentryId,isService,isOptic,lastbuyprice,lastbuyprice_withDiscount,meanbuyprice,meanbuyprice_withDiscount , productbuypricereal , buypricereal_precentage , buytotal_precentage , buyhalf_precentage , buypart_precentage,logo,inMenu,obygyDetectionId,hasSizeAndColor,overAllAveragePrice,reviewType,online,updatebyuser,proExcelid,proExcelParcode,webApiId) VALUES ('قطيفة هايدي خام','','2','87','87', '87','87', '2021-12-15', '0', '1', '0', '', '0', '0', '0', '0', '0', '87','87','87','87','87','0','0','0','0','.','0','0','0','0','0','','','0','0','0');
UPDATE product SET productName = 'قطيفة هايدي خام', productDescription = '', productCatId = '2', productBuyPrice = '87', productSellAllPrice = '87', productSellUnitPrice = '87', productSellHalfPrice = '87', productDate = '2021-12-15', conditions = '0', userId = '1', limitamount = '0', parcode = '00608',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '87',lastbuyprice_withDiscount = '87',meanbuyprice = '87',meanbuyprice_withDiscount = '87' , productbuypricereal = '87' , buypricereal_precentage = '0' , buytotal_precentage = '0' , buyhalf_precentage = '0' , buypart_precentage = '0',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '608';
INSERT INTO productunit (unitid, productid, productnumber, productunitdate, userid, conditions,proUnitParcode,proUnitSellAllPrice,proUnitSellHalfPrice,proUnitSellUnitPrice,proUnitBuyPrice) VALUES ('1', '608', '1', '2021-12-15', '1', '0','0060801','87','87','87','87');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('608', '1', '248.55', '1', '2021-12-15');
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('608', '1', '248.55', '0', '608', 'إضافة منتج', 'productController.php', '0', '248.55', '1', '2021-12-15','0','0');
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (608, 1,'2021-12-15 13:28:46',1)
                ON DUPLICATE KEY UPDATE productid = 608, edited = 1, sysdate = '2021-12-15 13:28:46', userid = 1;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '21623.85', '21623.85', '2021-12-15', '1', '0', '0', '2021-12-15 13:28:46','إضافة منتج قطيفة هايدي خام الكمية 248.55','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('845', '19', '21623.85', '','0');
UPDATE accountstree SET name = 'البضاعة (بضاعة أول المدة)', customName = 'البضاعة (بضاعة أول المدة)', parent = '6', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '6150846.35', theOrder = '0', layingOrder = '121',reportid = '0' WHERE id = '19';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('845', '7', '21623.85', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '7002232.15', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
UPDATE product SET productName = 'قطيفة هايدي خام', productDescription = '', productCatId = '2', productBuyPrice = '87.00', productSellAllPrice = '87.00', productSellUnitPrice = '87.00', productSellHalfPrice = '87.00', productDate = '2021-12-15', conditions = '0', userId = '1', limitamount = '0', parcode = '00608',type ='0', expireDate = '0' , dailyentryId = '845',isService = '0',isOptic = '0',lastbuyprice = '87',lastbuyprice_withDiscount = '87',meanbuyprice = '87',meanbuyprice_withDiscount = '87' , productbuypricereal = '87' , buypricereal_precentage = '0' , buytotal_precentage = '0' , buyhalf_precentage = '0' , buypart_precentage = '0',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '608';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 09:58:47";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 13:28:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 13:28:48', '1', '', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 09:58:52";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 13:28:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 13:28:52', '1', 'addsellBill', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:00:16";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 13:30:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 13:30:16', '1', 'addAndRetuen', '197.56.115.45', '', '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 061b9d1743516d
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(5,@clientdebt,@clientname);
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-15 13:28:52', '061b9d1743516d', '5', '3460.00', '10084', '0', '1', '21624', '21624', '15000', '6624', '1', '2021-12-15 13:30:16', '', '1', '0', 'خالد غرام', '1', '1', '3', '0', 'خالد غرام', '248.55' ,'0','','','','','-1','0','0','0','0','0','21624','0','','0','0','15000','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '10084', userid = '1' WHERE clientid = '5';
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 ('5','3460.00','6624','0','اضافة فاتورة مبيعات','319', '10084', '2021-12-15 13:30:16', '1', 'sellbillController.php', 'اضافة فاتورة مبيعات', '21624', '0', null, '0', null, null,'', '0','1','1','6624','1');
UPDATE client SET  inUse = 0 where clientid = 5;
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 ('87','00608', '319', '2', '608', '248.55', '87', '21624', '0', '', '1', '2021-12-15 13:30:16', '608', '0.00', '0', '1','0','','','0','0','0','0','0','0','1','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 87.00 , meanbuyprice = 87.00, lastbuyprice_withDiscount = 87.00, meanbuyprice_withDiscount = 87.00
                where sellbilldetailid = 667;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (608, '2021-12-15', 21624, 21623.85, 21623.85
                    , 21623.85, 21623.85, 21623.85, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 248.55, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+21624, sellCostBuyPrice =sellCostBuyPrice+21623.85
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+21623.85, sellCostMeanBuyPrice = sellCostMeanBuyPrice+21623.85
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+21623.85, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+21623.85
                            , 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+248.55
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-15', 21624, 21623.85, 21623.85
                    , 21623.85, 21623.85, 21623.85, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+21624, sellCostBuyPrice =sellCostBuyPrice+21623.85
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+21623.85, sellCostMeanBuyPrice = sellCostMeanBuyPrice+21623.85
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+21623.85, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+21623.85
                            , 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 = '0', userid = '1', storedetaildate = '2021-12-15 13:30:16' WHERE storedetailid = '1690';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('608', '1', '248.55', '1', '319', 'اضافة فاتورة مبيعات', 'sellbillController.php', '248.55', '0', '1', '2021-12-15 13:30:16','0','0');
UPDATE save SET  savecurrentvalue = '120776',  userid = '1' WHERE saveid = '1';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('105776.00','15000', '0', '1', 'اضافة فاتورة مبيعات', '319', '120776', '2021-12-15 13:30:16', '1',  'sellbillController.php','5','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 21624, 21623.85, 21623.85
                    , 21623.85, 21623.85, 21623.85, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+21624, sellCostBuyPrice =sellCostBuyPrice+21623.85
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+21623.85, sellCostMeanBuyPrice = sellCostMeanBuyPrice+21623.85
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+21623.85, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+21623.85
                            , 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 (5, '2021-12-15', 21624, 21623.85, 21623.85
                    , 21623.85, 21623.85, 21623.85, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+21624, sellCostBuyPrice =sellCostBuyPrice+21623.85
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+21623.85, sellCostMeanBuyPrice = sellCostMeanBuyPrice+21623.85
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+21623.85, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+21623.85
                            , 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, 21624, 21623.85, 21623.85
                    , 21623.85, 21623.85, 21623.85, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+21624, netSellCostBuyPrice = netSellCostBuyPrice+21623.85
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+21623.85
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+21623.85
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+21623.85
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+21623.85
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9d1743516d and sellbillId = 319 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:00:16";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 13:30:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 13:30:16', '1', 'addsellBill', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:01:08";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 13:31:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-15 13:31:08', '1', '', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:01:21";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 13:31:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-15 13:31:21', '1', 'show', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:01:37";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 13:31:37", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 13:31:37', '4', 'addsellBill', '197.61.178.123', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:03:01";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 13:33:01", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 13:33:01', '4', 'addAndRetuen', '197.61.178.123', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b9d2199c674
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO returnsellbill (returnsellbilldate, returnsellbillserial, returnsellbillclientid, returnsellbilltotaldeptbefor, returnsellbilltotaldeptafter, returnsellbilldiscount, returnsellbilldiscounttype, returnsellbilltotalbill, returnsellbillaftertotalbill, returnsellbilltotalpayed, returnsellbillfinalbill, returnsellbillstoreid, returnsellbillsysdate,comment, userid, conditions, returnsellbillclientname, returnsellbillsaveid, returnsellbildirectpayment, billnameid, sellerid, tempclientName, returnsellQuantity,tax, carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,delbyuserid,billReservation,billReservationDate,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal) VALUES ('2021-12-15 13:31:37', '061b9d2199c674', '1', '0.00', '0', '0', '1', '630', '630', '-630', '0', '7', '2021-12-15 13:33:01', '', '4', '0', 'نقدي','7', '0', '5', '0', 'نقدي', '3', '0', '', '','','','-1','0','0','0','','0','-630','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','اضافة فاتورة مردوات مبيعات','95', '0', '2021-12-15 13:33:01', '4', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '630', '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 ('190.00', '00463', '95', '1', '463', '1', '200', '200', '0', '', '0', '0', '463', '0.00', '0','7','0','','','0','0','0','0','0','0');
UPDATE returnsellbilldetail SET  lastbuyprice = 190.00 , meanbuyprice = 190.00, lastbuyprice_withDiscount = 190.00, meanbuyprice_withDiscount = 190.00
                where returnsellbilldetailid = 149;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (463, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 200, 190, 190, 190
                    , 190, 190, 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+200, returnSellCostBuyPrice = returnSellCostBuyPrice+190, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+190
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+190, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+190
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+190
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+0
                        , netQuantityRet = netQuantityRet+1;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (7, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 200, 190, 190, 190
                    , 190, 190, 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+200, returnSellCostBuyPrice = returnSellCostBuyPrice+190, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+190
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+190, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+190
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+190
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '24', userid = '4', storedetaildate = '2021-12-15 13:33:01' WHERE storedetailid = '1516';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('463', '7', '1', '0', '95', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '23.00', '24', '4', '2021-12-15 13:33:01','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', '95', '1', '515', '1', '210', '210', '0', '', '0', '0', '515', '0.00', '0','7','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 = 150;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (515, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 210, 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+210, 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, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 210, 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+210, returnSellCostBuyPrice = returnSellCostBuyPrice+220, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+220
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+220, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+220
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+220
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '14', userid = '4', storedetaildate = '2021-12-15 13:33:01' WHERE storedetailid = '1299';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('515', '7', '1', '0', '95', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '13.00', '14', '4', '2021-12-15 13:33:01','0','0');
INSERT INTO returnsellbilldetail (buyprice, parcode, returnsellbillid, returnsellbilldetailcatid, returnsellbilldetailproductid, returnsellbilldetailquantity, returnsellbilldetailprice, returnsellbilldetailtotalprice, conditions, note, pricetype, discountvalue, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,pricetypepro) VALUES ('210.00', '00127', '95', '1', '127', '1', '220', '220', '0', '', '0', '0', '127', '0.00', '0','7','0','','','0','0','0','0','0','0');
UPDATE returnsellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 1148.55, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 1148.55
                where returnsellbilldetailid = 151;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (127, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 220, 210, 210, 1148.55
                    , 210, 1148.55, 0, 0, 1)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+220, returnSellCostBuyPrice = returnSellCostBuyPrice+210, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+210
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+1148.55, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+210
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+1148.55
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+0
                        , netQuantityRet = netQuantityRet+1;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (7, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 220, 210, 210, 1148.55
                    , 210, 1148.55, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+220, returnSellCostBuyPrice = returnSellCostBuyPrice+210, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+210
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+1148.55, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+210
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+1148.55
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '1', userid = '4', storedetaildate = '2021-12-15 13:33:01' WHERE storedetailid = '1581';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('127', '7', '1', '0', '95', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '0.00', '1', '4', '2021-12-15 13:33:01','0','0');
UPDATE save SET  savecurrentvalue = '305',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('935.00','630', '1', '7', 'اضافة فاتورة مردوات مبيعات', '95', '305', '2021-12-15 13:33:01', '4',  'returnsellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 630, 620, 620, 1558.55
                    , 620, 1558.55, 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+630, returnSellCostBuyPrice = returnSellCostBuyPrice+620, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+620
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+1558.55, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+620
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+1558.55
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 630, 620, 620, 1558.55
                    , 620, 1558.55, 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+630, returnSellCostBuyPrice = returnSellCostBuyPrice+620, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+620
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+1558.55, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+620
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+1558.55
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -630, -620, -620
                    , -1558.55, -620, -1558.55, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-630, netSellCostBuyPrice = netSellCostBuyPrice+-620
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-620
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-1558.55
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-620
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-1558.55
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9d2199c674 and sellbillId = 95 and returnsellbillId = 95
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:03:01";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 13:33:01", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 13:33:01', '4', 'addsellBill', '197.61.178.123', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:03:10";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 13:33:10", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 13:33:10', '4', 'addsellBill', '197.61.178.123', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:04:10";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 13:34:10", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 13:34:10', '4', 'addAndRetuen', '197.61.178.123', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b9d276c1bb1
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-15 13:33:10', '061b9d276c1bb1', '1', '0.00', '0', '20', '1', '945', '925', '925', '0', '7', '2021-12-15 13:34:10', '', '4', '0', 'نقدي', '7', '0', '3', '0', 'نقدي', '4' ,'0','','','','','-1','0','0','0','0','0','925','0','','0','0','925','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','اضافة فاتورة مبيعات','320', '0', '2021-12-15 13:34:10', '4', 'sellbillController.php', 'اضافة فاتورة مبيعات', '925', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2224;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('230','00590', '320', '1', '590', '1', '235.00', '235', '0', '', '0', '2021-12-15 13:34:10', '590', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','2224-1,');
UPDATE sellbilldetail SET  lastbuyprice = 230.00 , meanbuyprice = 230.00, lastbuyprice_withDiscount = 230.00, meanbuyprice_withDiscount = 230.00
                where sellbilldetailid = 668;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (590, '2021-12-15', 230.026455026, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+230.026455026, sellCostBuyPrice =sellCostBuyPrice+230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+230
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (7, '2021-12-15', 230.026455026, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+230.026455026, sellCostBuyPrice =sellCostBuyPrice+230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+230
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '6', userid = '4', storedetaildate = '2021-12-15 13:34:10' WHERE storedetailid = '1670';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '7', '1', '1', '320', 'اضافة فاتورة مبيعات', 'sellbillController.php', '7.00', '6', '4', '2021-12-15 13:34:10','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2008;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('220','00585', '320', '1', '585', '1', '225', '225', '0', '', '0', '2021-12-15 13:34:10', '585', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','2008-1,');
UPDATE sellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where sellbilldetailid = 669;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (585, '2021-12-15', 220.238095238, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+220.238095238, 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, '2021-12-15', 220.238095238, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+220.238095238, 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 = '23', userid = '4', storedetaildate = '2021-12-15 13:34:10' WHERE storedetailid = '1555';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('585', '7', '1', '1', '320', 'اضافة فاتورة مبيعات', 'sellbillController.php', '24.00', '23', '4', '2021-12-15 13:34:10','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2010;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('230','00589', '320', '1', '589', '1', '235', '235', '0', '', '0', '2021-12-15 13:34:10', '589', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','2010-1,');
UPDATE sellbilldetail SET  lastbuyprice = 230.00 , meanbuyprice = 230.00, lastbuyprice_withDiscount = 230.00, meanbuyprice_withDiscount = 230.00
                where sellbilldetailid = 670;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (589, '2021-12-15', 230.026455026, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+230.026455026, sellCostBuyPrice =sellCostBuyPrice+230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+230
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (7, '2021-12-15', 230.026455026, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+230.026455026, sellCostBuyPrice =sellCostBuyPrice+230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+230
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '5', userid = '4', storedetaildate = '2021-12-15 13:34:10' WHERE storedetailid = '1573';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '7', '1', '1', '320', 'اضافة فاتورة مبيعات', 'sellbillController.php', '6.00', '5', '4', '2021-12-15 13:34:10','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1518;
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 ('235','00540', '320', '1', '540', '1', '250', '250', '0', '', '0', '2021-12-15 13:34:10', '540', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','1518-1,');
UPDATE sellbilldetail SET  lastbuyprice = 235.00 , meanbuyprice = 235.00, lastbuyprice_withDiscount = 235.00, meanbuyprice_withDiscount = 235.00
                where sellbilldetailid = 671;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (540, '2021-12-15', 244.708994709, 235, 235
                    , 235, 235, 235, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+244.708994709, sellCostBuyPrice =sellCostBuyPrice+235
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+235, sellCostMeanBuyPrice = sellCostMeanBuyPrice+235
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+235, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+235
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (7, '2021-12-15', 244.708994709, 235, 235
                    , 235, 235, 235, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+244.708994709, sellCostBuyPrice =sellCostBuyPrice+235
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+235, sellCostMeanBuyPrice = sellCostMeanBuyPrice+235
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+235, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+235
                            , 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 = '2021-12-15 13:34:10' WHERE storedetailid = '1310';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('540', '7', '1', '1', '320', 'اضافة فاتورة مبيعات', 'sellbillController.php', '14.00', '13', '4', '2021-12-15 13:34:10','0','0');
UPDATE save SET  savecurrentvalue = '1230',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('305.00','925', '0', '7', 'اضافة فاتورة مبيعات', '320', '1230', '2021-12-15 13:34:10', '4',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 925, 915, 915
                    , 915, 915, 915, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+925, sellCostBuyPrice =sellCostBuyPrice+915
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+915, sellCostMeanBuyPrice = sellCostMeanBuyPrice+915
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+915, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+915
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-15', 925, 915, 915
                    , 915, 915, 915, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+925, sellCostBuyPrice =sellCostBuyPrice+915
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+915, sellCostMeanBuyPrice = sellCostMeanBuyPrice+915
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+915, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+915
                            , 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, 925, 915, 915
                    , 915, 915, 915, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+925, netSellCostBuyPrice = netSellCostBuyPrice+915
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+915
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+915
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+915
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+915
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9d276c1bb1 and sellbillId = 320 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:04:11";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 13:34:11", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 13:34:11', '4', 'addsellBill', '197.61.178.123', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:04:18";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 13:34:18", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-15 13:34:18', '4', '', '197.61.178.123', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:04:25";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 13:34:25", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 13:34:25', '4', '', '197.61.178.123', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:06:16";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 13:36:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-15 13:36:16', '1', '', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:06:28";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 13:36:28", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-15 13:36:28', '1', 'show', '197.56.115.45', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:07:05";
UPDATE user SET loginip = "197.56.115.45", lastactivetime = "2021-12-15 13:37:05", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-15 13:37:05', '1', 'show', '197.56.115.45', '', 'DESKTOP');
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:13:56";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 13:43:56", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-15 13:43:56', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:13:56";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:13:59";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 13:43:59", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 13:43:59', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:52:31";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:22:31", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-15 14:22:31', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:52: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 < "2021-12-15 10:52:34";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:22:34", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:22:34', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:53:08";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:23:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:23:08', '1', '', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:53:17";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:23:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:23:17', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:55:13";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:25:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:25:13', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '12', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '352';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('352', '1', '12', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '12', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:55:15";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:25:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:25:15', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:55:22";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:25:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:25:22', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:55:25";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:25:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:25:25', '1', 'edit', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:55:42";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:25:42", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:25:42', '1', 'update', '41.233.39.117', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 352;
UPDATE productunit SET unitid = '1', productid = '352', productnumber = '1.00', productunitdate = '2021-12-15', userid = '1', conditions = '0',proUnitParcode='0035201',proUnitSellAllPrice='135',proUnitSellHalfPrice='135',proUnitSellUnitPrice ='160',proUnitBuyPrice='120' WHERE productunitid = '352';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (352, 1,'2021-12-15 14:25:42',1)
                ON DUPLICATE KEY UPDATE productid = 352, edited = 1, sysdate = '2021-12-15 14:25:42', userid = 1;
UPDATE product SET productName = 'دكرون 338', productDescription = '', productCatId = '1', productBuyPrice = '120', productSellAllPrice = '150', productSellUnitPrice = '180', productSellHalfPrice = '160', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00352',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '120.00',lastbuyprice_withDiscount = '120',meanbuyprice = '120.00',meanbuyprice_withDiscount = '120' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '25' , buyhalf_precentage = '33.33' , buypart_precentage = '50',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '352';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:55:44";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:25:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:25:44', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:56:30";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:26:30", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:26:30', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '19', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '364';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('364', '1', '19', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '19', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:56:32";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:26:32", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:26:32', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:56:41";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:26:42", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:26:42', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:56:46";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:26:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:26:46', '1', 'edit', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:57:06";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:27:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:27:06', '1', 'update', '41.233.39.117', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 364;
UPDATE productunit SET unitid = '1', productid = '364', productnumber = '1.00', productunitdate = '2021-12-15', userid = '1', conditions = '0',proUnitParcode='0036401',proUnitSellAllPrice='135',proUnitSellHalfPrice='145',proUnitSellUnitPrice ='160',proUnitBuyPrice='120' WHERE productunitid = '364';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (364, 1,'2021-12-15 14:27:06',1)
                ON DUPLICATE KEY UPDATE productid = 364, edited = 1, sysdate = '2021-12-15 14:27:06', userid = 1;
UPDATE product SET productName = 'دكرون 356', productDescription = '', productCatId = '1', productBuyPrice = '120', productSellAllPrice = '150', productSellUnitPrice = '180', productSellHalfPrice = '160', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00364',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '120.00',lastbuyprice_withDiscount = '120',meanbuyprice = '120.00',meanbuyprice_withDiscount = '120' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '25' , buyhalf_precentage = '33.33' , buypart_precentage = '50',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '364';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:57:08";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:27:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:27:08', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:58:29";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:28:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:28:29', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:59:50";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:29:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:29:50', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '17', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '359';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('359', '1', '17', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '17', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:59:52";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:29:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:29:52', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 10:59:58";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:29:58", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:29:58', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:00:04";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:30:04", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:30:04', '1', 'edit', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:00:18";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:30:18", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:30:18', '1', 'update', '41.233.39.117', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 359;
UPDATE productunit SET unitid = '1', productid = '359', productnumber = '1.00', productunitdate = '2021-12-15', userid = '1', conditions = '0',proUnitParcode='0035901',proUnitSellAllPrice='135',proUnitSellHalfPrice='145',proUnitSellUnitPrice ='160',proUnitBuyPrice='120' WHERE productunitid = '359';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (359, 1,'2021-12-15 14:30:18',1)
                ON DUPLICATE KEY UPDATE productid = 359, edited = 1, sysdate = '2021-12-15 14:30:18', userid = 1;
UPDATE product SET productName = 'دكرون 347', productDescription = '', productCatId = '1', productBuyPrice = '120', productSellAllPrice = '150', productSellUnitPrice = '180', productSellHalfPrice = '160', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00359',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '120.00',lastbuyprice_withDiscount = '120',meanbuyprice = '120.00',meanbuyprice_withDiscount = '120' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '25' , buyhalf_precentage = '33.33' , buypart_precentage = '50',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '359';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:00:20";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:30:20", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:30:20', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:01:01";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:31:01", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:31:01', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '69', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '74';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('74', '1', '25', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '44.00', '69', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:01:03";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:31:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:31:03', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:01:09";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 14:31:09", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:31:09', '4', 'addsellBill', '197.61.178.123', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:01:11";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:31:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:31:11', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:01:14";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:31:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:31:14', '1', 'edit', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:02:04";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:32:04", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:32:04', '1', 'update', '41.233.39.117', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 74;
UPDATE productunit SET unitid = '1', productid = '74', productnumber = '1.00', productunitdate = '2021-12-15', userid = '1', conditions = '0',proUnitParcode='0007401',proUnitSellAllPrice='175',proUnitSellHalfPrice='185',proUnitSellUnitPrice ='205',proUnitBuyPrice='165' WHERE productunitid = '74';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (74, 1,'2021-12-15 14:32:04',1)
                ON DUPLICATE KEY UPDATE productid = 74, edited = 1, sysdate = '2021-12-15 14:32:04', userid = 1;
UPDATE product SET productName = '473', productDescription = '', productCatId = '1', productBuyPrice = '150', productSellAllPrice = '150', productSellUnitPrice = '180', productSellHalfPrice = '160', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00074',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '165.00',lastbuyprice_withDiscount = '165',meanbuyprice = '157.5',meanbuyprice_withDiscount = '157.5' , productbuypricereal = '150' , buypricereal_precentage = '0' , buytotal_precentage = '0' , buyhalf_precentage = '6.67' , buypart_precentage = '20',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '74';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:02:06";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:32:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:32:06', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:02:30";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:32:30", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:32:30', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '7', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '340';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('340', '1', '7', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '7', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:02:32";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:32:32", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:32:32', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:02:41";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:32:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:32:41', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:02:46";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:32:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:32:46', '1', 'edit', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:03:00";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:33:00", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:33:01', '1', 'update', '41.233.39.117', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 340;
UPDATE productunit SET unitid = '1', productid = '340', productnumber = '1.00', productunitdate = '2021-12-15', userid = '1', conditions = '0',proUnitParcode='0034001',proUnitSellAllPrice='135',proUnitSellHalfPrice='135',proUnitSellUnitPrice ='160',proUnitBuyPrice='120' WHERE productunitid = '340';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (340, 1,'2021-12-15 14:33:01',1)
                ON DUPLICATE KEY UPDATE productid = 340, edited = 1, sysdate = '2021-12-15 14:33:01', userid = 1;
UPDATE product SET productName = 'دكرون 324', productDescription = '', productCatId = '1', productBuyPrice = '120', productSellAllPrice = '150', productSellUnitPrice = '180', productSellHalfPrice = '160', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00340',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '120.00',lastbuyprice_withDiscount = '120',meanbuyprice = '120.00',meanbuyprice_withDiscount = '120' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '25' , buyhalf_precentage = '33.33' , buypart_precentage = '50',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '340';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:03:03";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:33:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:33:03', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:05:00";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:35:00", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:35:00', '1', '', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:06:05";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:36:05", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:36:05', '1', 'add', '41.233.39.117', '', 'DESKTOP');
BEGIN;
INSERT INTO product (productName, productDescription, productCatId, productBuyPrice, productSellAllPrice, productSellUnitPrice, productSellHalfPrice, productDate, conditions, userId, limitamount, parcode,type, expireDate, dailyentryId,isService,isOptic,lastbuyprice,lastbuyprice_withDiscount,meanbuyprice,meanbuyprice_withDiscount , productbuypricereal , buypricereal_precentage , buytotal_precentage , buyhalf_precentage , buypart_precentage,logo,inMenu,obygyDetectionId,hasSizeAndColor,overAllAveragePrice,reviewType,online,updatebyuser,proExcelid,proExcelParcode,webApiId) VALUES ('341 امهات','','1','120','150', '180','160', '2021-12-15', '0', '1', '0', '', '0', '0', '0', '0', '0', '120','120','120','120','120','0','25','33.33','50','.','0','0','0','0','0','','','0','0','0');
UPDATE product SET productName = '341 امهات', productDescription = '', productCatId = '1', productBuyPrice = '120', productSellAllPrice = '150', productSellUnitPrice = '180', productSellHalfPrice = '160', productDate = '2021-12-15', conditions = '0', userId = '1', limitamount = '0', parcode = '00609',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '120',lastbuyprice_withDiscount = '120',meanbuyprice = '120',meanbuyprice_withDiscount = '120' , productbuypricereal = '120' , buypricereal_precentage = '0' , buytotal_precentage = '25' , buyhalf_precentage = '33.33' , buypart_precentage = '50',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '609';
INSERT INTO productunit (unitid, productid, productnumber, productunitdate, userid, conditions,proUnitParcode,proUnitSellAllPrice,proUnitSellHalfPrice,proUnitSellUnitPrice,proUnitBuyPrice) VALUES ('1', '609', '1', '2021-12-15', '1', '0','0060901','150','160','180','120');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('609', '1', '8', '1', '2021-12-15');
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('609', '1', '8', '0', '609', 'إضافة منتج', 'productController.php', '0', '8', '1', '2021-12-15','0','0');
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (609, 1,'2021-12-15 14:36:05',1)
                ON DUPLICATE KEY UPDATE productid = 609, edited = 1, sysdate = '2021-12-15 14:36:05', userid = 1;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '960', '960', '2021-12-15', '1', '0', '0', '2021-12-15 14:36:05','إضافة منتج 341 امهات الكمية 8','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('846', '19', '960', '','0');
UPDATE accountstree SET name = 'البضاعة (بضاعة أول المدة)', customName = 'البضاعة (بضاعة أول المدة)', parent = '6', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '6151806.35', theOrder = '0', layingOrder = '121',reportid = '0' WHERE id = '19';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('846', '7', '960', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '7003192.15', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
UPDATE product SET productName = '341 امهات', productDescription = '', productCatId = '1', productBuyPrice = '120.00', productSellAllPrice = '150.00', productSellUnitPrice = '180.00', productSellHalfPrice = '160.00', productDate = '2021-12-15', conditions = '0', userId = '1', limitamount = '0', parcode = '00609',type ='0', expireDate = '0' , dailyentryId = '846',isService = '0',isOptic = '0',lastbuyprice = '120',lastbuyprice_withDiscount = '120',meanbuyprice = '120',meanbuyprice_withDiscount = '120' , productbuypricereal = '120' , buypricereal_precentage = '0' , buytotal_precentage = '25' , buyhalf_precentage = '33.33' , buypart_precentage = '50',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '609';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:06:07";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:36:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:36:07', '1', '', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:06:21";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:36:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:36:22', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '8', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '1691';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('609', '1', '8', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية لم يتغير', 'inventoryController.php', '8.00', '8', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:06:23";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:36:23", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:36:23', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:06:43";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:36:43", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:36:43', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '18', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '52';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('52', '1', '18', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '18', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:06:45";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:36:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:36:45', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:06:54";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:36:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:36:54', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:06:59";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:36:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:36:59', '1', 'edit', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:07:16";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:37:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:37:16', '1', 'update', '41.233.39.117', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 52;
UPDATE productunit SET unitid = '1', productid = '52', productnumber = '1.00', productunitdate = '2021-12-15', userid = '1', conditions = '0',proUnitParcode='0005201',proUnitSellAllPrice='135',proUnitSellHalfPrice='145',proUnitSellUnitPrice ='165',proUnitBuyPrice='125' WHERE productunitid = '52';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (52, 1,'2021-12-15 14:37:16',1)
                ON DUPLICATE KEY UPDATE productid = 52, edited = 1, sysdate = '2021-12-15 14:37:16', userid = 1;
UPDATE product SET productName = '334', productDescription = '', productCatId = '1', productBuyPrice = '125', productSellAllPrice = '150', productSellUnitPrice = '180', productSellHalfPrice = '160', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00052',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '125.00',lastbuyprice_withDiscount = '125',meanbuyprice = '125.00',meanbuyprice_withDiscount = '125' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '20' , buyhalf_precentage = '28' , buypart_precentage = '44',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '52';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:07:18";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:37:18", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:37:18', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:07:47";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:37:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:37:47', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:08:23";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:38:23", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:38:23', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '52';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('52', '1', '18', '1', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالنقص', 'inventoryController.php', '18.00', '0', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:08:25";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:38:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:38:25', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:09:01";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:39:01", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:39:01', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '30', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '352';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('352', '1', '18', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '12.00', '30', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:09:05";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:39:05", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:39:05', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:09:13";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:39:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:39:13', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:09:49";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:39:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:39:49', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '36', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '364';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('364', '1', '17', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '19.00', '36', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:09:53";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:39:53", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:39:53', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:09:59";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:39:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 14:39:59', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:10:50";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:40:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:40:50', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '34', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '359';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('359', '1', '17', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '17.00', '34', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:10:54";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:40:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:40:54', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:11:38";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:41:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:41:38', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '12', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '342';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('342', '1', '5', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '7.00', '12', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:11:40";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:41:40", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 14:41:40', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:12:12";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:42:14", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 14:42:14', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:12:14";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:42:14", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 14:42:14', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:12:18";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:42:18", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:42:18', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:12:19";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:42:19", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:42:19', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:14:39";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:44:39", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:44:39', '5', 'addAndRetuen', '41.45.236.6', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b9e2ab3f20f
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-15 14:42:19', '061b9e2ab3f20f', '1', '0.00', '0', '0', '1', '1210', '1210', '1210', '0', '3', '2021-12-15 14:44:39', '', '5', '0', 'نقدي', '3', '0', '3', '0', 'نقدي', '5' ,'0','','','','','-1','0','0','0','0','0','1210','0','','0','0','1210','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '5' WHERE clientid = '1';
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('1','0.00','0','0','اضافة فاتورة مبيعات','321', '0', '2021-12-15 14:44:39', '5', 'sellbillController.php', 'اضافة فاتورة مبيعات', '1210', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+3 where id = 2056;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('230','00590', '321', '1', '590', '3', '245.00', '735', '0', '', '2', '2021-12-15 14:44:39', '590', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','2056-3,');
UPDATE sellbilldetail SET  lastbuyprice = 230.00 , meanbuyprice = 230.00, lastbuyprice_withDiscount = 230.00, meanbuyprice_withDiscount = 230.00
                where sellbilldetailid = 672;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (590, '2021-12-15', 735, 690, 690
                    , 690, 690, 690, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 3, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+735, sellCostBuyPrice =sellCostBuyPrice+690
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+690, sellCostMeanBuyPrice = sellCostMeanBuyPrice+690
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+690, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+690
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+3
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2021-12-15', 735, 690, 690
                    , 690, 690, 690, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+735, sellCostBuyPrice =sellCostBuyPrice+690
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+690, sellCostMeanBuyPrice = sellCostMeanBuyPrice+690
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+690, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+690
                            , 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 = '2021-12-15 14:44:39' WHERE storedetailid = '1585';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '3', '3', '1', '321', 'اضافة فاتورة مبيعات', 'sellbillController.php', '30.00', '27', '5', '2021-12-15 14:44:39','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1882;
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', '321', '1', '560', '1', '235', '235', '0', '', '2', '2021-12-15 14:44:39', '560', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','1882-1,');
UPDATE sellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where sellbilldetailid = 673;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (560, '2021-12-15', 235, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+235, 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 (3, '2021-12-15', 235, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+235, 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 = '61', userid = '5', storedetaildate = '2021-12-15 14:44:39' WHERE storedetailid = '1501';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('560', '3', '1', '1', '321', 'اضافة فاتورة مبيعات', 'sellbillController.php', '62.00', '61', '5', '2021-12-15 14:44:39','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1880;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('150','00565', '321', '1', '565', '1', '240', '240', '0', '', '2', '2021-12-15 14:44:39', '565', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','1880-1,');
UPDATE sellbilldetail SET  lastbuyprice = 150.00 , meanbuyprice = 150.00, lastbuyprice_withDiscount = 150.00, meanbuyprice_withDiscount = 150.00
                where sellbilldetailid = 674;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (565, '2021-12-15', 240, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+240, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+150, sellCostMeanBuyPrice = sellCostMeanBuyPrice+150
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+150, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+150
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2021-12-15', 240, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+240, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+150, sellCostMeanBuyPrice = sellCostMeanBuyPrice+150
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+150, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+150
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '28', userid = '5', storedetaildate = '2021-12-15 14:44:39' WHERE storedetailid = '1500';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '3', '1', '1', '321', 'اضافة فاتورة مبيعات', 'sellbillController.php', '29.00', '28', '5', '2021-12-15 14:44:39','0','0');
UPDATE save SET  savecurrentvalue = '6795',  userid = '5' WHERE saveid = '3';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('5585.00','1210', '0', '3', 'اضافة فاتورة مبيعات', '321', '6795', '2021-12-15 14:44:39', '5',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 1210, 1060, 1060
                    , 1060, 1060, 1060, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1210, sellCostBuyPrice =sellCostBuyPrice+1060
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1060, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1060
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1060, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1060
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-15', 1210, 1060, 1060
                    , 1060, 1060, 1060, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1210, sellCostBuyPrice =sellCostBuyPrice+1060
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1060, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1060
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1060, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1060
                            , 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, 1210, 1060, 1060
                    , 1060, 1060, 1060, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+1210, netSellCostBuyPrice = netSellCostBuyPrice+1060
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+1060
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+1060
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+1060
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+1060
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9e2ab3f20f and sellbillId = 321 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:14:40";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:44:40", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:44:40', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:14:45";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:44:46", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:44:46', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:14:46";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:44:46", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:44:46', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:15:17";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:45:17", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:45:17', '5', 'addAndRetuen', '41.45.236.6', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b9e33e857ec
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO returnsellbill (returnsellbilldate, returnsellbillserial, returnsellbillclientid, returnsellbilltotaldeptbefor, returnsellbilltotaldeptafter, returnsellbilldiscount, returnsellbilldiscounttype, returnsellbilltotalbill, returnsellbillaftertotalbill, returnsellbilltotalpayed, returnsellbillfinalbill, returnsellbillstoreid, returnsellbillsysdate,comment, userid, conditions, returnsellbillclientname, returnsellbillsaveid, returnsellbildirectpayment, billnameid, sellerid, tempclientName, returnsellQuantity,tax, carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,delbyuserid,billReservation,billReservationDate,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal) VALUES ('2021-12-15 14:44:46', '061b9e33e857ec', '1', '0.00', '0', '0', '1', '250', '250', '-250', '0', '3', '2021-12-15 14:45:17', '', '5', '0', 'نقدي','3', '0', '5', '0', 'نقدي', '1', '0', '', '','','','-1','0','0','0','','0','-250','0','0','0','0','0','0');
UPDATE client SET  clientdebt = '0', userid = '5' WHERE clientid = '1';
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('1','0.00','0','1','اضافة فاتورة مردوات مبيعات','96', '0', '2021-12-15 14:45:17', '5', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '250', '0', null, '0', null, null,'', '0','1','1','0','1');
INSERT INTO returnsellbilldetail (buyprice, parcode, returnsellbillid, returnsellbilldetailcatid, returnsellbilldetailproductid, returnsellbilldetailquantity, returnsellbilldetailprice, returnsellbilldetailtotalprice, conditions, note, pricetype, discountvalue, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,pricetypepro) VALUES ('195.00', '00556', '96', '1', '556', '1', '250.00', '250', '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 = 152;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (556, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 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+250, 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, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 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+250, returnSellCostBuyPrice = returnSellCostBuyPrice+195, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+195
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+195, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+195
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+195
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '6', userid = '5', storedetaildate = '2021-12-15 14:45:17' WHERE storedetailid = '1503';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('556', '3', '1', '0', '96', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '5.00', '6', '5', '2021-12-15 14:45:17','0','0');
UPDATE save SET  savecurrentvalue = '6545',  userid = '5' WHERE saveid = '3';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('6795.00','250', '1', '3', 'اضافة فاتورة مردوات مبيعات', '96', '6545', '2021-12-15 14:45:17', '5',  'returnsellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 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+250, 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 (1, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 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+250, 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, -250, -195, -195
                    , -195, -195, -195, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-250, netSellCostBuyPrice = netSellCostBuyPrice+-195
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-195
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-195
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-195
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-195
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9e33e857ec and sellbillId = 96 and returnsellbillId = 96
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:15:18";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:45:18", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:45:18', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:15:32";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:45:32", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:45:32', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:15:32";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:45:32", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:45:32', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
INSERT INTO client (clientname, clientaddress, clientphone, clientmobile, clientdebt, clientdetails, conditions, clientdate, userid,clientareaid,clientcode,dailyentryid ,rondomtxt,clientStoreIds,obygyPatientId,debtLimit,typeclientid,priceTypeId,card_number,file_faida,specialDiscount,specialDiscountVal,file,addDate,mandobCollectRatio,webApiId,clientRFID,linkedSupplierId,postponeDays,studentid) VALUES ('ام عبده اسكندريه' , '', '', '', '0', '', '0', '2021-12-15 14:46:51', '5', '0','','0','','-10','0','10000',',-20,','-1','0','.','0','0','.','2021-12-15','0','0','','0','0','0');
INSERT INTO tamweenclientdetail (clientid, noOfPersonsTamween, noOfPersonsDa3m, cardNum, cardPassword) VALUES ('93', '0', '0', '', '');
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 ('93','0','0','0','إضافة عميل جديد','93', '0', '2021-12-15 14:46:51', '5', 'clientController.php', '', '0', '0', null, '0', null, null,'', '0','1','1','0','1');
INSERT INTO accountstree (name, customName, parent, itemtype, itemfrom, notes, del, userid, mydate, itemtype2, theValue, theOrder, layingOrder,reportid) VALUES ('ام عبده اسكندريه', 'ام عبده اسكندريه', '23', '3', '0', '', '0', '5', '2021-12-15', '1', '0', '0', '','2');
UPDATE client SET clientname = 'ام عبده اسكندريه', clientaddress = '', clientphone = '', clientmobile = '', clientdebt = '0.00', clientdetails = '', conditions = '0', clientdate = '2021-12-15', userid = '5'  , clientareaid = '0'  ,clientcode = '',dailyentryid = '0' , rondomtxt = '',clientStoreIds = '-10', obygyPatientId = '0' , debtLimit='10000' , typeclientid=',-20,',priceTypeId='-1',lastEditUser = '0',card_number = '0',file_faida = '.',specialDiscount = '0',specialDiscountVal = '0',file = '.',mandobCollectRatio='0',clientRFID = '',linkedSupplierId = '0',postponeDays='0', studentid='0' WHERE clientid = '93';
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:16:53";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 14:46:53", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-15 14:46:54', '1', 'show', '41.233.39.117', '', 'DESKTOP');
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:17:27";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 14:47:27", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-15 14:47:27', '7', '', '156.160.238.195', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:17:27";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:17:32";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 14:47:33", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:47:33', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:19:53";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:49:53", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:49:53', '5', 'addAndRetuen', '41.45.236.6', '', '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 061b9e36c97311
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(93,@clientdebt,@clientname);
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-15 14:45:32', '061b9e36c97311', '93', '0.00', '665', '10', '1', '1475', '1465', '800', '665', '3', '2021-12-15 14:49:54', '', '5', '0', 'ام عبده اسكندريه', '3', '1', '3', '0', 'ام عبده اسكندريه', '6' ,'0','','','','','-1','0','0','0','0','0','1465','0','','0','0','800','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '665', userid = '5' WHERE clientid = '93';
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 ('93','0.00','665','0','اضافة فاتورة مبيعات','322', '665', '2021-12-15 14:49:54', '5', 'sellbillController.php', 'اضافة فاتورة مبيعات', '1465', '0', null, '0', null, null,'', '0','1','1','665','1');
UPDATE client SET  inUse = 0 where clientid = 93;
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+2 where id = 2020;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('230','00589', '322', '1', '589', '2', '245.00', '490', '0', '', '2', '2021-12-15 14:49:54', '589', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','2020-2,');
UPDATE sellbilldetail SET  lastbuyprice = 230.00 , meanbuyprice = 230.00, lastbuyprice_withDiscount = 230.00, meanbuyprice_withDiscount = 230.00
                where sellbilldetailid = 675;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (589, '2021-12-15', 486.677966102, 460, 460
                    , 460, 460, 460, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 2, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+486.677966102, sellCostBuyPrice =sellCostBuyPrice+460
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+460, sellCostMeanBuyPrice = sellCostMeanBuyPrice+460
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+460, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+460
                            , 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, '2021-12-15', 486.677966102, 460, 460
                    , 460, 460, 460, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+486.677966102, sellCostBuyPrice =sellCostBuyPrice+460
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+460, sellCostMeanBuyPrice = sellCostMeanBuyPrice+460
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+460, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+460
                            , 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 = '5', storedetaildate = '2021-12-15 14:49:54' WHERE storedetailid = '1576';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '3', '2', '1', '322', 'اضافة فاتورة مبيعات', 'sellbillController.php', '19.00', '17', '5', '2021-12-15 14:49:54','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1806;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('280','00450', '322', '1', '450', '1', '270.00', '270', '0', '', '2', '2021-12-15 14:49:54', '450', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','1806-1,');
UPDATE sellbilldetail SET  lastbuyprice = 280.00 , meanbuyprice = 267.50, lastbuyprice_withDiscount = 280.00, meanbuyprice_withDiscount = 267.50
                where sellbilldetailid = 676;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (450, '2021-12-15', 268.169491525, 255, 280
                    , 267.5, 280, 267.5, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+268.169491525, sellCostBuyPrice =sellCostBuyPrice+255
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+280, sellCostMeanBuyPrice = sellCostMeanBuyPrice+267.5
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+280, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+267.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 (3, '2021-12-15', 268.169491525, 255, 280
                    , 267.5, 280, 267.5, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+268.169491525, sellCostBuyPrice =sellCostBuyPrice+255
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+280, sellCostMeanBuyPrice = sellCostMeanBuyPrice+267.5
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+280, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+267.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 = '107', userid = '5', storedetaildate = '2021-12-15 14:49:54' WHERE storedetailid = '1453';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('450', '3', '1', '1', '322', 'اضافة فاتورة مبيعات', 'sellbillController.php', '108.00', '107', '5', '2021-12-15 14:49:54','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1880;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('150','00565', '322', '1', '565', '1', '240.00', '240', '0', '', '2', '2021-12-15 14:49:54', '565', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','1880-1,');
UPDATE sellbilldetail SET  lastbuyprice = 150.00 , meanbuyprice = 150.00, lastbuyprice_withDiscount = 150.00, meanbuyprice_withDiscount = 150.00
                where sellbilldetailid = 677;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (565, '2021-12-15', 238.372881356, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+238.372881356, sellCostBuyPrice =sellCostBuyPrice+150
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+150, sellCostMeanBuyPrice = sellCostMeanBuyPrice+150
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+150, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+150
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2021-12-15', 238.372881356, 150, 150
                    , 150, 150, 150, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+238.372881356, 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 = '27', userid = '5', storedetaildate = '2021-12-15 14:49:54' WHERE storedetailid = '1500';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('565', '3', '1', '1', '322', 'اضافة فاتورة مبيعات', 'sellbillController.php', '28.00', '27', '5', '2021-12-15 14:49:54','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2056;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('230','00590', '322', '1', '590', '1', '245', '245', '0', '', '2', '2021-12-15 14:49:54', '590', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','2056-1,');
UPDATE sellbilldetail SET  lastbuyprice = 230.00 , meanbuyprice = 230.00, lastbuyprice_withDiscount = 230.00, meanbuyprice_withDiscount = 230.00
                where sellbilldetailid = 678;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (590, '2021-12-15', 243.338983051, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+243.338983051, sellCostBuyPrice =sellCostBuyPrice+230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+230
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2021-12-15', 243.338983051, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+243.338983051, sellCostBuyPrice =sellCostBuyPrice+230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+230
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '26', userid = '5', storedetaildate = '2021-12-15 14:49:54' WHERE storedetailid = '1585';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '3', '1', '1', '322', 'اضافة فاتورة مبيعات', 'sellbillController.php', '27.00', '26', '5', '2021-12-15 14:49:54','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1890;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('210','00563', '322', '1', '563', '1', '230', '230', '0', '', '2', '2021-12-15 14:49:54', '563', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','1890-1,');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 210.00, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 210.00
                where sellbilldetailid = 679;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (563, '2021-12-15', 228.440677966, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+228.440677966, 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 (3, '2021-12-15', 228.440677966, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+228.440677966, 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 = '5', storedetaildate = '2021-12-15 14:49:54' WHERE storedetailid = '1505';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '3', '1', '1', '322', 'اضافة فاتورة مبيعات', 'sellbillController.php', '12.00', '11', '5', '2021-12-15 14:49:54','0','0');
UPDATE save SET  savecurrentvalue = '7345',  userid = '5' WHERE saveid = '3';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('6545.00','800', '0', '3', 'اضافة فاتورة مبيعات', '322', '7345', '2021-12-15 14:49:54', '5',  'sellbillController.php','93','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 1465, 1305, 1330
                    , 1317.5, 1330, 1317.5, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1465, sellCostBuyPrice =sellCostBuyPrice+1305
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1330, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1317.5
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1330, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1317.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 (93, '2021-12-15', 1465, 1305, 1330
                    , 1317.5, 1330, 1317.5, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1465, sellCostBuyPrice =sellCostBuyPrice+1305
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1330, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1317.5
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1330, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1317.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, 1465, 1305, 1330
                    , 1317.5, 1330, 1317.5, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+1465, netSellCostBuyPrice = netSellCostBuyPrice+1305
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+1330
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+1317.5
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+1330
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+1317.5
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9e36c97311 and sellbillId = 322 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:19:54";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:49:54", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:49:54', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:20:35";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 14:50:35", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 14:50:35', '4', '', '197.61.178.123', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:20:39";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 14:50:39", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:50:40', '4', 'addsellBill', '197.61.178.123', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:21:26";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 14:51:26", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:51:26', '7', 'addAndRetuen', '156.160.238.195', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b9e3e54d769
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-15 14:47:33', '061b9e3e54d769', '1', '0.00', '0', '0', '1', '765', '765', '765', '0', '5', '2021-12-15 14:51:26', '', '7', '0', 'نقدي', '5', '0', '3', '0', 'نقدي', '3' ,'0','','','','','-1','0','0','0','0','0','765','0','','0','0','765','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','اضافة فاتورة مبيعات','323', '0', '2021-12-15 14:51:26', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '765', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 720;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('210','00251', '323', '1', '251', '1', '245', '245', '0', '', '2', '2021-12-15 14:51:26', '251', '0.00', '0', '5','0','','','0','0','0','0','0','0','2','0','','720-1,');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 210.00, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 210.00
                where sellbilldetailid = 680;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (251, '2021-12-15', 245, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+245, 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, '2021-12-15', 245, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+245, 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 = '2021-12-15 14:51:26' WHERE storedetailid = '911';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('251', '5', '1', '1', '323', 'اضافة فاتورة مبيعات', 'sellbillController.php', '12.00', '11', '7', '2021-12-15 14:51:26','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 738;
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 ('255','00255', '323', '1', '255', '1', '275', '275', '0', '', '2', '2021-12-15 14:51:26', '255', '0.00', '0', '5','0','','','0','0','0','0','0','0','2','0','','738-1,');
UPDATE sellbilldetail SET  lastbuyprice = 255.00 , meanbuyprice = 255.00, lastbuyprice_withDiscount = 255.00, meanbuyprice_withDiscount = 255.00
                where sellbilldetailid = 681;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (255, '2021-12-15', 275, 255, 255
                    , 255, 255, 255, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+275, sellCostBuyPrice =sellCostBuyPrice+255
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+255, sellCostMeanBuyPrice = sellCostMeanBuyPrice+255
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+255, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+255
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (5, '2021-12-15', 275, 255, 255
                    , 255, 255, 255, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+275, sellCostBuyPrice =sellCostBuyPrice+255
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+255, sellCostMeanBuyPrice = sellCostMeanBuyPrice+255
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+255, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+255
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '7', userid = '7', storedetaildate = '2021-12-15 14:51:26' WHERE storedetailid = '920';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('255', '5', '1', '1', '323', 'اضافة فاتورة مبيعات', 'sellbillController.php', '8.00', '7', '7', '2021-12-15 14:51:26','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2058;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('230','00590', '323', '1', '590', '1', '245', '245', '0', '', '2', '2021-12-15 14:51:26', '590', '0.00', '0', '5','0','','','0','0','0','0','0','0','2','0','','2058-1,');
UPDATE sellbilldetail SET  lastbuyprice = 230.00 , meanbuyprice = 230.00, lastbuyprice_withDiscount = 230.00, meanbuyprice_withDiscount = 230.00
                where sellbilldetailid = 682;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (590, '2021-12-15', 245, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+245, sellCostBuyPrice =sellCostBuyPrice+230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+230
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (5, '2021-12-15', 245, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+245, sellCostBuyPrice =sellCostBuyPrice+230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+230
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '20', userid = '7', storedetaildate = '2021-12-15 14:51:26' WHERE storedetailid = '1586';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '5', '1', '1', '323', 'اضافة فاتورة مبيعات', 'sellbillController.php', '21.00', '20', '7', '2021-12-15 14:51:26','0','0');
UPDATE save SET  savecurrentvalue = '810',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('45.00','765', '0', '5', 'اضافة فاتورة مبيعات', '323', '810', '2021-12-15 14:51:26', '7',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 765, 695, 695
                    , 695, 695, 695, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+765, sellCostBuyPrice =sellCostBuyPrice+695
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+695, sellCostMeanBuyPrice = sellCostMeanBuyPrice+695
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+695, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+695
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-15', 765, 695, 695
                    , 695, 695, 695, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+765, sellCostBuyPrice =sellCostBuyPrice+695
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+695, sellCostMeanBuyPrice = sellCostMeanBuyPrice+695
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+695, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+695
                            , 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, 765, 695, 695
                    , 695, 695, 695, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+765, netSellCostBuyPrice = netSellCostBuyPrice+695
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+695
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+695
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+695
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+695
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9e3e54d769 and sellbillId = 323 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:21:27";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 14:51:27", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:51:27', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:21:51";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 14:51:51", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:51:51', '7', 'addAndRetuen', '156.160.238.195', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b9e4cf72d5e
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-15 14:51:27', '061b9e4cf72d5e', '1', '0.00', '0', '0', '1', '230', '230', '230', '0', '5', '2021-12-15 14:51:51', '', '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','اضافة فاتورة مبيعات','324', '0', '2021-12-15 14:51:51', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '230', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1972;
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', '324', '1', '127', '1', '230.00', '230', '0', '', '2', '2021-12-15 14:51:51', '127', '0.00', '0', '5','0','','','0','0','0','0','0','0','2','0','','1972-1,');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 1148.55, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 1148.55
                where sellbilldetailid = 683;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (127, '2021-12-15', 230, 210, 210
                    , 1148.55, 210, 1148.55, 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+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 (5, '2021-12-15', 230, 210, 210
                    , 1148.55, 210, 1148.55, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+230, 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 = '6', userid = '7', storedetaildate = '2021-12-15 14:51:51' WHERE storedetailid = '1551';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('127', '5', '1', '1', '324', 'اضافة فاتورة مبيعات', 'sellbillController.php', '7.00', '6', '7', '2021-12-15 14:51:51','0','0');
UPDATE save SET  savecurrentvalue = '1040',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('810.00','230', '0', '5', 'اضافة فاتورة مبيعات', '324', '1040', '2021-12-15 14:51:51', '7',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 230, 210, 210
                    , 1148.55, 210, 1148.55, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+230, 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;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-15', 230, 210, 210
                    , 1148.55, 210, 1148.55, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+230, 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;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, 230, 210, 210
                    , 1148.55, 210, 1148.55, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+230, netSellCostBuyPrice = netSellCostBuyPrice+210
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+210
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+1148.55
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+210
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+1148.55
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9e4cf72d5e and sellbillId = 324 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:21:52";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 14:51:52", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:51:52', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:21:56";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 14:51:56", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:51:57', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:22:22";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:52:22", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:52:22', '5', 'addAndRetuen', '41.45.236.6', '', '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 061b9e4729535b
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(73,@clientdebt,@clientname);
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-15 14:49:54', '061b9e4729535b', '73', '1150.00', '1800', '10', '1', '1445', '1435', '785', '650', '3', '2021-12-15 14:52:23', '', '5', '0', 'ام سعد', '3', '1', '3', '0', 'ام سعد', '6' ,'0','','','','','-1','0','0','0','0','0','1435','0','','0','0','785','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '1800', userid = '5' WHERE clientid = '73';
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 ('73','1150.00','650','0','اضافة فاتورة مبيعات','325', '1800', '2021-12-15 14:52:23', '5', 'sellbillController.php', 'اضافة فاتورة مبيعات', '1435', '0', null, '0', null, null,'', '0','1','1','650','1');
UPDATE client SET  inUse = 0 where clientid = 73;
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1808;
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 ('235','00252', '325', '1', '252', '1', '275.00', '275', '0', '', '2', '2021-12-15 14:52:23', '252', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','1808-1,');
UPDATE sellbilldetail SET  lastbuyprice = 235.00 , meanbuyprice = 235.00, lastbuyprice_withDiscount = 235.00, meanbuyprice_withDiscount = 235.00
                where sellbilldetailid = 684;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (252, '2021-12-15', 273.096885813, 235, 235
                    , 235, 235, 235, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+273.096885813, sellCostBuyPrice =sellCostBuyPrice+235
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+235, sellCostMeanBuyPrice = sellCostMeanBuyPrice+235
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+235, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+235
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2021-12-15', 273.096885813, 235, 235
                    , 235, 235, 235, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+273.096885813, sellCostBuyPrice =sellCostBuyPrice+235
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+235, sellCostMeanBuyPrice = sellCostMeanBuyPrice+235
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+235, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+235
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '18', userid = '5', storedetaildate = '2021-12-15 14:52:23' WHERE storedetailid = '1454';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('252', '3', '1', '1', '325', 'اضافة فاتورة مبيعات', 'sellbillController.php', '19.00', '18', '5', '2021-12-15 14:52:23','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+2 where id = 2020;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('230','00589', '325', '1', '589', '2', '245', '490', '0', '', '2', '2021-12-15 14:52:23', '589', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','2020-2,');
UPDATE sellbilldetail SET  lastbuyprice = 230.00 , meanbuyprice = 230.00, lastbuyprice_withDiscount = 230.00, meanbuyprice_withDiscount = 230.00
                where sellbilldetailid = 685;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (589, '2021-12-15', 486.60899654, 460, 460
                    , 460, 460, 460, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 2, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+486.60899654, sellCostBuyPrice =sellCostBuyPrice+460
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+460, sellCostMeanBuyPrice = sellCostMeanBuyPrice+460
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+460, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+460
                            , 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, '2021-12-15', 486.60899654, 460, 460
                    , 460, 460, 460, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+486.60899654, sellCostBuyPrice =sellCostBuyPrice+460
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+460, sellCostMeanBuyPrice = sellCostMeanBuyPrice+460
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+460, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+460
                            , 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 = '5', storedetaildate = '2021-12-15 14:52:23' WHERE storedetailid = '1576';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '3', '2', '1', '325', 'اضافة فاتورة مبيعات', 'sellbillController.php', '17.00', '15', '5', '2021-12-15 14:52:23','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', '325', '1', '127', '1', '230.00', '230', '0', '', '2', '2021-12-15 14:52:23', '127', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','1962-1,');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 1148.55, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 1148.55
                where sellbilldetailid = 686;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (127, '2021-12-15', 228.408304498, 210, 210
                    , 1148.55, 210, 1148.55, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+228.408304498, 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, '2021-12-15', 228.408304498, 210, 210
                    , 1148.55, 210, 1148.55, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+228.408304498, 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 = '-1', userid = '5', storedetaildate = '2021-12-15 14:52:23' WHERE storedetailid = '1546';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('127', '3', '1', '1', '325', 'اضافة فاتورة مبيعات', 'sellbillController.php', '0.00', '-1', '5', '2021-12-15 14:52:23','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1890;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('210','00563', '325', '1', '563', '1', '230', '230', '0', '', '2', '2021-12-15 14:52:23', '563', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','1890-1,');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 210.00, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 210.00
                where sellbilldetailid = 687;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (563, '2021-12-15', 228.408304498, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+228.408304498, 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 (3, '2021-12-15', 228.408304498, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+228.408304498, 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 = '10', userid = '5', storedetaildate = '2021-12-15 14:52:23' WHERE storedetailid = '1505';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '3', '1', '1', '325', 'اضافة فاتورة مبيعات', 'sellbillController.php', '11.00', '10', '5', '2021-12-15 14:52:23','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2134;
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','00597', '325', '1', '597', '1', '220', '220', '0', '', '2', '2021-12-15 14:52:23', '597', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','2134-1,');
UPDATE sellbilldetail SET  lastbuyprice = 190.00 , meanbuyprice = 190.00, lastbuyprice_withDiscount = 190.00, meanbuyprice_withDiscount = 190.00
                where sellbilldetailid = 688;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (597, '2021-12-15', 218.477508651, 190, 190
                    , 190, 190, 190, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+218.477508651, sellCostBuyPrice =sellCostBuyPrice+190
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+190, sellCostMeanBuyPrice = sellCostMeanBuyPrice+190
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+190, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+190
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2021-12-15', 218.477508651, 190, 190
                    , 190, 190, 190, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+218.477508651, sellCostBuyPrice =sellCostBuyPrice+190
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+190, sellCostMeanBuyPrice = sellCostMeanBuyPrice+190
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+190, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+190
                            , 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 = '0', userid = '5', storedetaildate = '2021-12-15 14:52:23' WHERE storedetailid = '1626';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('597', '3', '1', '1', '325', 'اضافة فاتورة مبيعات', 'sellbillController.php', '1.00', '0', '5', '2021-12-15 14:52:23','0','0');
UPDATE save SET  savecurrentvalue = '8130',  userid = '5' WHERE saveid = '3';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('7345.00','785', '0', '3', 'اضافة فاتورة مبيعات', '325', '8130', '2021-12-15 14:52:23', '5',  'sellbillController.php','73','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 1435, 1305, 1305
                    , 2243.55, 1305, 2243.55, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1435, sellCostBuyPrice =sellCostBuyPrice+1305
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1305, sellCostMeanBuyPrice = sellCostMeanBuyPrice+2243.55
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1305, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+2243.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 (73, '2021-12-15', 1435, 1305, 1305
                    , 2243.55, 1305, 2243.55, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1435, sellCostBuyPrice =sellCostBuyPrice+1305
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1305, sellCostMeanBuyPrice = sellCostMeanBuyPrice+2243.55
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1305, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+2243.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, 1435, 1305, 1305
                    , 2243.55, 1305, 2243.55, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+1435, netSellCostBuyPrice = netSellCostBuyPrice+1305
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+1305
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+2243.55
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+1305
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+2243.55
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9e4729535b and sellbillId = 325 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:22:23";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:52:23", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:52:23', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:22:31";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:52:31", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:52:31', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:22:31";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:52:31", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:52:31', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:23:30";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:53:30", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:53:30', '5', 'addAndRetuen', '41.45.236.6', '', '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 061b9e50fb1e58
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(73,@clientdebt,@clientname);
INSERT INTO returnsellbill (returnsellbilldate, returnsellbillserial, returnsellbillclientid, returnsellbilltotaldeptbefor, returnsellbilltotaldeptafter, returnsellbilldiscount, returnsellbilldiscounttype, returnsellbilltotalbill, returnsellbillaftertotalbill, returnsellbilltotalpayed, returnsellbillfinalbill, returnsellbillstoreid, returnsellbillsysdate,comment, userid, conditions, returnsellbillclientname, returnsellbillsaveid, returnsellbildirectpayment, billnameid, sellerid, tempclientName, returnsellQuantity,tax, carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,delbyuserid,billReservation,billReservationDate,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal) VALUES ('2021-12-15 14:52:31', '061b9e50fb1e58', '73', '1800.00', '950', '0', '1', '850', '850', '0', '-850', '3', '2021-12-15 14:53:30', '', '5', '0', 'ام سعد','3', '1', '5', '0', 'ام سعد', '3', '0', '', '','','','-1','0','0','0','','0','0','0','0','0','0','0','0');
UPDATE client SET  clientdebt = '950', userid = '5' WHERE clientid = '73';
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 ('73','1800.00','850','1','اضافة فاتورة مردوات مبيعات','97', '950', '2021-12-15 14:53:30', '5', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '850', '0', null, '0', null, null,'', '0','1','1','850','1');
UPDATE client SET  inUse = 0 where clientid = 73;
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 ('270.00', '00254', '97', '1', '254', '2', '300.00', '600', '0', '', '2', '0', '254', '0.00', '0','3','0','','','0','0','0','0','0','2');
UPDATE returnsellbilldetail SET  lastbuyprice = 270.00 , meanbuyprice = 270.00, lastbuyprice_withDiscount = 270.00, meanbuyprice_withDiscount = 270.00
                where returnsellbilldetailid = 153;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (254, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 600, 540, 540, 540
                    , 540, 540, 0, 0, 2)
                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+600, returnSellCostBuyPrice = returnSellCostBuyPrice+540, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+540
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+540, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+540
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+540
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+0
                        , netQuantityRet = netQuantityRet+2;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 600, 540, 540, 540
                    , 540, 540, 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+600, returnSellCostBuyPrice = returnSellCostBuyPrice+540, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+540
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+540, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+540
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+540
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '5', userid = '5', storedetaildate = '2021-12-15 14:53:30' WHERE storedetailid = '1463';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('254', '3', '2', '0', '97', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '3.00', '5', '5', '2021-12-15 14:53:30','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 ('195.00', '00556', '97', '1', '556', '1', '250', '250', '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 = 154;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (556, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 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+250, 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, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 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+250, returnSellCostBuyPrice = returnSellCostBuyPrice+195, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+195
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+195, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+195
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+195
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '7', userid = '5', storedetaildate = '2021-12-15 14:53:30' WHERE storedetailid = '1503';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('556', '3', '1', '0', '97', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '6.00', '7', '5', '2021-12-15 14:53:30','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 850, 735, 735, 735
                    , 735, 735, 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+850, returnSellCostBuyPrice = returnSellCostBuyPrice+735, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+735
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+735, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+735
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+735
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (73, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 850, 735, 735, 735
                    , 735, 735, 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+850, returnSellCostBuyPrice = returnSellCostBuyPrice+735, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+735
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+735, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+735
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+735
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -850, -735, -735
                    , -735, -735, -735, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-850, netSellCostBuyPrice = netSellCostBuyPrice+-735
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-735
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-735
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-735
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-735
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9e50fb1e58 and sellbillId = 97 and returnsellbillId = 97
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:23:30";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:53:30", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:53:30', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:23:38";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:53:38", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:53:38', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:23:38";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:53:38", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:53:39', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:23:46";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:53:46", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 14:53:46', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:23:47";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:53:47", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 14:53:47', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:24:29";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:54:29", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:54:29', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:24:29";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 14:54:29", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:54:29', '5', 'addsellBill', '41.45.236.6', '', '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;
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:26:14";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 14:56:14", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-15 14:56:14', '6', '', '197.61.178.123', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:26: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 < "2021-12-15 11:26:16";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 14:56:16", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:56:16', '6', 'addsellBill', '197.61.178.123', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:26:38";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 14:56:38", deviceType = "DESKTOP" WHERE userid = 6;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:56:38', '6', 'addAndRetuen', '197.61.178.123', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b9e5f11ca9a
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-15 14:56:17', '061b9e5f11ca9a', '1', '0.00', '0', '0', '1', '470', '470', '470', '0', '4', '2021-12-15 14:56:38', '', '6', '0', 'نقدي', '4', '0', '3', '0', 'نقدي', '2' ,'0','','','','','-1','0','0','0','0','0','470','0','','0','0','470','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '6' WHERE clientid = '1';
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('1','0.00','0','0','اضافة فاتورة مبيعات','326', '0', '2021-12-15 14:56:38', '6', 'sellbillController.php', 'اضافة فاتورة مبيعات', '470', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2016;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('230','00589', '326', '1', '589', '1', '235.00', '235', '0', '', '0', '2021-12-15 14:56:38', '589', '0.00', '0', '4','0','','','0','0','0','0','0','0','0','0','','2016-1,');
UPDATE sellbilldetail SET  lastbuyprice = 230.00 , meanbuyprice = 230.00, lastbuyprice_withDiscount = 230.00, meanbuyprice_withDiscount = 230.00
                where sellbilldetailid = 689;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (589, '2021-12-15', 235, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+235, sellCostBuyPrice =sellCostBuyPrice+230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+230
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (4, '2021-12-15', 235, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+235, sellCostBuyPrice =sellCostBuyPrice+230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+230
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '3', userid = '6', storedetaildate = '2021-12-15 14:56:38' WHERE storedetailid = '1574';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('589', '4', '1', '1', '326', 'اضافة فاتورة مبيعات', 'sellbillController.php', '4.00', '3', '6', '2021-12-15 14:56:38','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 2220;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('230','00590', '326', '1', '590', '1', '235', '235', '0', '', '0', '2021-12-15 14:56:38', '590', '0.00', '0', '4','0','','','0','0','0','0','0','0','0','0','','2220-1,');
UPDATE sellbilldetail SET  lastbuyprice = 230.00 , meanbuyprice = 230.00, lastbuyprice_withDiscount = 230.00, meanbuyprice_withDiscount = 230.00
                where sellbilldetailid = 690;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (590, '2021-12-15', 235, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+235, sellCostBuyPrice =sellCostBuyPrice+230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+230
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (4, '2021-12-15', 235, 230, 230
                    , 230, 230, 230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+235, sellCostBuyPrice =sellCostBuyPrice+230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+230
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '8', userid = '6', storedetaildate = '2021-12-15 14:56:38' WHERE storedetailid = '1669';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('590', '4', '1', '1', '326', 'اضافة فاتورة مبيعات', 'sellbillController.php', '9.00', '8', '6', '2021-12-15 14:56:38','0','0');
UPDATE save SET  savecurrentvalue = '470',  userid = '6' WHERE saveid = '4';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('0.00','470', '0', '4', 'اضافة فاتورة مبيعات', '326', '470', '2021-12-15 14:56:38', '6',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 470, 460, 460
                    , 460, 460, 460, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+470, sellCostBuyPrice =sellCostBuyPrice+460
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+460, sellCostMeanBuyPrice = sellCostMeanBuyPrice+460
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+460, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+460
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-15', 470, 460, 460
                    , 460, 460, 460, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+470, sellCostBuyPrice =sellCostBuyPrice+460
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+460, sellCostMeanBuyPrice = sellCostMeanBuyPrice+460
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+460, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+460
                            , 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, 470, 460, 460
                    , 460, 460, 460, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+470, netSellCostBuyPrice = netSellCostBuyPrice+460
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+460
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+460
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+460
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+460
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9e5f11ca9a and sellbillId = 326 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

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

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

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

END

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

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:28:38";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 14:58:38", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 14:58:38', '4', 'addsellBill', '197.61.178.123', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:30:47";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 15:00:47", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 15:00:47', '4', '', '197.61.178.123', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:31:09";
UPDATE user SET loginip = "197.61.178.123", lastactivetime = "2021-12-15 15:01:09", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 15:01:09', '4', 'addsellBill', '197.61.178.123', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:41:21";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 15:11:21", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 15:11:21', '7', 'addAndRetuen', '156.160.238.195', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b9e4ed23fec
-- ----------------------------------------------------------------------------------------------------

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

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9e4ed23fec and sellbillId = 327 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:41:22";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 15:11:22", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 15:11:22', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 11:41:26";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 15:11:26", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 15:11:26', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:02:12";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:32:12", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-15 15:32:12', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:02:40";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:32:40", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2021-12-15 15:32:40', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:03:43";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:33:43", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2021-12-15 15:33:43', '1', 'edit', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:04:56";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:34:56", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2021-12-15 15:34:56', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:05:12";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:35:12", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2021-12-15 15:35:12', '1', 'edit', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:05:49";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:35:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientDeficitController.php', '2021-12-15 15:35:49', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:05:59";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:35:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientDeficitController.php', '2021-12-15 15:35:59', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:06:02";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:36:02", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientDeficitController.php', '2021-12-15 15:36:02', '1', '', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:06:39";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:36:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientDeficitController.php', '2021-12-15 15:36:39', '1', 'add', '41.233.39.117', '', '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

;

-- ----------------------------------------------------------------------------------------------------
-- clientDeficitController add - with clientid =70
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(70,@clientdebt,@clientname);
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('70','19345.00','675','0','تسوية عجز عميل بالزيادة','-1', '20020', '2021-12-15 15:36:39', '1', 'clientDeficitController.php', '', '675', '0', null, '0', null, null,'', '0','1','1','675','1');
UPDATE client SET  clientdebt = '20020' , clientdate = '2021-12-15', userid = '1' WHERE clientid = '70';
UPDATE client SET  inUse = 0 where clientid = 70;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '675', '675', '2021-12-15', '1', '0', '0', '2021-12-15 15:36:39','تم اضافة معالجة عجز للعميل سنتر اولاد حموده(تسوية بالاضافة)','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('847', '123', '675', '','0');
UPDATE accountstree SET name = 'سنتر اولاد حموده', customName = 'سنتر اولاد حموده', parent = '23', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '5740', theOrder = '0', layingOrder = '',reportid = '0' WHERE id = '123';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('847', '29', '675', '','0');
UPDATE accountstree SET name = 'معالجة عجز مدينين', customName = 'معالجة عجز مدينين', parent = '3', itemtype = '0', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '-875', theOrder = '0', layingOrder = '36',reportid = '1' WHERE id = '29';
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- clientDeficitController add end- with clientid =70 ,id=584
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:06:39";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:36:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientDeficitController.php', '2021-12-15 15:36:39', '1', 'sucess', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:06:41";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:36:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientDeficitController.php', '2021-12-15 15:36:41', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:06:45";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:36:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-15 15:36:45', '1', '', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:06:52";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:36:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2021-12-15 15:36:52', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:10:49";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 15:40:49", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2021-12-15 15:40:49', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:10:50";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 15:40:50", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2021-12-15 15:40:50', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:11:16";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 15:41:16", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 15:41:16', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:11:17";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 15:41:17", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 15:41:17', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:20:50";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:50:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2021-12-15 15:50:50', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:20:55";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:50:55", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2021-12-15 15:50:55', '1', '', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:21:15";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:51:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2021-12-15 15:51:15', '1', 'add', '41.233.39.117', '', 'DESKTOP');
BEGIN;
INSERT INTO transfermoney (saveidfrom, saveidto, transfermoneyvalue, transfermoneydate, userid, conditions, dailyentryid , comment) VALUES ('4','7', '470.00', '2021-12-15', '1', '0', '0','');
UPDATE save SET  savecurrentvalue = '0',  userid = '1' WHERE saveid = '4';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('470.00','470.00', '1', '4', 'تحويل امول الى الخزنة  [ خزينة محل العميد ] ', '19', '0', '2021-12-15 15:51:15', '1',  'transfermoneyController.php','0','');
UPDATE save SET  savecurrentvalue = '1700',  userid = '1' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1230.00','470.00', '0', '7', 'تحويل امول من الخزنة  [ خزينة محل روني ] ', '19', '1700', '2021-12-15 15:51:15', '1',  'transfermoneyController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '470', '470', '2021-12-15', '1', '0', '0', '2021-12-15 15:51:15','اضافة تحويل من خزينة محل روني الى خزينة محل العميد','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('848', '141', '470.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 = '-38590', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('848', '138', '470.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 = '-19130', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '138';
UPDATE transfermoney SET saveidfrom = '4', saveidto = '7', transfermoneyvalue = '470.00', transfermoneydate = '2021-12-15', userid = '1', conditions = '0' , dailyentryid = '848' , comment = '' WHERE transfermoneyid = '19';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:21:15";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:51:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2021-12-15 15:51:15', '1', 'sucess', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:21:18";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:51:18", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2021-12-15 15:51:18', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:21:34";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:51:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-15 15:51:34', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:28:01";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:58:01", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientDeficitController.php', '2021-12-15 15:58:01', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:28:14";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:58:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientDeficitController.php', '2021-12-15 15:58:14', '1', '', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:28:32";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:58:32", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientDeficitController.php', '2021-12-15 15:58:32', '1', 'add', '41.233.39.117', '', '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

;

-- ----------------------------------------------------------------------------------------------------
-- clientDeficitController add - with clientid =29
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(29,@clientdebt,@clientname);
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 ('29','650.00','650','1','تسوية عجز عميل بالخصم','-1', '0', '2021-12-15 15:58:32', '1', 'clientDeficitController.php', '', '650', '0', null, '0', null, null,'', '0','1','1','650','1');
UPDATE client SET  clientdebt = '0' , clientdate = '2021-12-15', userid = '1' WHERE clientid = '29';
UPDATE client SET  inUse = 0 where clientid = 29;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '650', '650', '2021-12-15', '1', '0', '0', '2021-12-15 15:58:32','تم اضافة معالجة عجز للعميل ام ساره الراس السوده(تسوية بالخصم)','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('849', '29', '650', '','0');
UPDATE accountstree SET name = 'معالجة عجز مدينين', customName = 'معالجة عجز مدينين', parent = '3', itemtype = '0', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '-225', theOrder = '0', layingOrder = '36',reportid = '1' WHERE id = '29';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('849', '82', '650', '','0');
UPDATE accountstree SET name = 'ام ساره الراس السوده', customName = 'ام ساره الراس السوده', parent = '23', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-650', theOrder = '0', layingOrder = '',reportid = '0' WHERE id = '82';
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- clientDeficitController add end- with clientid =29 ,id=585
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:28:33";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:58:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientDeficitController.php', '2021-12-15 15:58:33', '1', 'sucess', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:28:35";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 15:58:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientDeficitController.php', '2021-12-15 15:58:35', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:29:44";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 15:59:44", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 15:59:44', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:30:33";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:00:33", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:00:33', '7', 'addAndRetuen', '156.160.238.195', '', '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 061b9f4d079a6f
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(29,@clientdebt,@clientname);
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-15 15:59:44', '061b9f4d079a6f', '29', '0.00', '300', '0', '1', '300', '300', '0', '300', '5', '2021-12-15 16:00:34', '', '7', '0', 'ام ساره الراس السوده', '5', '1', '3', '0', 'ام ساره الراس السوده', '1' ,'0','','','','','-1','0','0','0','0','0','300','0','','0','0','0','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '300', userid = '7' WHERE clientid = '29';
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 ('29','0.00','300','0','اضافة فاتورة مبيعات','328', '300', '2021-12-15 16:00:34', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '300', '0', null, '0', null, null,'', '0','1','1','300','1');
UPDATE client SET  inUse = 0 where clientid = 29;
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 736;
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 ('270','00254', '328', '1', '254', '1', '300.00', '300', '0', '', '2', '2021-12-15 16:00:34', '254', '0.00', '0', '5','0','','','0','0','0','0','0','0','2','0','','736-1,');
UPDATE sellbilldetail SET  lastbuyprice = 270.00 , meanbuyprice = 270.00, lastbuyprice_withDiscount = 270.00, meanbuyprice_withDiscount = 270.00
                where sellbilldetailid = 692;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (254, '2021-12-15', 300, 270, 270
                    , 270, 270, 270, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+300, sellCostBuyPrice =sellCostBuyPrice+270
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+270, sellCostMeanBuyPrice = sellCostMeanBuyPrice+270
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+270, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+270
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (5, '2021-12-15', 300, 270, 270
                    , 270, 270, 270, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+300, sellCostBuyPrice =sellCostBuyPrice+270
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+270, sellCostMeanBuyPrice = sellCostMeanBuyPrice+270
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+270, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+270
                            , 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 = '2021-12-15 16:00:34' WHERE storedetailid = '919';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('254', '5', '1', '1', '328', 'اضافة فاتورة مبيعات', 'sellbillController.php', '5.00', '4', '7', '2021-12-15 16:00:34','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 300, 270, 270
                    , 270, 270, 270, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+300, sellCostBuyPrice =sellCostBuyPrice+270
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+270, sellCostMeanBuyPrice = sellCostMeanBuyPrice+270
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+270, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+270
                            , 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 (29, '2021-12-15', 300, 270, 270
                    , 270, 270, 270, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+300, sellCostBuyPrice =sellCostBuyPrice+270
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+270, sellCostMeanBuyPrice = sellCostMeanBuyPrice+270
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+270, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+270
                            , 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, 300, 270, 270
                    , 270, 270, 270, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+300, netSellCostBuyPrice = netSellCostBuyPrice+270
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+270
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+270
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+270
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+270
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9f4d079a6f and sellbillId = 328 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:30:34";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:00:34", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:00:34', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:31:43";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:01:43", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:01:43', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:33:25";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:03:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:03:25', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:33:33";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:03:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:03:33', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:33:38";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:03:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:03:38', '1', 'editsellBill', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:33:44";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:03:44", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:03:44', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:34:35";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:04:35", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:04:35', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:35:20";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:05:20", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:05:20', '7', 'addAndRetuen', '156.160.238.195', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b9f5f391cbb
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO returnsellbill (returnsellbilldate, returnsellbillserial, returnsellbillclientid, returnsellbilltotaldeptbefor, returnsellbilltotaldeptafter, returnsellbilldiscount, returnsellbilldiscounttype, returnsellbilltotalbill, returnsellbillaftertotalbill, returnsellbilltotalpayed, returnsellbillfinalbill, returnsellbillstoreid, returnsellbillsysdate,comment, userid, conditions, returnsellbillclientname, returnsellbillsaveid, returnsellbildirectpayment, billnameid, sellerid, tempclientName, returnsellQuantity,tax, carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,delbyuserid,billReservation,billReservationDate,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal) VALUES ('2021-12-15 16:04:35', '061b9f5f391cbb', '1', '0.00', '0', '0', '1', '490', '490', '-490', '0', '5', '2021-12-15 16:05:20', '', '7', '0', 'نقدي','5', '0', '5', '0', 'نقدي', '2', '0', '', '','','','-1','0','0','0','','0','-490','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','1','اضافة فاتورة مردوات مبيعات','98', '0', '2021-12-15 16:05:20', '7', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '490', '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', '00556', '98', '1', '556', '1', '250', '250', '0', '', '2', '0', '556', '0.00', '0','5','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 = 155;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (556, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 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+250, 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 (5, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 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+250, returnSellCostBuyPrice = returnSellCostBuyPrice+195, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+195
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+195, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+195
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+195
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '13', userid = '7', storedetaildate = '2021-12-15 16:05:20' WHERE storedetailid = '1497';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('556', '5', '1', '0', '98', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '12.00', '13', '7', '2021-12-15 16:05:20','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 ('195.00', '00555', '98', '1', '555', '1', '240', '240', '0', '', '2', '0', '555', '0.00', '0','5','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 = 156;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (555, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 240, 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+240, 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 (5, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 240, 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+240, returnSellCostBuyPrice = returnSellCostBuyPrice+195, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+195
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+195, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+195
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+195
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '29', userid = '7', storedetaildate = '2021-12-15 16:05:20' WHERE storedetailid = '1496';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '5', '1', '0', '98', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '28.00', '29', '7', '2021-12-15 16:05:20','0','0');
UPDATE save SET  savecurrentvalue = '815',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1305.00','490', '1', '5', 'اضافة فاتورة مردوات مبيعات', '98', '815', '2021-12-15 16:05:20', '7',  'returnsellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 490, 390, 390, 390
                    , 390, 390, 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+490, returnSellCostBuyPrice = returnSellCostBuyPrice+390, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+390
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+390, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+390
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+390
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 490, 390, 390, 390
                    , 390, 390, 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+490, returnSellCostBuyPrice = returnSellCostBuyPrice+390, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+390
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+390, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+390
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+390
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -490, -390, -390
                    , -390, -390, -390, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-490, netSellCostBuyPrice = netSellCostBuyPrice+-390
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-390
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-390
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-390
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-390
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9f5f391cbb and sellbillId = 98 and returnsellbillId = 98
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:35:21";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:05:21", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:05:21', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:36:11";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:06:11", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:06:11', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:36:34";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:06:35", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:06:35', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:36:44";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:06:45", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 16:06:45', '7', '', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:36:57";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:06:57", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:06:57', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:37:04";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:07:04", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2021-12-15 16:07:04', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:37:12";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:07:12", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2021-12-15 16:07:12', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:37:16";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:07:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:07:16', '1', 'editreturnsellBill', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:37:23";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:07:23", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:07:23', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:37:28";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:07:28", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:07:28', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:37:53";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:07:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2021-12-15 16:07:54', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:38:03";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:08:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:08:03', '1', 'editreturnsellBill', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:38:20";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:08:20", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:08:20', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:38:28";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:08:28", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 16:08:28', '7', '', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:38:42";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:08:42", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2021-12-15 16:08:42', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:38:50";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:08:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2021-12-15 16:08:50', '1', 'delete', '41.233.39.117', '', '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 delete start - returnsellbill with id = 98
-- ----------------------------------------------------------------------------------------------------

BEGIN;
UPDATE costcenterdetail SET del = 1 WHERE type in( 1) and  modelid = 98;
UPDATE returnsellbill SET returnsellbillsysdate = '2021-12-15', userid = '7',delbyuserid = '1', conditions = '1'  ,billReservation= 0,billReservationDate='0000-00-00'  WHERE returnsellbillid = '98';
UPDATE storedetail SET  productquantity = '12', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '1497';
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (556, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 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-250, 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 (5, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 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-250, returnSellCostBuyPrice = returnSellCostBuyPrice-195, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice-195
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice-195, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount-195
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount-195
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice-0;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('556', '5', '1', '1', '98', 'حذف فاتورة مردودات مبيعات', 'returnsellbillController.php', '13.00', '12', '1', '2021-12-15','0','0');
UPDATE storedetail SET  productquantity = '28', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '1496';
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (555, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 240, 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-240, 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 (5, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 240, 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-240, returnSellCostBuyPrice = returnSellCostBuyPrice-195, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice-195
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice-195, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount-195
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount-195
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice-0;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '5', '1', '1', '98', 'حذف فاتورة مردودات مبيعات', 'returnsellbillController.php', '29.00', '28', '1', '2021-12-15','0','0');
UPDATE client SET  clientdebt = '0', userid = '1' 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','حذف فاتورة مردودات مبيعات','98', '0', '2021-12-15 16:08:50', '1', 'returnsellbillController.php', 'حذف فاتورة مردودات مبيعات', '490', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE save SET  savecurrentvalue = '1305',  userid = '1' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('815.00','-490', '0', '5', 'حذف فاتورة مردودات مبيعات', '98', '1305', '2021-12-15 16:08:50', '1',  'returnsellbillController.php','0','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 490, 390, 390, 390
                    , 390, 390, 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-490, returnSellCostBuyPrice = returnSellCostBuyPrice-390, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice-390
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice-390, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount-390
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount-390
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice-0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 490, 390, 390, 390
                    , 390, 390, 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-490, returnSellCostBuyPrice = returnSellCostBuyPrice-390, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice-390
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice-390, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount-390
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount-390
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice-0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -490, -390, -390
                    , -390, -390, -390, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal--490, netSellCostBuyPrice = netSellCostBuyPrice--390
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice--390
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice--390
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount--390
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount--390
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice-0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill delete end - returnsellbill with id = 98
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:38:51";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:08:51", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2021-12-15 16:08:51', '1', 'sucess', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:38:53";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:08:53", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2021-12-15 16:08:53', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:38:57";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:08:57", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:08:57', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:38:59";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:08:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2021-12-15 16:08:59', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:39:00";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:09:00", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:09:00', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:39:27";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:09:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2021-12-15 16:09:27', '1', 'showDetail', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:39:34";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:09:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2021-12-15 16:09:34', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:39:34";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:09:34", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:09:34', '7', 'addAndRetuen', '156.160.238.195', '', '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 061b9f6fcb30b1
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(29,@clientdebt,@clientname);
INSERT INTO returnsellbill (returnsellbilldate, returnsellbillserial, returnsellbillclientid, returnsellbilltotaldeptbefor, returnsellbilltotaldeptafter, returnsellbilldiscount, returnsellbilldiscounttype, returnsellbilltotalbill, returnsellbillaftertotalbill, returnsellbilltotalpayed, returnsellbillfinalbill, returnsellbillstoreid, returnsellbillsysdate,comment, userid, conditions, returnsellbillclientname, returnsellbillsaveid, returnsellbildirectpayment, billnameid, sellerid, tempclientName, returnsellQuantity,tax, carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,delbyuserid,billReservation,billReservationDate,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal) VALUES ('2021-12-15 16:09:00', '061b9f6fcb30b1', '29', '300.00', '-190', '0', '1', '490', '490', '0', '-490', '5', '2021-12-15 16:09:34', '', '7', '0', 'ام ساره الراس السوده','5', '1', '5', '0', 'ام ساره الراس السوده', '2', '0', '', '','','','-1','0','0','0','','0','0','0','0','0','0','0','0');
UPDATE client SET  clientdebt = '-190', userid = '7' WHERE clientid = '29';
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 ('29','300.00','490','1','اضافة فاتورة مردوات مبيعات','99', '-190', '2021-12-15 16:09:34', '7', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '490', '0', null, '0', null, null,'', '0','1','1','490','1');
UPDATE client SET  inUse = 0 where clientid = 29;
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', '99', '1', '556', '1', '250.00', '250', '0', '', '2', '0', '556', '0.00', '0','5','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 = 157;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (556, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 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+250, 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 (5, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 250, 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+250, returnSellCostBuyPrice = returnSellCostBuyPrice+195, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+195
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+195, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+195
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+195
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '13', userid = '7', storedetaildate = '2021-12-15 16:09:34' WHERE storedetailid = '1497';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('556', '5', '1', '0', '99', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '12.00', '13', '7', '2021-12-15 16:09:34','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 ('195.00', '00555', '99', '1', '555', '1', '240.00', '240', '0', '', '2', '0', '555', '0.00', '0','5','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 = 158;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (555, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 240, 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+240, 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 (5, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 240, 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+240, returnSellCostBuyPrice = returnSellCostBuyPrice+195, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+195
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+195, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+195
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+195
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '29', userid = '7', storedetaildate = '2021-12-15 16:09:34' WHERE storedetailid = '1496';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '5', '1', '0', '99', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '28.00', '29', '7', '2021-12-15 16:09:34','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 490, 390, 390, 390
                    , 390, 390, 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+490, returnSellCostBuyPrice = returnSellCostBuyPrice+390, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+390
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+390, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+390
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+390
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (29, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 490, 390, 390, 390
                    , 390, 390, 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+490, returnSellCostBuyPrice = returnSellCostBuyPrice+390, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+390
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+390, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+390
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+390
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -490, -390, -390
                    , -390, -390, -390, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-490, netSellCostBuyPrice = netSellCostBuyPrice+-390
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-390
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-390
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-390
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-390
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061b9f6fcb30b1 and sellbillId = 99 and returnsellbillId = 99
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:39:35";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:09:35", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:09:35', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:39:47";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 16:09:47", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:09:47', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:58:37";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:28:37", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 16:28:37', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '26', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '356';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('356', '1', '26', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '26', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:58:38";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:28:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 16:28:38', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:58:49";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:28:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 16:28:49', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:59:22";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:29:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 16:29:22', '1', 'edit', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:59:38";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:29:38", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 16:29:38', '1', 'update', '41.233.39.117', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 356;
UPDATE productunit SET unitid = '1', productid = '356', productnumber = '1.00', productunitdate = '2021-12-15', userid = '1', conditions = '0',proUnitParcode='0035601',proUnitSellAllPrice='135',proUnitSellHalfPrice='135',proUnitSellUnitPrice ='160',proUnitBuyPrice='120' WHERE productunitid = '356';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (356, 1,'2021-12-15 16:29:38',1)
                ON DUPLICATE KEY UPDATE productid = 356, edited = 1, sysdate = '2021-12-15 16:29:38', userid = 1;
UPDATE product SET productName = 'دكرون 344', productDescription = '', productCatId = '1', productBuyPrice = '120', productSellAllPrice = '150', productSellUnitPrice = '180', productSellHalfPrice = '160', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00356',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '120.00',lastbuyprice_withDiscount = '120',meanbuyprice = '120.00',meanbuyprice_withDiscount = '120' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '25' , buyhalf_precentage = '33.33' , buypart_precentage = '50',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '356';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:59:39";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:29:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 16:29:40', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 12:59:43";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 16:29:43", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-15 16:29:43', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:00:06";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:30:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 16:30:06', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '19', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '343';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('343', '1', '19', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '19', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:00:09";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:30:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 16:30:09', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:00:16";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:30:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 16:30:16', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:00:22";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:30:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 16:30:22', '1', 'edit', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:00:34";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:30:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 16:30:34', '1', 'update', '41.233.39.117', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 343;
UPDATE productunit SET unitid = '1', productid = '343', productnumber = '1.00', productunitdate = '2021-12-15', userid = '1', conditions = '0',proUnitParcode='0034301',proUnitSellAllPrice='135',proUnitSellHalfPrice='135',proUnitSellUnitPrice ='160',proUnitBuyPrice='120' WHERE productunitid = '343';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (343, 1,'2021-12-15 16:30:34',1)
                ON DUPLICATE KEY UPDATE productid = 343, edited = 1, sysdate = '2021-12-15 16:30:34', userid = 1;
UPDATE product SET productName = 'دكرون 327', productDescription = '', productCatId = '1', productBuyPrice = '120', productSellAllPrice = '150', productSellUnitPrice = '180', productSellHalfPrice = '160', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00343',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '120.00',lastbuyprice_withDiscount = '120',meanbuyprice = '120.00',meanbuyprice_withDiscount = '120' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '25' , buyhalf_precentage = '33.33' , buypart_precentage = '50',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '343';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:00:36";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:30:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 16:30:36', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:00:50";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 16:30:50", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-15 16:30:50', '5', 'add', '41.45.236.6', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('1', 'فاتوره كهرباء المحل', '', '165', '2021-12-15', '5', '0','-1','3','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '7965',  userid = '5' WHERE saveid = '3';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('8130.00','165', '1', '3', 'إضافة مصروف', '67', '7965', '2021-12-15 16:30:50', '5',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '165', '165', '2021-12-15', '5', '0', '0', '2021-12-15 16:30:50','اضافة اسم مصروف( فاتوره كهرباء المحل )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('850', '144', '165', '','0');
UPDATE accountstree SET name = 'شحن كهرباء', customName = 'شحن كهرباء', parent = '14', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-08', itemtype2 = '0', theValue = '660', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '144';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('850', '137', '165', '','0');
UPDATE accountstree SET name = 'خزينة رائد', customName = 'خزينة رائد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-8705', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '137';
UPDATE expenses SET expensestypeid = '1', expensesname = 'فاتوره كهرباء المحل', expensesdetails = '', expensesValue = '165.00', expensesdate = '2021-12-15', userid = '5', conditions = '0',saveid = '3' , dailyentryid = '850', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '67';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:00:50";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 16:30:50", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-15 16:30:50', '5', 'sucess', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:00:52";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 16:30:52", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-15 16:30:52', '5', 'show', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:00:55";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 16:30:55", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 16:30:55', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:00:55";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 16:30:55", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 16:30:56', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:01:19";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 16:31:19", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:31:19', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:01:19";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 16:31:19", deviceType = "DESKTOP" WHERE userid = 5;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:01:19";
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 16:31:19', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:31:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 16:31:20', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '50', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '356';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('356', '1', '24', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '26.00', '50', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:01:21";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:31:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 16:31:21', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:01:59";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:31:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 16:31:59', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '40', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '343';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('343', '1', '21', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '19.00', '40', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:02:01";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:32:01", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 16:32:01', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:02:34";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:32:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 16:32:34', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '32', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '348';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('348', '1', '32', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '32', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:02:37";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:32:37", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 16:32:37', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:02:44";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:32:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 16:32:44', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:02:48";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:32:48", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 16:32:48', '1', 'edit', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:03:00";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:33:00", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 16:33:00', '1', 'update', '41.233.39.117', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 348;
UPDATE productunit SET unitid = '1', productid = '348', productnumber = '1.00', productunitdate = '2021-12-15', userid = '1', conditions = '0',proUnitParcode='0034801',proUnitSellAllPrice='135',proUnitSellHalfPrice='145',proUnitSellUnitPrice ='160',proUnitBuyPrice='120' WHERE productunitid = '348';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (348, 1,'2021-12-15 16:33:00',1)
                ON DUPLICATE KEY UPDATE productid = 348, edited = 1, sysdate = '2021-12-15 16:33:00', userid = 1;
UPDATE product SET productName = 'دكرون 332', productDescription = '', productCatId = '1', productBuyPrice = '120', productSellAllPrice = '150', productSellUnitPrice = '180', productSellHalfPrice = '160', productDate = '2021-11-07', conditions = '0', userId = '1', limitamount = '0', parcode = '00348',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '120.00',lastbuyprice_withDiscount = '120',meanbuyprice = '120.00',meanbuyprice_withDiscount = '120' , productbuypricereal = '0' , buypricereal_precentage = '0' , buytotal_precentage = '25' , buyhalf_precentage = '33.33' , buypart_precentage = '50',logo = '',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '348';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:03:02";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:33:02", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2021-12-15 16:33:02', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:06:34";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:36:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 16:36:34', '1', 'add', '41.233.39.117', '', '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(171,1,7,339,15,'2021-12-15',1,0, '' ,0,0,0,0,0,'2021-12-15 16:36:35',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '15', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '339';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 339, 0, 0
                    , 160.00, -15, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "15*2021-12-15*160.00," WHERE transferproductid = 1158;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('339', '1', '15', '1', '1158', 'تحويل منتجات من المخزن', 'storemovementController.php', '30.00', '15', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('339', '7', '15', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 339, 0, 0
                    , 160.00, 15, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('339', '7', '15', '0', '1158', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '15', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '264', '16', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '264';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 264, 0, 0
                    , 170.00, -16, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 170.00,
                        buyQuantity =buyQuantity+-16, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "16*2021-12-15*170.00," WHERE transferproductid = 1159;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('264', '1', '16', '1', '1159', 'تحويل منتجات من المخزن', 'storemovementController.php', '16.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('264', '7', '16', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 264, 0, 0
                    , 170.00, 16, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+16, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('264', '7', '16', '0', '1159', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '16', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '60', '15', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '60';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 60, 0, 0
                    , 155.00, -15, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 155.00,
                        buyQuantity =buyQuantity+-15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "15*2021-12-15*155.00," WHERE transferproductid = 1160;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('60', '1', '15', '1', '1160', 'تحويل منتجات من المخزن', 'storemovementController.php', '15.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('60', '7', '15', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 60, 0, 0
                    , 155.00, 15, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('60', '7', '15', '0', '1160', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '15', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '136', '11', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '136';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 136, 0, 0
                    , 160.00, -11, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-11, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "11*2021-12-15*160.00," WHERE transferproductid = 1161;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('136', '1', '11', '1', '1161', 'تحويل منتجات من المخزن', 'storemovementController.php', '11.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('136', '7', '11', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 136, 0, 0
                    , 160.00, 11, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+11, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('136', '7', '11', '0', '1161', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '11', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '604', '7', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '1686';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 604, 0, 0
                    , 180.00, -7, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 180.00,
                        buyQuantity =buyQuantity+-7, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "7*2021-12-15*180.00," WHERE transferproductid = 1162;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('604', '1', '7', '1', '1162', 'تحويل منتجات من المخزن', 'storemovementController.php', '7.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('604', '7', '7', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 604, 0, 0
                    , 180.00, 7, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+7, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('604', '7', '7', '0', '1162', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '7', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '605', '1', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '1687';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 605, 0, 0
                    , 180.00, -1, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 180.00,
                        buyQuantity =buyQuantity+-1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "1*2021-12-15*180.00," WHERE transferproductid = 1163;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('605', '1', '1', '1', '1163', 'تحويل منتجات من المخزن', 'storemovementController.php', '1.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('605', '7', '1', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 605, 0, 0
                    , 180.00, 1, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('605', '7', '1', '0', '1163', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '1', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '606', '1', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '1688';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 606, 0, 0
                    , 180.00, -1, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 180.00,
                        buyQuantity =buyQuantity+-1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "1*2021-12-15*180.00," WHERE transferproductid = 1164;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('606', '1', '1', '1', '1164', 'تحويل منتجات من المخزن', 'storemovementController.php', '1.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('606', '7', '1', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 606, 0, 0
                    , 180.00, 1, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('606', '7', '1', '0', '1164', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '1', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '607', '3', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '1689';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 607, 0, 0
                    , 180.00, -3, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 180.00,
                        buyQuantity =buyQuantity+-3, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "3*2021-12-15*180.00," WHERE transferproductid = 1165;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('607', '1', '3', '1', '1165', 'تحويل منتجات من المخزن', 'storemovementController.php', '3.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('607', '7', '3', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 607, 0, 0
                    , 180.00, 3, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+3, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('607', '7', '3', '0', '1165', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '3', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '374', '20', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '125', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '374';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 374, 0, 0
                    , 160.00, -20, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-20, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "20*2021-12-15*160.00," WHERE transferproductid = 1166;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('374', '1', '20', '1', '1166', 'تحويل منتجات من المخزن', 'storemovementController.php', '145.00', '125', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('374', '7', '20', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 374, 0, 0
                    , 160.00, 20, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+20, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('374', '7', '20', '0', '1166', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '20', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '378', '9', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '378';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 378, 0, 0
                    , 160.00, -9, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-9, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "9*2021-12-15*160.00," WHERE transferproductid = 1167;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('378', '1', '9', '1', '1167', 'تحويل منتجات من المخزن', 'storemovementController.php', '9.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('378', '7', '9', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 378, 0, 0
                    , 160.00, 9, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+9, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('378', '7', '9', '0', '1167', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '9', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '239', '10', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '10', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '239';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 239, 0, 0
                    , 170.00, -10, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 170.00,
                        buyQuantity =buyQuantity+-10, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "10*2021-12-15*170.00," WHERE transferproductid = 1168;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('239', '1', '10', '1', '1168', 'تحويل منتجات من المخزن', 'storemovementController.php', '20.00', '10', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('239', '7', '10', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 239, 0, 0
                    , 170.00, 10, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+10, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('239', '7', '10', '0', '1168', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '10', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '334', '8', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '10', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '334';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 334, 0, 0
                    , 180.00, -8, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 180.00,
                        buyQuantity =buyQuantity+-8, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "8*2021-12-15*180.00," WHERE transferproductid = 1169;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('334', '1', '8', '1', '1169', 'تحويل منتجات من المخزن', 'storemovementController.php', '18.00', '10', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('334', '7', '8', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 334, 0, 0
                    , 180.00, 8, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+8, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('334', '7', '8', '0', '1169', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '8', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '372', '13', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '15', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '372';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 372, 0, 0
                    , 160.00, -13, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-13, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "13*2021-12-15*160.00," WHERE transferproductid = 1170;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('372', '1', '13', '1', '1170', 'تحويل منتجات من المخزن', 'storemovementController.php', '28.00', '15', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('372', '7', '13', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 372, 0, 0
                    , 160.00, 13, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+13, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('372', '7', '13', '0', '1170', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '13', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '341', '22', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '341';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 341, 0, 0
                    , 120.00, -22, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-22, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "22*2021-12-15*120.00," WHERE transferproductid = 1171;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('341', '1', '22', '1', '1171', 'تحويل منتجات من المخزن', 'storemovementController.php', '22.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('341', '7', '22', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 341, 0, 0
                    , 120.00, 22, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+22, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('341', '7', '22', '0', '1171', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '22', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '354', '12', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '14', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '354';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 354, 0, 0
                    , 120.00, -12, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-12, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "12*2021-12-15*120.00," WHERE transferproductid = 1172;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('354', '1', '12', '1', '1172', 'تحويل منتجات من المخزن', 'storemovementController.php', '26.00', '14', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('354', '7', '12', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 354, 0, 0
                    , 120.00, 12, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+12, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('354', '7', '12', '0', '1172', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '12', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '362', '13', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '362';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 362, 0, 0
                    , 120.00, -13, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-13, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "13*2021-12-15*120.00," WHERE transferproductid = 1173;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('362', '1', '13', '1', '1173', 'تحويل منتجات من المخزن', 'storemovementController.php', '13.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('362', '7', '13', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 362, 0, 0
                    , 120.00, 13, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+13, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('362', '7', '13', '0', '1173', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '13', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '365', '22', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '21', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '365';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 365, 0, 0
                    , 120.00, -22, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-22, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "22*2021-12-15*120.00," WHERE transferproductid = 1174;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('365', '1', '22', '1', '1174', 'تحويل منتجات من المخزن', 'storemovementController.php', '43.00', '21', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('365', '7', '22', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 365, 0, 0
                    , 120.00, 22, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+22, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('365', '7', '22', '0', '1174', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '22', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '347', '10', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '347';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 347, 0, 0
                    , 120.00, -10, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-10, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "10*2021-12-15*120.00," WHERE transferproductid = 1175;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('347', '1', '10', '1', '1175', 'تحويل منتجات من المخزن', 'storemovementController.php', '10.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('347', '7', '10', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 347, 0, 0
                    , 120.00, 10, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+10, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('347', '7', '10', '0', '1175', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '10', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '361', '4', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '6', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '361';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 361, 0, 0
                    , 120.00, -4, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-4, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "4*2021-12-15*120.00," WHERE transferproductid = 1176;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('361', '1', '4', '1', '1176', 'تحويل منتجات من المخزن', 'storemovementController.php', '10.00', '6', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('361', '7', '4', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 361, 0, 0
                    , 120.00, 4, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+4, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('361', '7', '4', '0', '1176', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '4', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '352', '12', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '18', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '352';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 352, 0, 0
                    , 120.00, -12, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-12, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "12*2021-12-15*120.00," WHERE transferproductid = 1177;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('352', '1', '12', '1', '1177', 'تحويل منتجات من المخزن', 'storemovementController.php', '30.00', '18', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('352', '7', '12', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 352, 0, 0
                    , 120.00, 12, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+12, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('352', '7', '12', '0', '1177', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '12', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '364', '19', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '17', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '364';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 364, 0, 0
                    , 120.00, -19, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-19, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "19*2021-12-15*120.00," WHERE transferproductid = 1178;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('364', '1', '19', '1', '1178', 'تحويل منتجات من المخزن', 'storemovementController.php', '36.00', '17', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('364', '7', '19', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 364, 0, 0
                    , 120.00, 19, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+19, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('364', '7', '19', '0', '1178', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '19', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '359', '17', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '17', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '359';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 359, 0, 0
                    , 120.00, -17, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-17, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "17*2021-12-15*120.00," WHERE transferproductid = 1179;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('359', '1', '17', '1', '1179', 'تحويل منتجات من المخزن', 'storemovementController.php', '34.00', '17', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('359', '7', '17', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 359, 0, 0
                    , 120.00, 17, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+17, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('359', '7', '17', '0', '1179', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '17', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '74', '25', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '44', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '74';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 74, 0, 0
                    , 165.00, -25, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 165.00,
                        buyQuantity =buyQuantity+-25, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "25*2021-12-15*165.00," WHERE transferproductid = 1180;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('74', '1', '25', '1', '1180', 'تحويل منتجات من المخزن', 'storemovementController.php', '69.00', '44', '1', '2021-12-15','0','0');
UPDATE storedetail SET  productquantity = '25', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '1245';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 74, 0, 0
                    , 165.00, 25, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+25, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('74', '7', '25', '0', '1180', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0.00', '25', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '340', '7', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '340';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 340, 0, 0
                    , 120.00, -7, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-7, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "7*2021-12-15*120.00," WHERE transferproductid = 1181;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('340', '1', '7', '1', '1181', 'تحويل منتجات من المخزن', 'storemovementController.php', '7.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('340', '7', '7', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 340, 0, 0
                    , 120.00, 7, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+7, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('340', '7', '7', '0', '1181', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '7', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '609', '8', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '1691';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 609, 0, 0
                    , 120.00, -8, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-8, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "8*2021-12-15*120.00," WHERE transferproductid = 1182;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('609', '1', '8', '1', '1182', 'تحويل منتجات من المخزن', 'storemovementController.php', '8.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('609', '7', '8', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 609, 0, 0
                    , 120.00, 8, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+8, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('609', '7', '8', '0', '1182', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '8', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '356', '26', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '24', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '356';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 356, 0, 0
                    , 120.00, -26, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-26, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "26*2021-12-15*120.00," WHERE transferproductid = 1183;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('356', '1', '26', '1', '1183', 'تحويل منتجات من المخزن', 'storemovementController.php', '50.00', '24', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('356', '7', '26', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 356, 0, 0
                    , 120.00, 26, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+26, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('356', '7', '26', '0', '1183', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '26', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '343', '19', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '21', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '343';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 343, 0, 0
                    , 120.00, -19, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-19, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "19*2021-12-15*120.00," WHERE transferproductid = 1184;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('343', '1', '19', '1', '1184', 'تحويل منتجات من المخزن', 'storemovementController.php', '40.00', '21', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('343', '7', '19', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 343, 0, 0
                    , 120.00, 19, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+19, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('343', '7', '19', '0', '1184', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '19', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '348', '18', '2021-12-15', '1', '0','171',null,null,'2021-12-15 16:36:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '14', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '348';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 348, 0, 0
                    , 120.00, -18, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-18, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "18*2021-12-15*120.00," WHERE transferproductid = 1185;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('348', '1', '18', '1', '1185', 'تحويل منتجات من المخزن', 'storemovementController.php', '32.00', '14', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('348', '7', '18', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 348, 0, 0
                    , 120.00, 18, 0, 0, 1, '2021-12-15 16:36:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+18, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:36:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('348', '7', '18', '0', '1185', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '18', '1', '2021-12-15','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:06:35";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:36:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 16:36:35', '1', 'editshow', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:08:25";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:38:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 16:38:25', '1', 'add', '41.233.39.117', '', '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(172,1,4,350,10,'2021-12-15',1,0, '' ,0,0,0,0,0,'2021-12-15 16:38:25',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '350';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 350, 0, 0
                    , 160.00, -10, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-10, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "10*2021-12-15*160.00," WHERE transferproductid = 1186;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('350', '1', '10', '1', '1186', 'تحويل منتجات من المخزن', 'storemovementController.php', '10.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('350', '4', '10', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 4, 350, 0, 0
                    , 160.00, 10, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+10, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('350', '4', '10', '0', '1186', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '10', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '4', '358', '15', '2021-12-15', '1', '0','172',null,null,'2021-12-15 16:38:25',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '358';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 358, 0, 0
                    , 160.00, -15, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "15*2021-12-15*160.00," WHERE transferproductid = 1187;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('358', '1', '15', '1', '1187', 'تحويل منتجات من المخزن', 'storemovementController.php', '15.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('358', '4', '15', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 4, 358, 0, 0
                    , 160.00, 15, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('358', '4', '15', '0', '1187', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '15', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '4', '357', '9', '2021-12-15', '1', '0','172',null,null,'2021-12-15 16:38:25',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '357';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 357, 0, 0
                    , 160.00, -9, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-9, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "9*2021-12-15*160.00," WHERE transferproductid = 1188;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('357', '1', '9', '1', '1188', 'تحويل منتجات من المخزن', 'storemovementController.php', '9.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('357', '4', '9', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 4, 357, 0, 0
                    , 160.00, 9, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+9, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('357', '4', '9', '0', '1188', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '9', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '4', '164', '17', '2021-12-15', '1', '0','172',null,null,'2021-12-15 16:38:25',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '12', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '164';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 164, 0, 0
                    , 160.00, -17, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-17, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "17*2021-12-15*160.00," WHERE transferproductid = 1189;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('164', '1', '17', '1', '1189', 'تحويل منتجات من المخزن', 'storemovementController.php', '29.00', '12', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('164', '4', '17', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 4, 164, 0, 0
                    , 160.00, 17, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+17, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('164', '4', '17', '0', '1189', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '17', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '4', '515', '11', '2021-12-15', '1', '0','172',null,null,'2021-12-15 16:38:25',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '1', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '515';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 515, 0, 0
                    , 220.00, -11, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyprice = 220.00,
                        buyQuantity =buyQuantity+-11, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "11*2021-12-15*220.00," WHERE transferproductid = 1190;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('515', '1', '11', '1', '1190', 'تحويل منتجات من المخزن', 'storemovementController.php', '12.00', '1', '1', '2021-12-15','0','0');
UPDATE storedetail SET  productquantity = '24', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '789';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 4, 515, 0, 0
                    , 220.00, 11, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+11, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('515', '4', '11', '0', '1190', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '13.00', '24', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '4', '239', '10', '2021-12-15', '1', '0','172',null,null,'2021-12-15 16:38:25',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '239';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 239, 0, 0
                    , 170.00, -10, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyprice = 170.00,
                        buyQuantity =buyQuantity+-10, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "10*2021-12-15*170.00," WHERE transferproductid = 1191;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('239', '1', '10', '1', '1191', 'تحويل منتجات من المخزن', 'storemovementController.php', '10.00', '0', '1', '2021-12-15','0','0');
UPDATE storedetail SET  productquantity = '10', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '704';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 4, 239, 0, 0
                    , 170.00, 10, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+10, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('239', '4', '10', '0', '1191', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0.00', '10', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '4', '361', '6', '2021-12-15', '1', '0','172',null,null,'2021-12-15 16:38:25',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '361';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 361, 0, 0
                    , 120.00, -6, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-6, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "6*2021-12-15*120.00," WHERE transferproductid = 1192;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('361', '1', '6', '1', '1192', 'تحويل منتجات من المخزن', 'storemovementController.php', '6.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('361', '4', '6', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 4, 361, 0, 0
                    , 120.00, 6, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+6, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('361', '4', '6', '0', '1192', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '6', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '4', '338', '4', '2021-12-15', '1', '0','172',null,null,'2021-12-15 16:38:25',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '338';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 338, 0, 0
                    , 160.00, -4, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-4, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "4*2021-12-15*160.00," WHERE transferproductid = 1193;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('338', '1', '4', '1', '1193', 'تحويل منتجات من المخزن', 'storemovementController.php', '4.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('338', '4', '4', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 4, 338, 0, 0
                    , 160.00, 4, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+4, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('338', '4', '4', '0', '1193', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '4', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '4', '370', '12', '2021-12-15', '1', '0','172',null,null,'2021-12-15 16:38:25',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '10', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '370';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 370, 0, 0
                    , 160.00, -12, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-12, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "12*2021-12-15*160.00," WHERE transferproductid = 1194;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('370', '1', '12', '1', '1194', 'تحويل منتجات من المخزن', 'storemovementController.php', '22.00', '10', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('370', '4', '12', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 4, 370, 0, 0
                    , 160.00, 12, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+12, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('370', '4', '12', '0', '1194', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '12', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '4', '334', '10', '2021-12-15', '1', '0','172',null,null,'2021-12-15 16:38:25',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '334';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 334, 0, 0
                    , 180.00, -10, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyprice = 180.00,
                        buyQuantity =buyQuantity+-10, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "10*2021-12-15*180.00," WHERE transferproductid = 1195;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('334', '1', '10', '1', '1195', 'تحويل منتجات من المخزن', 'storemovementController.php', '10.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('334', '4', '10', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 4, 334, 0, 0
                    , 180.00, 10, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+10, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('334', '4', '10', '0', '1195', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '10', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '4', '376', '15', '2021-12-15', '1', '0','172',null,null,'2021-12-15 16:38:25',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '376';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 376, 0, 0
                    , 160.00, -15, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "15*2021-12-15*160.00," WHERE transferproductid = 1196;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('376', '1', '15', '1', '1196', 'تحويل منتجات من المخزن', 'storemovementController.php', '15.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('376', '4', '15', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 4, 376, 0, 0
                    , 160.00, 15, 0, 0, 1, '2021-12-15 16:38:25')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:25' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('376', '4', '15', '0', '1196', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '15', '1', '2021-12-15','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:08:25";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:38:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 16:38:25', '1', 'editshow', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:08:54";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:38:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 16:38:54', '1', 'add', '41.233.39.117', '', '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(173,1,8,374,20,'2021-12-15',1,0, '' ,0,0,0,0,0,'2021-12-15 16:38:54',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '105', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '374';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 374, 0, 0
                    , 160.00, -20, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-20, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "20*2021-12-15*160.00," WHERE transferproductid = 1197;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('374', '1', '20', '1', '1197', 'تحويل منتجات من المخزن', 'storemovementController.php', '125.00', '105', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('374', '8', '20', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 374, 0, 0
                    , 160.00, 20, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+20, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('374', '8', '20', '0', '1197', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '20', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '339', '15', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '339';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 339, 0, 0
                    , 160.00, -15, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "15*2021-12-15*160.00," WHERE transferproductid = 1198;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('339', '1', '15', '1', '1198', 'تحويل منتجات من المخزن', 'storemovementController.php', '15.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('339', '8', '15', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 339, 0, 0
                    , 160.00, 15, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('339', '8', '15', '0', '1198', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '15', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '63', '20', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '63';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 63, 0, 0
                    , 155.00, -20, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 155.00,
                        buyQuantity =buyQuantity+-20, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "20*2021-12-15*155.00," WHERE transferproductid = 1199;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('63', '1', '20', '1', '1199', 'تحويل منتجات من المخزن', 'storemovementController.php', '20.00', '0', '1', '2021-12-15','0','0');
UPDATE storedetail SET  productquantity = '20', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '1115';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 63, 0, 0
                    , 155.00, 20, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+20, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('63', '8', '20', '0', '1199', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0.00', '20', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '61', '13', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '61';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 61, 0, 0
                    , 155.00, -13, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 155.00,
                        buyQuantity =buyQuantity+-13, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "13*2021-12-15*155.00," WHERE transferproductid = 1200;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('61', '1', '13', '1', '1200', 'تحويل منتجات من المخزن', 'storemovementController.php', '13.00', '0', '1', '2021-12-15','0','0');
UPDATE storedetail SET  productquantity = '13', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '1113';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 61, 0, 0
                    , 155.00, 13, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+13, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('61', '8', '13', '0', '1200', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0.00', '13', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '69', '25', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '9', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '69';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 69, 0, 0
                    , 155.00, -25, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 155.00,
                        buyQuantity =buyQuantity+-25, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "25*2021-12-15*155.00," WHERE transferproductid = 1201;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('69', '1', '25', '1', '1201', 'تحويل منتجات من المخزن', 'storemovementController.php', '34.00', '9', '1', '2021-12-15','0','0');
UPDATE storedetail SET  productquantity = '25', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '1121';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 69, 0, 0
                    , 155.00, 25, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+25, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('69', '8', '25', '0', '1201', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0.00', '25', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '335', '9', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '335';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 335, 0, 0
                    , 160.00, -9, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-9, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "9*2021-12-15*160.00," WHERE transferproductid = 1202;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('335', '1', '9', '1', '1202', 'تحويل منتجات من المخزن', 'storemovementController.php', '9.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('335', '8', '9', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 335, 0, 0
                    , 160.00, 9, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+9, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('335', '8', '9', '0', '1202', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '9', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '329', '8', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '329';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 329, 0, 0
                    , 155.00, -8, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 155.00,
                        buyQuantity =buyQuantity+-8, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "8*2021-12-15*155.00," WHERE transferproductid = 1203;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('329', '1', '8', '1', '1203', 'تحويل منتجات من المخزن', 'storemovementController.php', '8.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('329', '8', '8', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 329, 0, 0
                    , 155.00, 8, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+8, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('329', '8', '8', '0', '1203', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '8', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '370', '10', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '370';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 370, 0, 0
                    , 160.00, -10, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-10, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "10*2021-12-15*160.00," WHERE transferproductid = 1204;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('370', '1', '10', '1', '1204', 'تحويل منتجات من المخزن', 'storemovementController.php', '10.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('370', '8', '10', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 370, 0, 0
                    , 160.00, 10, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+10, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('370', '8', '10', '0', '1204', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '10', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '372', '15', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '372';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 372, 0, 0
                    , 160.00, -15, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 160.00,
                        buyQuantity =buyQuantity+-15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "15*2021-12-15*160.00," WHERE transferproductid = 1205;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('372', '1', '15', '1', '1205', 'تحويل منتجات من المخزن', 'storemovementController.php', '15.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('372', '8', '15', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 372, 0, 0
                    , 160.00, 15, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('372', '8', '15', '0', '1205', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '15', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '333', '15', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '333';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 333, 0, 0
                    , 120.00, -15, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "15*2021-12-15*120.00," WHERE transferproductid = 1206;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('333', '1', '15', '1', '1206', 'تحويل منتجات من المخزن', 'storemovementController.php', '15.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('333', '8', '15', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 333, 0, 0
                    , 120.00, 15, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('333', '8', '15', '0', '1206', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '15', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '365', '21', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '365';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 365, 0, 0
                    , 120.00, -21, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-21, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "21*2021-12-15*120.00," WHERE transferproductid = 1207;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('365', '1', '21', '1', '1207', 'تحويل منتجات من المخزن', 'storemovementController.php', '21.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('365', '8', '21', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 365, 0, 0
                    , 120.00, 21, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+21, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('365', '8', '21', '0', '1207', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '21', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '342', '12', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '342';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 342, 0, 0
                    , 120.00, -12, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-12, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "12*2021-12-15*120.00," WHERE transferproductid = 1208;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('342', '1', '12', '1', '1208', 'تحويل منتجات من المخزن', 'storemovementController.php', '12.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('342', '8', '12', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 342, 0, 0
                    , 120.00, 12, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+12, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('342', '8', '12', '0', '1208', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '12', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '354', '14', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '354';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 354, 0, 0
                    , 120.00, -14, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-14, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "14*2021-12-15*120.00," WHERE transferproductid = 1209;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('354', '1', '14', '1', '1209', 'تحويل منتجات من المخزن', 'storemovementController.php', '14.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('354', '8', '14', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 354, 0, 0
                    , 120.00, 14, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+14, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('354', '8', '14', '0', '1209', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '14', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '355', '16', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '355';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 355, 0, 0
                    , 120.00, -16, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-16, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "16*2021-12-15*120.00," WHERE transferproductid = 1210;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('355', '1', '16', '1', '1210', 'تحويل منتجات من المخزن', 'storemovementController.php', '16.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('355', '8', '16', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 355, 0, 0
                    , 120.00, 16, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+16, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('355', '8', '16', '0', '1210', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '16', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '49', '15', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '49';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 49, 0, 0
                    , 125.00, -15, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 125.00,
                        buyQuantity =buyQuantity+-15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "15*2021-12-15*125.00," WHERE transferproductid = 1211;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('49', '1', '15', '1', '1211', 'تحويل منتجات من المخزن', 'storemovementController.php', '15.00', '0', '1', '2021-12-15','0','0');
UPDATE storedetail SET  productquantity = '15', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '1101';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 49, 0, 0
                    , 125.00, 15, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('49', '8', '15', '0', '1211', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0.00', '15', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '352', '18', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '352';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 352, 0, 0
                    , 120.00, -18, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-18, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "18*2021-12-15*120.00," WHERE transferproductid = 1212;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('352', '1', '18', '1', '1212', 'تحويل منتجات من المخزن', 'storemovementController.php', '18.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('352', '8', '18', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 352, 0, 0
                    , 120.00, 18, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+18, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('352', '8', '18', '0', '1212', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '18', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '364', '17', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '364';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 364, 0, 0
                    , 120.00, -17, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-17, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "17*2021-12-15*120.00," WHERE transferproductid = 1213;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('364', '1', '17', '1', '1213', 'تحويل منتجات من المخزن', 'storemovementController.php', '17.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('364', '8', '17', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 364, 0, 0
                    , 120.00, 17, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+17, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('364', '8', '17', '0', '1213', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '17', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '359', '17', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '359';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 359, 0, 0
                    , 120.00, -17, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-17, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "17*2021-12-15*120.00," WHERE transferproductid = 1214;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('359', '1', '17', '1', '1214', 'تحويل منتجات من المخزن', 'storemovementController.php', '17.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('359', '8', '17', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 359, 0, 0
                    , 120.00, 17, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+17, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('359', '8', '17', '0', '1214', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '17', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '356', '24', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '356';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 356, 0, 0
                    , 120.00, -24, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "24*2021-12-15*120.00," WHERE transferproductid = 1215;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('356', '1', '24', '1', '1215', 'تحويل منتجات من المخزن', 'storemovementController.php', '24.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('356', '8', '24', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 356, 0, 0
                    , 120.00, 24, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('356', '8', '24', '0', '1215', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '24', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '343', '21', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '343';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 343, 0, 0
                    , 120.00, -21, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-21, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "21*2021-12-15*120.00," WHERE transferproductid = 1216;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('343', '1', '21', '1', '1216', 'تحويل منتجات من المخزن', 'storemovementController.php', '21.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('343', '8', '21', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 343, 0, 0
                    , 120.00, 21, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+21, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('343', '8', '21', '0', '1216', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '21', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '348', '14', '2021-12-15', '1', '0','173',null,null,'2021-12-15 16:38:54',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '348';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 348, 0, 0
                    , 120.00, -14, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyprice = 120.00,
                        buyQuantity =buyQuantity+-14, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "14*2021-12-15*120.00," WHERE transferproductid = 1217;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('348', '1', '14', '1', '1217', 'تحويل منتجات من المخزن', 'storemovementController.php', '14.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('348', '8', '14', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 8, 348, 0, 0
                    , 120.00, 14, 0, 0, 1, '2021-12-15 16:38:54')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+14, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 16:38:54' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('348', '8', '14', '0', '1217', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '14', '1', '2021-12-15','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:08:55";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:38:55", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 16:38:55', '1', 'editshow', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 13:10:46";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 16:40:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-15 16:40:46', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 1;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 14:29:57";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 17:59:57", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2021-12-15 17:59:57', '7', '', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 14:31:27";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 18:01:27", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2021-12-15 18:01:27', '7', 'add', '156.160.238.195', '', '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 =590
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(48,@clientdebt,@clientname);
UPDATE client SET  clientdebt = '205' , clientdate = '2021-12-15 18:01:27', userid = '7' WHERE clientid = '48';
UPDATE client SET  inUse = 0 where clientid = 48;
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 ('48','480.00','275','1','ايصال تحصيل (( قبض من عميل ))','590', '205', '2021-12-15 17:59:57', '7', 'clientPayedDeptController.php', '   ', '275', '0', null, '0', null, null,'', '-1','1','1','1','1');
UPDATE save SET  savecurrentvalue = '1580',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1305.00','275', '0', '5', 'ايصال تحصيل (( قبض من عميل ))', '590', '1580', '2021-12-15 18:01:27', '7',  'clientPayedDeptController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '275', '275', '2021-12-15', '7', '0', '0', '2021-12-15 18:01:27','اضافة ايصال سداد للعميل ام فاطمه','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('851', '139', '275', '','0');
UPDATE accountstree SET name = 'خزينة محل عبدالله', customName = 'خزينة محل عبدالله', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-21344', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '139';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('851', '101', '275', '','0');
UPDATE accountstree SET name = 'ام فاطمه', customName = 'ام فاطمه', parent = '23', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-275', theOrder = '0', layingOrder = '',reportid = '0' WHERE id = '101';
UPDATE clientdebtchange SET clientid = '48', clientdebtchangebefore = '480.00', clientdebtchangeamount = '275.00', clientdebtchangetype = '1', processname = 'ايصال تحصيل (( قبض من عميل ))', clientdebtchangemodelid = '590', clientdebtchangeafter = '205.00', clientdebtchangedate = '2021-12-15 17:59:57', userid = '7', tablename = 'clientPayedDeptController.php', comment = '   ', totalOperationCost = '275.00',discount='', reciptid=null, dailyentryid = '851',seller = '0',currencyId='1',conversionFactor='1',payedInCurrency='1',saveConversionFactor='1' WHERE clientdebtchangeid = '590';
COMMIT;

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

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 14:31:28";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 18:01:28", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2021-12-15 18:01:28', '7', 'sucess', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 14:31:29";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 18:01:30", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2021-12-15 18:01:30', '7', 'show', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 14:31:30";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 18:01:30", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 18:01:30', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 14:31:38";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 18:01:38", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2021-12-15 18:01:38', '7', '', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 14:31:56";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 18:01:56", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2021-12-15 18:01:56', '7', 'add', '156.160.238.195', '', '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 =591
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(48,@clientdebt,@clientname);
UPDATE client SET  clientdebt = '200' , clientdate = '2021-12-15 18:01:56', userid = '7' WHERE clientid = '48';
UPDATE client SET  inUse = 0 where clientid = 48;
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 ('48','205.00','5','1','ايصال تحصيل (( قبض من عميل ))','591', '200', '2021-12-15 18:01:38', '7', 'clientPayedDeptController.php', '   ', '5', '0', null, '0', null, null,'', '-1','1','1','1','1');
UPDATE save SET  savecurrentvalue = '1585',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1580.00','5', '0', '5', 'ايصال تحصيل (( قبض من عميل ))', '591', '1585', '2021-12-15 18:01:56', '7',  'clientPayedDeptController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '5', '5', '2021-12-15', '7', '0', '0', '2021-12-15 18:01:56','اضافة ايصال سداد للعميل ام فاطمه','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('852', '139', '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 = '-21339', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '139';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('852', '101', '5', '','0');
UPDATE accountstree SET name = 'ام فاطمه', customName = 'ام فاطمه', parent = '23', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-280', theOrder = '0', layingOrder = '',reportid = '0' WHERE id = '101';
UPDATE clientdebtchange SET clientid = '48', clientdebtchangebefore = '205.00', clientdebtchangeamount = '5.00', clientdebtchangetype = '1', processname = 'ايصال تحصيل (( قبض من عميل ))', clientdebtchangemodelid = '591', clientdebtchangeafter = '200.00', clientdebtchangedate = '2021-12-15 18:01:38', userid = '7', tablename = 'clientPayedDeptController.php', comment = '   ', totalOperationCost = '5.00',discount='', reciptid=null, dailyentryid = '852',seller = '0',currencyId='1',conversionFactor='1',payedInCurrency='1',saveConversionFactor='1' WHERE clientdebtchangeid = '591';
COMMIT;

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

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

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 15:30:02";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 19:00:02", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2021-12-15 19:00:02', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 15:30:11";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 19:00:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2021-12-15 19:00:11', '1', '', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 15:30:22";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 19:00:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2021-12-15 19:00:22', '1', 'add', '41.233.39.117', '', 'DESKTOP');
BEGIN;
INSERT INTO transfermoney (saveidfrom, saveidto, transfermoneyvalue, transfermoneydate, userid, conditions, dailyentryid , comment) VALUES ('7','9', '1700.00', '2021-12-15', '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 ('1700.00','1700.00', '1', '7', 'تحويل امول الى الخزنة  [ الشيخ وليد ] ', '20', '0', '2021-12-15 19:00:22', '1',  'transfermoneyController.php','0','');
UPDATE save SET  savecurrentvalue = '27325',  userid = '1' WHERE saveid = '9';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('25625.00','1700.00', '0', '9', 'تحويل امول من الخزنة  [ خزينة محل العميد ] ', '20', '27325', '2021-12-15 19:00:22', '1',  'transfermoneyController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '1700', '1700', '2021-12-15', '1', '0', '0', '2021-12-15 19:00:22','اضافة تحويل من خزينة محل العميد الى الشيخ وليد','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('853', '156', '1700.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 = '27325', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '156';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('853', '141', '1700.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 = '-40290', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE transfermoney SET saveidfrom = '7', saveidto = '9', transfermoneyvalue = '1700.00', transfermoneydate = '2021-12-15', userid = '1', conditions = '0' , dailyentryid = '853' , comment = '' WHERE transfermoneyid = '20';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 15:30:22";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 19:00:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2021-12-15 19:00:22', '1', 'sucess', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 15:30:24";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 19:00:24", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2021-12-15 19:00:24', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 15:30:26";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 19:00:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-15 19:00:27', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 15:59:16";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:29:16", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 19:29:16', '7', '', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:01:42";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:31:42", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 19:31:42', '7', 'showDetail', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:01:49";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:31:49", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 19:31:49', '7', '', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:03:44";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:33:44", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2021-12-15 19:33:44', '7', 'showDetail', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:04:47";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:34:47", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 19:34:47', '7', '', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:05:07";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:35:07", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2021-12-15 19:35:07', '7', 'showDetail', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:05:13";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:35:13", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 19:35:13', '7', '', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:05:18";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:35:18", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2021-12-15 19:35:18', '7', 'showDetail', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:05:23";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:35:23", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 19:35:23', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:05:26";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:35:26", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 19:35:26', '7', '', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:08:51";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:38:51", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 19:38:51', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
INSERT INTO client (clientname, clientaddress, clientphone, clientmobile, clientdebt, clientdetails, conditions, clientdate, userid,clientareaid,clientcode,dailyentryid ,rondomtxt,clientStoreIds,obygyPatientId,debtLimit,typeclientid,priceTypeId,card_number,file_faida,specialDiscount,specialDiscountVal,file,addDate,mandobCollectRatio,webApiId,clientRFID,linkedSupplierId,postponeDays,studentid) VALUES ('ام رحمي سكلام' , '', '', '01206585786', '0', '', '0', '2021-12-15 19:40:33', '7', '0','','0','','-10','0','0',',','-1','0','.','0','0','.','2021-12-15','0','0','','0','0','0');
INSERT INTO tamweenclientdetail (clientid, noOfPersonsTamween, noOfPersonsDa3m, cardNum, cardPassword) VALUES ('94', '0', '0', '', '');
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 ('94','0','0','0','إضافة عميل جديد','94', '0', '2021-12-15 19:40:33', '7', 'clientController.php', '', '0', '0', null, '0', null, null,'', '0','1','1','0','1');
INSERT INTO accountstree (name, customName, parent, itemtype, itemfrom, notes, del, userid, mydate, itemtype2, theValue, theOrder, layingOrder,reportid) VALUES ('ام رحمي سكلام', 'ام رحمي سكلام', '23', '3', '0', '', '0', '7', '2021-12-15', '1', '0', '0', '','2');
UPDATE client SET clientname = 'ام رحمي سكلام', clientaddress = '', clientphone = '', clientmobile = '01206585786', clientdebt = '0.00', clientdetails = '', conditions = '0', clientdate = '2021-12-15', userid = '7'  , clientareaid = '0'  ,clientcode = '',dailyentryid = '0' , rondomtxt = '',clientStoreIds = '-10', obygyPatientId = '0' , debtLimit='0' , typeclientid=',',priceTypeId='-1',lastEditUser = '0',card_number = '0',file_faida = '.',specialDiscount = '0',specialDiscountVal = '0',file = '.',mandobCollectRatio='0',clientRFID = '',linkedSupplierId = '0',postponeDays='0', studentid='0' WHERE clientid = '94';
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:12:09";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:42:09", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 19:42:09', '7', 'addAndRetuen', '156.160.238.195', '', '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 061ba282bbc8f1
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(94,@clientdebt,@clientname);
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-15 19:38:51', '061ba282bbc8f1', '94', '0.00', '300', '10', '1', '515', '505', '205', '300', '5', '2021-12-15 19:42:09', '', '7', '0', 'ام رحمي سكلام', '5', '1', '3', '0', 'ام رحمي سكلام', '2' ,'0','','','','','-1','0','0','0','0','0','505','0','','0','0','205','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '300', userid = '7' WHERE clientid = '94';
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 ('94','0.00','300','0','اضافة فاتورة مبيعات','329', '300', '2021-12-15 19:42:09', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '505', '0', null, '0', null, null,'', '0','1','1','300','1');
UPDATE client SET  inUse = 0 where clientid = 94;
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 718;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('280','00450', '329', '1', '450', '1', '270', '270', '0', '', '2', '2021-12-15 19:42:09', '450', '0.00', '0', '5','0','','','0','0','0','0','0','0','2','0','','718-1,');
UPDATE sellbilldetail SET  lastbuyprice = 280.00 , meanbuyprice = 267.50, lastbuyprice_withDiscount = 280.00, meanbuyprice_withDiscount = 267.50
                where sellbilldetailid = 693;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (450, '2021-12-15', 264.757281553, 255, 280
                    , 267.5, 280, 267.5, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+264.757281553, sellCostBuyPrice =sellCostBuyPrice+255
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+280, sellCostMeanBuyPrice = sellCostMeanBuyPrice+267.5
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+280, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+267.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 (5, '2021-12-15', 264.757281553, 255, 280
                    , 267.5, 280, 267.5, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+264.757281553, sellCostBuyPrice =sellCostBuyPrice+255
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+280, sellCostMeanBuyPrice = sellCostMeanBuyPrice+267.5
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+280, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+267.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 = '27', userid = '7', storedetaildate = '2021-12-15 19:42:09' WHERE storedetailid = '910';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('450', '5', '1', '1', '329', 'اضافة فاتورة مبيعات', 'sellbillController.php', '28.00', '27', '7', '2021-12-15 19:42:09','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 720;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('210','00251', '329', '1', '251', '1', '245', '245', '0', '', '2', '2021-12-15 19:42:09', '251', '0.00', '0', '5','0','','','0','0','0','0','0','0','2','0','','720-1,');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 210.00, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 210.00
                where sellbilldetailid = 694;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (251, '2021-12-15', 240.242718447, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+240.242718447, 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, '2021-12-15', 240.242718447, 210, 210
                    , 210, 210, 210, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+240.242718447, 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 = '10', userid = '7', storedetaildate = '2021-12-15 19:42:09' WHERE storedetailid = '911';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('251', '5', '1', '1', '329', 'اضافة فاتورة مبيعات', 'sellbillController.php', '11.00', '10', '7', '2021-12-15 19:42:09','0','0');
UPDATE save SET  savecurrentvalue = '1790',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1585.00','205', '0', '5', 'اضافة فاتورة مبيعات', '329', '1790', '2021-12-15 19:42:09', '7',  'sellbillController.php','94','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 505, 465, 490
                    , 477.5, 490, 477.5, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+505, sellCostBuyPrice =sellCostBuyPrice+465
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+490, sellCostMeanBuyPrice = sellCostMeanBuyPrice+477.5
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+490, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+477.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 (94, '2021-12-15', 505, 465, 490
                    , 477.5, 490, 477.5, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+505, sellCostBuyPrice =sellCostBuyPrice+465
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+490, sellCostMeanBuyPrice = sellCostMeanBuyPrice+477.5
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+490, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+477.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, 505, 465, 490
                    , 477.5, 490, 477.5, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+505, netSellCostBuyPrice = netSellCostBuyPrice+465
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+490
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+477.5
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+490
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+477.5
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061ba282bbc8f1 and sellbillId = 329 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:12:10";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:42:10", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 19:42:10', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:12:15";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:42:15", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 19:42:15', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:12:48";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:42:51", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 19:42:52', '7', 'addAndRetuen', '156.160.238.195', '', '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 061ba28f75a480
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(94,@clientdebt,@clientname);
INSERT INTO returnsellbill (returnsellbilldate, returnsellbillserial, returnsellbillclientid, returnsellbilltotaldeptbefor, returnsellbilltotaldeptafter, returnsellbilldiscount, returnsellbilldiscounttype, returnsellbilltotalbill, returnsellbillaftertotalbill, returnsellbilltotalpayed, returnsellbillfinalbill, returnsellbillstoreid, returnsellbillsysdate,comment, userid, conditions, returnsellbillclientname, returnsellbillsaveid, returnsellbildirectpayment, billnameid, sellerid, tempclientName, returnsellQuantity,tax, carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,delbyuserid,billReservation,billReservationDate,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal) VALUES ('2021-12-15 19:42:15', '061ba28f75a480', '94', '300.00', '70', '0', '1', '230', '230', '0', '-230', '5', '2021-12-15 19:42:52', '', '7', '0', 'ام رحمي سكلام','5', '1', '5', '0', 'ام رحمي سكلام', '1', '0', '', '','','','-1','0','0','0','','0','0','0','0','0','0','0','0');
UPDATE client SET  clientdebt = '70', userid = '7' WHERE clientid = '94';
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 ('94','300.00','230','1','اضافة فاتورة مردوات مبيعات','100', '70', '2021-12-15 19:42:52', '7', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '230', '0', null, '0', null, null,'', '0','1','1','230','1');
UPDATE client SET  inUse = 0 where clientid = 94;
INSERT INTO returnsellbilldetail (buyprice, parcode, returnsellbillid, returnsellbilldetailcatid, returnsellbilldetailproductid, returnsellbilldetailquantity, returnsellbilldetailprice, returnsellbilldetailtotalprice, conditions, note, pricetype, discountvalue, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,pricetypepro) VALUES ('210.00', '00127', '100', '1', '127', '1', '230', '230', '0', '', '2', '0', '127', '0.00', '0','5','0','','','0','0','0','0','0','2');
UPDATE returnsellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 1148.55, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 1148.55
                where returnsellbilldetailid = 159;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (127, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 230, 210, 210, 1148.55
                    , 210, 1148.55, 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+210, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+210
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+1148.55, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+210
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+1148.55
                            , 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 (5, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 230, 210, 210, 1148.55
                    , 210, 1148.55, 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+210, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+210
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+1148.55, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+210
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+1148.55
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '7', userid = '7', storedetaildate = '2021-12-15 19:42:52' WHERE storedetailid = '1551';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('127', '5', '1', '0', '100', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '6.00', '7', '7', '2021-12-15 19:42:52','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 230, 210, 210, 1148.55
                    , 210, 1148.55, 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+210, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+210
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+1148.55, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+210
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+1148.55
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (94, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 230, 210, 210, 1148.55
                    , 210, 1148.55, 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+210, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+210
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+1148.55, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+210
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+1148.55
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -230, -210, -210
                    , -1148.55, -210, -1148.55, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-230, netSellCostBuyPrice = netSellCostBuyPrice+-210
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-210
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-1148.55
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-210
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-1148.55
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061ba28f75a480 and sellbillId = 100 and returnsellbillId = 100
-- ----------------------------------------------------------------------------------------------------

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

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061ba292aaac7d
-- ----------------------------------------------------------------------------------------------------

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

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061ba292aaac7d and sellbillId = 330 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:13:36";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:43:36", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 19:43:36', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
INSERT INTO client (clientname, clientaddress, clientphone, clientmobile, clientdebt, clientdetails, conditions, clientdate, userid,clientareaid,clientcode,dailyentryid ,rondomtxt,clientStoreIds,obygyPatientId,debtLimit,typeclientid,priceTypeId,card_number,file_faida,specialDiscount,specialDiscountVal,file,addDate,mandobCollectRatio,webApiId,clientRFID,linkedSupplierId,postponeDays,studentid) VALUES ('ام اسلام الملاحه' , '', '', '01201718034', '230', '', '0', '2021-12-15 19:47:01', '7', '0','','0','','-10','0','10000',',-20,','-1','0','.','0','0','.','2021-12-15','0','0','','0','0','0');
INSERT INTO tamweenclientdetail (clientid, noOfPersonsTamween, noOfPersonsDa3m, cardNum, cardPassword) VALUES ('95', '0', '0', '', '');
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 ('95','0','230','0','إضافة عميل جديد','95', '230', '2021-12-15 19:47:01', '7', 'clientController.php', '', '230', '0', null, '0', null, null,'', '0','1','1','230','1');
INSERT INTO accountstree (name, customName, parent, itemtype, itemfrom, notes, del, userid, mydate, itemtype2, theValue, theOrder, layingOrder,reportid) VALUES ('ام اسلام الملاحه', 'ام اسلام الملاحه', '23', '3', '0', '', '0', '7', '2021-12-15', '1', '0', '0', '','2');
BEGIN;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '230', '230', '2021-12-15', '7', '0', '0', '2021-12-15 19:47:01','تم اضافة عميل ام اسلام الملاحه','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('854', '171', '230', '','0');
UPDATE accountstree SET name = 'ام اسلام الملاحه', customName = 'ام اسلام الملاحه', parent = '23', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '7', mydate = '2021-12-15', itemtype2 = '1', theValue = '230', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '171';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('854', '7', '230', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '7003422.15', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
COMMIT;
UPDATE client SET clientname = 'ام اسلام الملاحه', clientaddress = '', clientphone = '', clientmobile = '01201718034', clientdebt = '230.00', clientdetails = '', conditions = '0', clientdate = '2021-12-15', userid = '7'  , clientareaid = '0'  ,clientcode = '',dailyentryid = '854' , rondomtxt = '',clientStoreIds = '-10', obygyPatientId = '0' , debtLimit='10000' , typeclientid=',-20,',priceTypeId='-1',lastEditUser = '0',card_number = '0',file_faida = '.',specialDiscount = '0',specialDiscountVal = '0',file = '.',mandobCollectRatio='0',clientRFID = '',linkedSupplierId = '0',postponeDays='0', studentid='0' WHERE clientid = '95';
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:17:36";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:47:36", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 19:47:36', '7', 'addAndRetuen', '156.160.238.195', '', '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 061ba2948ceaba
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(95,@clientdebt,@clientname);
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-15 19:43:36', '061ba2948ceaba', '95', '230.00', '680', '0', '1', '950', '950', '500', '450', '5', '2021-12-15 19:47:36', '', '7', '0', 'ام اسلام الملاحه', '5', '1', '3', '0', 'ام اسلام الملاحه', '4' ,'0','','','','','-1','0','0','0','0','0','950','0','','0','0','500','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '680', userid = '7' WHERE clientid = '95';
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 ('95','230.00','450','0','اضافة فاتورة مبيعات','331', '680', '2021-12-15 19:47:36', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '950', '0', null, '0', null, null,'', '0','1','1','450','1');
UPDATE client SET  inUse = 0 where clientid = 95;
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', '331', '1', '563', '1', '230.00', '230', '0', '', '2', '2021-12-15 19:47:36', '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 = 696;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (563, '2021-12-15', 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, '2021-12-15', 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 = '7', userid = '7', storedetaildate = '2021-12-15 19:47:36' WHERE storedetailid = '1550';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('563', '5', '1', '1', '331', 'اضافة فاتورة مبيعات', 'sellbillController.php', '8.00', '7', '7', '2021-12-15 19:47:36','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+2 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', '331', '1', '555', '2', '240.00', '480', '0', '', '2', '2021-12-15 19:47:36', '555', '0.00', '0', '5','0','','','0','0','0','0','0','0','2','0','','2068-2,');
UPDATE sellbilldetail SET  lastbuyprice = 195.00 , meanbuyprice = 195.00, lastbuyprice_withDiscount = 195.00, meanbuyprice_withDiscount = 195.00
                where sellbilldetailid = 697;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (555, '2021-12-15', 480, 390, 390
                    , 390, 390, 390, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 2, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+480, sellCostBuyPrice =sellCostBuyPrice+390
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+390, sellCostMeanBuyPrice = sellCostMeanBuyPrice+390
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+390, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+390
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+2
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (5, '2021-12-15', 480, 390, 390
                    , 390, 390, 390, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+480, sellCostBuyPrice =sellCostBuyPrice+390
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+390, sellCostMeanBuyPrice = sellCostMeanBuyPrice+390
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+390, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+390
                            , 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 = '7', storedetaildate = '2021-12-15 19:47:36' WHERE storedetailid = '1496';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('555', '5', '2', '1', '331', 'اضافة فاتورة مبيعات', 'sellbillController.php', '29.00', '27', '7', '2021-12-15 19:47:36','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1862;
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', '331', '1', '562', '1', '240.00', '240', '0', '', '2', '2021-12-15 19:47:36', '562', '0.00', '0', '5','0','','','0','0','0','0','0','0','2','0','','1862-1,');
UPDATE sellbilldetail SET  lastbuyprice = 225.00 , meanbuyprice = 225.00, lastbuyprice_withDiscount = 225.00, meanbuyprice_withDiscount = 225.00
                where sellbilldetailid = 698;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (562, '2021-12-15', 240, 225, 225
                    , 225, 225, 225, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+240, sellCostBuyPrice =sellCostBuyPrice+225
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+225, sellCostMeanBuyPrice = sellCostMeanBuyPrice+225
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+225, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+225
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (5, '2021-12-15', 240, 225, 225
                    , 225, 225, 225, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+240, sellCostBuyPrice =sellCostBuyPrice+225
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+225, sellCostMeanBuyPrice = sellCostMeanBuyPrice+225
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+225, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+225
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '11', userid = '7', storedetaildate = '2021-12-15 19:47:36' WHERE storedetailid = '1493';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('562', '5', '1', '1', '331', 'اضافة فاتورة مبيعات', 'sellbillController.php', '12.00', '11', '7', '2021-12-15 19:47:36','0','0');
UPDATE save SET  savecurrentvalue = '2580',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2080.00','500', '0', '5', 'اضافة فاتورة مبيعات', '331', '2580', '2021-12-15 19:47:36', '7',  'sellbillController.php','95','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 950, 825, 825
                    , 825, 825, 825, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+950, sellCostBuyPrice =sellCostBuyPrice+825
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+825, sellCostMeanBuyPrice = sellCostMeanBuyPrice+825
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+825, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+825
                            , 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 (95, '2021-12-15', 950, 825, 825
                    , 825, 825, 825, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+950, sellCostBuyPrice =sellCostBuyPrice+825
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+825, sellCostMeanBuyPrice = sellCostMeanBuyPrice+825
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+825, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+825
                            , 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, 950, 825, 825
                    , 825, 825, 825, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+950, netSellCostBuyPrice = netSellCostBuyPrice+825
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+825
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+825
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+825
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+825
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061ba2948ceaba and sellbillId = 331 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:17:36";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:47:36", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 19:47:36', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:17:42";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:47:42", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 19:47:42', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:19:14";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:49:14", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 19:49:14', '7', 'addAndRetuen', '156.160.238.195', '', '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 061ba2a3ed5163
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(95,@clientdebt,@clientname);
INSERT INTO returnsellbill (returnsellbilldate, returnsellbillserial, returnsellbillclientid, returnsellbilltotaldeptbefor, returnsellbilltotaldeptafter, returnsellbilldiscount, returnsellbilldiscounttype, returnsellbilltotalbill, returnsellbillaftertotalbill, returnsellbilltotalpayed, returnsellbillfinalbill, returnsellbillstoreid, returnsellbillsysdate,comment, userid, conditions, returnsellbillclientname, returnsellbillsaveid, returnsellbildirectpayment, billnameid, sellerid, tempclientName, returnsellQuantity,tax, carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,delbyuserid,billReservation,billReservationDate,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal) VALUES ('2021-12-15 19:47:42', '061ba2a3ed5163', '95', '680.00', '210', '0', '1', '470', '470', '0', '-470', '5', '2021-12-15 19:49:14', '', '7', '0', 'ام اسلام الملاحه','5', '1', '5', '0', 'ام اسلام الملاحه', '2', '0', '', '','','','-1','0','0','0','','0','0','0','0','0','0','0','0');
UPDATE client SET  clientdebt = '210', userid = '7' WHERE clientid = '95';
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 ('95','680.00','470','1','اضافة فاتورة مردوات مبيعات','101', '210', '2021-12-15 19:49:14', '7', 'returnsellbillController.php', 'اضافة فاتورة مردوات مبيعات', '470', '0', null, '0', null, null,'', '0','1','1','470','1');
UPDATE client SET  inUse = 0 where clientid = 95;
INSERT INTO returnsellbilldetail (buyprice, parcode, returnsellbillid, returnsellbilldetailcatid, returnsellbilldetailproductid, returnsellbilldetailquantity, returnsellbilldetailprice, returnsellbilldetailtotalprice, conditions, note, pricetype, discountvalue, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,pricetypepro) VALUES ('210.00', '00517', '101', '1', '517', '1', '230.00', '230', '0', '', '1', '0', '517', '0.00', '0','5','0','','','0','0','0','0','0','1');
UPDATE returnsellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 210.00, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 210.00
                where returnsellbilldetailid = 160;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (517, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 230, 210, 210, 210
                    , 210, 210, 0, 0, 1)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+230, returnSellCostBuyPrice = returnSellCostBuyPrice+210, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+210
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+210, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+210
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+210
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+0
                        , netQuantityRet = netQuantityRet+1;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (5, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 230, 210, 210, 210
                    , 210, 210, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+230, returnSellCostBuyPrice = returnSellCostBuyPrice+210, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+210
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+210, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+210
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+210
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '20', userid = '7', storedetaildate = '2021-12-15 19:49:14' WHERE storedetailid = '908';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('517', '5', '1', '0', '101', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '19.00', '20', '7', '2021-12-15 19:49:14','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', '101', '1', '515', '1', '240', '240', '0', '', '1', '0', '515', '0.00', '0','5','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 = 161;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (515, '2021-12-15', 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 (5, '2021-12-15', 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 = '2', userid = '7', storedetaildate = '2021-12-15 19:49:14' WHERE storedetailid = '906';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('515', '5', '1', '0', '101', 'اضافة فاتورة مردودات مبيعات', 'returnsellbillController.php', '1.00', '2', '7', '2021-12-15 19:49:14','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 470, 430, 430, 430
                    , 430, 430, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+470, returnSellCostBuyPrice = returnSellCostBuyPrice+430, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+430
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+430, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+430
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+430
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (95, '2021-12-15', 0, 0, 0
                    , 0, 0, 0, 0
                    , 470, 430, 430, 430
                    , 430, 430, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+0, sellCostBuyPrice =sellCostBuyPrice+0
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+0, sellCostMeanBuyPrice = sellCostMeanBuyPrice+0
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+0, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+0
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+470, returnSellCostBuyPrice = returnSellCostBuyPrice+430, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+430
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+430, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+430
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+430
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, -470, -430, -430
                    , -430, -430, -430, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+-470, netSellCostBuyPrice = netSellCostBuyPrice+-430
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+-430
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+-430
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+-430
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+-430
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061ba2a3ed5163 and sellbillId = 101 and returnsellbillId = 101
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:19:14";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:49:14", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 19:49:14', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:19:20";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:49:20", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 19:49:20', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:19:25";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:49:25", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 19:49:25', '7', '', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:21:03";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 19:51:03", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 19:51:03', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:33:23";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 20:03:23", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('supplierPayedDeptController.php', '2021-12-15 20:03:23', '7', '', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:33:43";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 20:03:43", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('supplierPayedDeptController.php', '2021-12-15 20:03:43', '7', 'add', '156.160.238.195', '', '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', '-14000.00', '2500', '1', 'ايصال دفع لمورد', '22', '-16500', '2021-12-15 20:03:23', '7', 'supplierPayedDeptController.php', '', '0','5', '-1','1','1','1','1');
UPDATE supplier SET  suppliercurrentDebt = '-16500', userid = '7', supplierdate = '2021-12-15 20:03:43'   WHERE supplierid = '1';
UPDATE save SET  savecurrentvalue = '80',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2580.00','2500', '1', '5', 'ايصال دفع لمورد', '22', '80', '2021-12-15 20:03:43', '7',  'supplierPayedDeptController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '2500', '2500', '2021-12-15', '7', '0', '0', '2021-12-15 20:03:43','ايصال دفع لمورد ( مباشر ) ','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('855', '168', '2500', '','0');
UPDATE accountstree SET name = 'مباشر', customName = 'مباشر', parent = '10', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '7', mydate = '2021-12-11', itemtype2 = '1', theValue = '-16500', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '168';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('855', '139', '2500', '','0');
UPDATE accountstree SET name = 'خزينة محل عبدالله', customName = 'خزينة محل عبدالله', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-23839', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '139';
UPDATE supplierdebtchange SET supplierid = '1', supplierdebtchangebefore = '-14000.00', supplierdebtchangeamount = '2500.00', supplierdebtchangetype = '1', processname = 'ايصال دفع لمورد', supplierdebtchangemodelid = '22', supplierdebtchangeafter = '-16500.00', supplierdebtchangedate = '2021-12-15 20:03:23', userid = '7', tablename = 'supplierPayedDeptController.php', comment = '', dailyentryid = '855',saveid = '5',currencyId='1',conversionFactor='1',payedInCurrency='1',saveConversionFactor='1' WHERE supplierdebtchangeid = '22';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:33:44";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 20:03:44", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('supplierPayedDeptController.php', '2021-12-15 20:03:44', '7', 'sucess', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:33:46";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 20:03:46", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('supplierPayedDeptController.php', '2021-12-15 20:03:46', '7', 'show', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:33:46";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 20:03:47", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('supplierReportsController.php', '2021-12-15 20:03:47', '7', '', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:33:56";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 20:03:56", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 20:03:56', '7', '', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 16:33:56";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 20:03:56", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 20:03:56', '7', '', '156.160.238.195', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:04:30";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 20:34:30", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 20:34:30', '1', '', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:04:35";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 20:34:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 20:34:35', '1', '', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:05:06";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 20:35:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 20:35:07', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '11', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '255';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('255', '1', '12', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '-1.00', '11', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:05:08";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 20:35:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 20:35:08', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:05:47";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 20:35:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 20:35:47', '1', 'add', '41.233.39.117', '', '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(174,1,7,255,11,'2021-12-15',1,0, '' ,0,0,0,0,0,'2021-12-15 20:35:47',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '255';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 255, 0, 0
                    , 255.00, -11, 0, 0, 1, '2021-12-15 20:35:47')
                ON DUPLICATE KEY UPDATE buyprice = 255.00,
                        buyQuantity =buyQuantity+-11, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 20:35:47' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "11*2021-12-15*255.00," WHERE transferproductid = 1218;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('255', '1', '11', '1', '1218', 'تحويل منتجات من المخزن', 'storemovementController.php', '11.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('255', '7', '11', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 255, 0, 0
                    , 255.00, 11, 0, 0, 1, '2021-12-15 20:35:47')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+11, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 20:35:47' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('255', '7', '11', '0', '1218', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '11', '1', '2021-12-15','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:05:47";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 20:35:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 20:35:47', '1', 'editshow', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:23:39";
UPDATE user SET loginip = "156.160.238.195", lastactivetime = "2021-12-15 20:53:39", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 20:53:39', '7', 'addsellBill', '156.160.238.195', '', 'DESKTOP');
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:39:23";
UPDATE user SET loginip = "197.41.125.146", lastactivetime = "2021-12-15 21:09:23", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-15 21:09:23', '3', '', '197.41.125.146', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:39:24";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:39:34";
UPDATE user SET loginip = "197.41.125.146", lastactivetime = "2021-12-15 21:09:34", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 21:09:34', '3', 'addsellBill', '197.41.125.146', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:41:49";
UPDATE user SET loginip = "197.41.125.146", lastactivetime = "2021-12-15 21:11:49", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 21:11:49', '3', 'addAndRetuen', '197.41.125.146', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061ba3d6f1d4d7
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-15 21:09:35', '061ba3d6f1d4d7', '1', '0.00', '0', '0', '1', '1230', '1230', '1230', '0', '8', '2021-12-15 21:11:50', '', '3', '0', 'نقدي', '8', '0', '3', '0', 'نقدي', '6' ,'0','','','','','-1','0','0','0','0','0','1230','0','','0','0','1230','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','اضافة فاتورة مبيعات','332', '0', '2021-12-15 21:11:50', '3', 'sellbillController.php', 'اضافة فاتورة مبيعات', '1230', '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 ('195','00126', '332', '1', '126', '2', '210.00', '420', '0', '', '0', '2021-12-15 21:11:50', '126', '0.00', '0', '8','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 195.00 , meanbuyprice = 195.00, lastbuyprice_withDiscount = 195.00, meanbuyprice_withDiscount = 195.00
                where sellbilldetailid = 699;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (126, '2021-12-15', 420, 390, 390
                    , 390, 390, 390, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 2, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+420, sellCostBuyPrice =sellCostBuyPrice+390
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+390, sellCostMeanBuyPrice = sellCostMeanBuyPrice+390
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+390, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+390
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+2
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (8, '2021-12-15', 420, 390, 390
                    , 390, 390, 390, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+420, sellCostBuyPrice =sellCostBuyPrice+390
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+390, sellCostMeanBuyPrice = sellCostMeanBuyPrice+390
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+390, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+390
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '30', userid = '3', storedetaildate = '2021-12-15 21:11:50' WHERE storedetailid = '1533';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('126', '8', '2', '1', '332', 'اضافة فاتورة مبيعات', 'sellbillController.php', '32.00', '30', '3', '2021-12-15 21:11:50','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1312;
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','00516', '332', '1', '516', '1', '210', '210', '0', '', '0', '2021-12-15 21:11:50', '516', '0.00', '0', '8','0','','','0','0','0','0','0','0','0','0','','1312-1,');
UPDATE sellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where sellbilldetailid = 700;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (516, '2021-12-15', 210, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+210, sellCostBuyPrice =sellCostBuyPrice+220
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+220, sellCostMeanBuyPrice = sellCostMeanBuyPrice+220
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+220, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+220
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (8, '2021-12-15', 210, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+210, 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 = '9', userid = '3', storedetaildate = '2021-12-15 21:11:50' WHERE storedetailid = '1206';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('516', '8', '1', '1', '332', 'اضافة فاتورة مبيعات', 'sellbillController.php', '10.00', '9', '3', '2021-12-15 21:11:50','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1310;
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('220','00515', '332', '1', '515', '1', '210', '210', '0', '', '0', '2021-12-15 21:11:50', '515', '0.00', '0', '8','0','','','0','0','0','0','0','0','0','0','','1310-1,');
UPDATE sellbilldetail SET  lastbuyprice = 220.00 , meanbuyprice = 220.00, lastbuyprice_withDiscount = 220.00, meanbuyprice_withDiscount = 220.00
                where sellbilldetailid = 701;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (515, '2021-12-15', 210, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+210, sellCostBuyPrice =sellCostBuyPrice+220
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+220, sellCostMeanBuyPrice = sellCostMeanBuyPrice+220
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+220, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+220
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (8, '2021-12-15', 210, 220, 220
                    , 220, 220, 220, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+210, 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 = '27', userid = '3', storedetaildate = '2021-12-15 21:11:50' WHERE storedetailid = '1205';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('515', '8', '1', '1', '332', 'اضافة فاتورة مبيعات', 'sellbillController.php', '28.00', '27', '3', '2021-12-15 21:11:50','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', '332', '1', '561', '1', '200', '200', '0', '', '0', '2021-12-15 21:11:50', '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 = 702;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (561, '2021-12-15', 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, '2021-12-15', 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 = '26', userid = '3', storedetaildate = '2021-12-15 21:11:50' WHERE storedetailid = '1520';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('561', '8', '1', '1', '332', 'اضافة فاتورة مبيعات', 'sellbillController.php', '27.00', '26', '3', '2021-12-15 21:11:50','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', '332', '1', '382', '1', '190', '190', '0', '', '0', '2021-12-15 21:11:50', '382', '0.00', '0', '8','0','','','0','0','0','0','0','0','0','0','','1254-1,');
UPDATE sellbilldetail SET  lastbuyprice = 190.00 , meanbuyprice = 190.00, lastbuyprice_withDiscount = 190.00, meanbuyprice_withDiscount = 190.00
                where sellbilldetailid = 703;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (382, '2021-12-15', 190, 190, 190
                    , 190, 190, 190, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+190, sellCostBuyPrice =sellCostBuyPrice+190
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+190, sellCostMeanBuyPrice = sellCostMeanBuyPrice+190
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+190, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+190
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (8, '2021-12-15', 190, 190, 190
                    , 190, 190, 190, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+190, sellCostBuyPrice =sellCostBuyPrice+190
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+190, sellCostMeanBuyPrice = sellCostMeanBuyPrice+190
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+190, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+190
                            , 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 = '3', storedetaildate = '2021-12-15 21:11:50' WHERE storedetailid = '1177';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('382', '8', '1', '1', '332', 'اضافة فاتورة مبيعات', 'sellbillController.php', '18.00', '17', '3', '2021-12-15 21:11:50','0','0');
UPDATE save SET  savecurrentvalue = '8530',  userid = '3' WHERE saveid = '8';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('7300.00','1230', '0', '8', 'اضافة فاتورة مبيعات', '332', '8530', '2021-12-15 21:11:50', '3',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 1230, 1230, 1230
                    , 1230, 1230, 1230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1230, sellCostBuyPrice =sellCostBuyPrice+1230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1230
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-15', 1230, 1230, 1230
                    , 1230, 1230, 1230, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1230, sellCostBuyPrice =sellCostBuyPrice+1230
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1230, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1230
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1230, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1230
                            , 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, 1230, 1230, 1230
                    , 1230, 1230, 1230, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+1230, netSellCostBuyPrice = netSellCostBuyPrice+1230
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+1230
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+1230
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+1230
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+1230
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061ba3d6f1d4d7 and sellbillId = 332 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:41:50";
UPDATE user SET loginip = "197.41.125.146", lastactivetime = "2021-12-15 21:11:50", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 21:11:50', '3', 'addsellBill', '197.41.125.146', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:41:53";
UPDATE user SET loginip = "197.41.125.146", lastactivetime = "2021-12-15 21:11:53", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 21:11:54', '3', '', '197.41.125.146', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:45:15";
UPDATE user SET loginip = "197.41.125.146", lastactivetime = "2021-12-15 21:15:15", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 21:15:15', '3', 'addsellBill', '197.41.125.146', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:47:58";

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061b9fc38166ef
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-15 16:31:20', '061b9fc38166ef', '1', '0.00', '0', '0', '1', '165', '165', '165', '0', '3', '2021-12-15 21:17:58', '', null, '0', 'نقدي', '3', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','165','0','','0','0','165','0','0','0','0','0','0','0','0','');
ROLLBACK;

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

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

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:48:12";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:18:12", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 21:18:12', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:48:34";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:18:34", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 21:18:34', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:49:01";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:19:01", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 21:19:01', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:49:16";
UPDATE user SET loginip = "197.41.125.146", lastactivetime = "2021-12-15 21:19:16", deviceType = "DESKTOP" WHERE userid = 3;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 21:19:16', '3', 'addsellBill', '197.41.125.146', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:52:02";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:22:02", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 21:22:02', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:52:13";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:22:13", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 21:22:13', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:52:13";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:22:13", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 21:22:13', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:54:25";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:24:25", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-15 21:24:25', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:54:25";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:24:25", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-15 21:24:25', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:54:30";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:24:30", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('supplierPayedDeptController.php', '2021-12-15 21:24:30', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:54:31";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:24:31", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('supplierPayedDeptController.php', '2021-12-15 21:24:31', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:54:45";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:24:45", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('supplierPayedDeptController.php', '2021-12-15 21:24:45', '5', 'add', '41.45.236.6', '', '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', '-16500.00', '1500', '1', 'ايصال دفع لمورد', '23', '-18000', '2021-12-15 21:24:31', '5', 'supplierPayedDeptController.php', '', '0','3', '-1','1','1','1','1');
UPDATE supplier SET  suppliercurrentDebt = '-18000', userid = '5', supplierdate = '2021-12-15 21:24:45'   WHERE supplierid = '1';
UPDATE save SET  savecurrentvalue = '6465',  userid = '5' WHERE saveid = '3';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('7965.00','1500', '1', '3', 'ايصال دفع لمورد', '23', '6465', '2021-12-15 21:24:45', '5',  'supplierPayedDeptController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '1500', '1500', '2021-12-15', '5', '0', '0', '2021-12-15 21:24:45','ايصال دفع لمورد ( مباشر ) ','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('856', '168', '1500', '','0');
UPDATE accountstree SET name = 'مباشر', customName = 'مباشر', parent = '10', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '7', mydate = '2021-12-11', itemtype2 = '1', theValue = '-18000', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '168';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('856', '137', '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 = '-10205', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '137';
UPDATE supplierdebtchange SET supplierid = '1', supplierdebtchangebefore = '-16500.00', supplierdebtchangeamount = '1500.00', supplierdebtchangetype = '1', processname = 'ايصال دفع لمورد', supplierdebtchangemodelid = '23', supplierdebtchangeafter = '-18000.00', supplierdebtchangedate = '2021-12-15 21:24:31', userid = '5', tablename = 'supplierPayedDeptController.php', comment = '', dailyentryid = '856',saveid = '3',currencyId='1',conversionFactor='1',payedInCurrency='1',saveConversionFactor='1' WHERE supplierdebtchangeid = '23';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:54:45";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:24:45", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('supplierPayedDeptController.php', '2021-12-15 21:24:45', '5', 'sucess', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:54:47";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:24:47", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('supplierPayedDeptController.php', '2021-12-15 21:24:47', '5', 'show', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:54:47";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:24:47", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('supplierReportsController.php', '2021-12-15 21:24:47', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:54:50";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:24:50", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 21:24:50', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:54:50";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:24:50", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 21:24:50', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:57:20";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:27:20", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 21:27:20', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:57:20";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:27:20", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 21:27:20', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:58:17";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:28:17", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 21:28:17', '5', 'addAndRetuen', '41.45.236.6', '', '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 061ba4198ed042
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(92,@clientdebt,@clientname);
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-15 21:27:20', '061ba4198ed042', '92', '-55.00', '100', '0', '1', '300', '300', '145', '155', '3', '2021-12-15 21:28:17', '', '5', '0', 'ام محمود اسكندرية', '3', '1', '3', '0', 'ام محمود اسكندرية', '1' ,'0','','','','','-1','0','0','0','0','0','300','0','','0','0','145','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '100', userid = '5' WHERE clientid = '92';
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 ('92','-55.00','155','0','اضافة فاتورة مبيعات','333', '100', '2021-12-15 21:28:17', '5', 'sellbillController.php', 'اضافة فاتورة مبيعات', '300', '0', null, '0', null, null,'', '0','1','1','155','1');
UPDATE client SET  inUse = 0 where clientid = 92;
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1826;
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 ('270','00254', '333', '1', '254', '1', '300.00', '300', '0', '', '2', '2021-12-15 21:28:17', '254', '0.00', '0', '3','0','','','0','0','0','0','0','0','2','0','','1826-1,');
UPDATE sellbilldetail SET  lastbuyprice = 270.00 , meanbuyprice = 270.00, lastbuyprice_withDiscount = 270.00, meanbuyprice_withDiscount = 270.00
                where sellbilldetailid = 704;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (254, '2021-12-15', 300, 270, 270
                    , 270, 270, 270, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+300, sellCostBuyPrice =sellCostBuyPrice+270
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+270, sellCostMeanBuyPrice = sellCostMeanBuyPrice+270
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+270, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+270
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (3, '2021-12-15', 300, 270, 270
                    , 270, 270, 270, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+300, sellCostBuyPrice =sellCostBuyPrice+270
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+270, sellCostMeanBuyPrice = sellCostMeanBuyPrice+270
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+270, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+270
                            , 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 = '5', storedetaildate = '2021-12-15 21:28:18' WHERE storedetailid = '1463';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('254', '3', '1', '1', '333', 'اضافة فاتورة مبيعات', 'sellbillController.php', '5.00', '4', '5', '2021-12-15 21:28:18','0','0');
UPDATE save SET  savecurrentvalue = '6610',  userid = '5' WHERE saveid = '3';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('6465.00','145', '0', '3', 'اضافة فاتورة مبيعات', '333', '6610', '2021-12-15 21:28:18', '5',  'sellbillController.php','92','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 300, 270, 270
                    , 270, 270, 270, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+300, sellCostBuyPrice =sellCostBuyPrice+270
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+270, sellCostMeanBuyPrice = sellCostMeanBuyPrice+270
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+270, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+270
                            , 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 (92, '2021-12-15', 300, 270, 270
                    , 270, 270, 270, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+300, sellCostBuyPrice =sellCostBuyPrice+270
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+270, sellCostMeanBuyPrice = sellCostMeanBuyPrice+270
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+270, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+270
                            , 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, 300, 270, 270
                    , 270, 270, 270, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+300, netSellCostBuyPrice = netSellCostBuyPrice+270
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+270
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+270
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+270
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+270
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061ba4198ed042 and sellbillId = 333 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:58:18";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:28:18", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 21:28:18', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:58:56";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:28:56", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 21:28:56', '5', 'addAndRetuen', '41.45.236.6', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 061ba41d289ed0
-- ----------------------------------------------------------------------------------------------------

BEGIN;
INSERT INTO sellbill (sellbilldate, sellbillserial, sellbillclientid, sellbilltotaldeptbefor, sellbilltotaldeptafter, sellbilldiscount, sellbilldiscounttype, sellbilltotalbill, sellbillaftertotalbill, sellbilltotalpayed, sellbillfinalbill, sellbillstoreid, sellbillsysdate,comment, userid, conditions, sellbillclientname, sellbillsaveid, sellbildirectpayment, billnameid, sellerid, tempclientName, sellQuantity,tax ,carnumber, cartype, carchase, carmotor,costcenterid,dailyentryid,obygyVisitId,onlineOrderId,delbyuserid,delivery,totalafterdelivery,billReservation,billReservationDate,webApiId,visaAccountId,cashPayed,visaPayed,isBankAccountTransfer,extraDiscountPer,extraDiscountVal,taxOfDiscountPer,taxOfDiscountVal,taxBillNumber,collectionType,collectionDate) VALUES ('2021-12-15 21:28:18', '061ba41d289ed0', '1', '0.00', '0', '5', '1', '185', '180', '180', '0', '3', '2021-12-15 21:28:56', '', '5', '0', 'نقدي', '3', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','180','0','','0','0','180','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '5' WHERE clientid = '1';
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('1','0.00','0','0','اضافة فاتورة مبيعات','334', '0', '2021-12-15 21:28:56', '5', 'sellbillController.php', 'اضافة فاتورة مبيعات', '180', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 1708;
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','00306', '334', '1', '306', '1', '185', '185', '0', '', '1', '2021-12-15 21:28:56', '306', '0.00', '0', '3','0','','','0','0','0','0','0','0','1','0','','1708-1,');
UPDATE sellbilldetail SET  lastbuyprice = 145.00 , meanbuyprice = 145.00, lastbuyprice_withDiscount = 145.00, meanbuyprice_withDiscount = 145.00
                where sellbilldetailid = 705;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (306, '2021-12-15', 180, 145, 145
                    , 145, 145, 145, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+180, 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 (3, '2021-12-15', 180, 145, 145
                    , 145, 145, 145, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+180, 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 = '38', userid = '5', storedetaildate = '2021-12-15 21:28:56' WHERE storedetailid = '1405';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('306', '3', '1', '1', '334', 'اضافة فاتورة مبيعات', 'sellbillController.php', '39.00', '38', '5', '2021-12-15 21:28:56','0','0');
UPDATE save SET  savecurrentvalue = '6790',  userid = '5' WHERE saveid = '3';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('6610.00','180', '0', '3', 'اضافة فاتورة مبيعات', '334', '6790', '2021-12-15 21:28:56', '5',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2021-12-15', 180, 145, 145
                    , 145, 145, 145, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+180, 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;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2021-12-15', 180, 145, 145
                    , 145, 145, 145, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+180, 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;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, 180, 145, 145
                    , 145, 145, 145, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+180, netSellCostBuyPrice = netSellCostBuyPrice+145
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+145
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+145
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+145
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+145
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 061ba41d289ed0 and sellbillId = 334 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:58:56";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:28:56", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 21:28:56', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:59:07";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:29:07", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 21:29:07', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 17:59:07";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:29:07", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 21:29:07', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:00:22";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:30:22", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-15 21:30:22', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:00:22";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:30:22", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-15 21:30:22', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:01:21";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:31:21", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-15 21:31:21', '5', 'add', '41.45.236.6', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('4', 'نظافه وبخور المحل', '', '10', '2021-12-15', '5', '0','-1','3','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '6780',  userid = '5' WHERE saveid = '3';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('6790.00','10', '1', '3', 'إضافة مصروف', '68', '6780', '2021-12-15 21:31:21', '5',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '10', '10', '2021-12-15', '5', '0', '0', '2021-12-15 21:31:21','اضافة اسم مصروف( نظافه وبخور المحل )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('857', '147', '10', '','0');
UPDATE accountstree SET name = 'نظافة', customName = 'نظافة', parent = '14', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-08', itemtype2 = '0', theValue = '505', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '147';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('857', '137', '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 = '-10215', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '137';
UPDATE expenses SET expensestypeid = '4', expensesname = 'نظافه وبخور المحل', expensesdetails = '', expensesValue = '10.00', expensesdate = '2021-12-15', userid = '5', conditions = '0',saveid = '3' , dailyentryid = '857', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '68';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:01:21";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:31:21", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-15 21:31:21', '5', 'sucess', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:01:23";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:31:23", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2021-12-15 21:31:23', '5', 'show', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:01:25";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:31:25", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 21:31:25', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:01:26";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:31:26", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 21:31:26', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:02:10";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:32:10", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 21:32:10', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:02:11";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 21:32:11", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 21:32:11', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:07:30";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 21:37:30", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 21:37:30', '1', '', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:08:19";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 21:38:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 21:38:19', '1', 'add', '41.233.39.117', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '1', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '253';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('253', '1', '1', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '0.00', '1', '1', '2021-12-15','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:08:20";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 21:38:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2021-12-15 21:38:21', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:09:11";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 21:39:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 21:39:11', '1', '', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:09:35";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 21:39:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 21:39:35', '1', 'add', '41.233.39.117', '', '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(175,1,7,253,1,'2021-12-15',1,0, '' ,0,0,0,0,0,'2021-12-15 21:39:35',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '253';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 253, 0, 0
                    , 225.00, -1, 0, 0, 1, '2021-12-15 21:39:35')
                ON DUPLICATE KEY UPDATE buyprice = 225.00,
                        buyQuantity =buyQuantity+-1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 21:39:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "1*2021-12-15*225.00," WHERE transferproductid = 1219;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('253', '1', '1', '1', '1219', 'تحويل منتجات من المخزن', 'storemovementController.php', '1.00', '0', '1', '2021-12-15','0','0');
UPDATE storedetail SET  productquantity = '24', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '1556';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 253, 0, 0
                    , 225.00, 1, 0, 0, 1, '2021-12-15 21:39:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 21:39:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('253', '7', '1', '0', '1219', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '23.00', '24', '1', '2021-12-15','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '7', '402', '1', '2021-12-15', '1', '0','175',null,null,'2021-12-15 21:39:35',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2021-12-15' WHERE storedetailid = '402';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 1, 402, 0, 0
                    , 240.00, -1, 0, 0, 1, '2021-12-15 21:39:35')
                ON DUPLICATE KEY UPDATE buyprice = 240.00,
                        buyQuantity =buyQuantity+-1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 21:39:35' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "1*2021-12-15*240.00," WHERE transferproductid = 1220;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('402', '1', '1', '1', '1220', 'تحويل منتجات من المخزن', 'storemovementController.php', '1.00', '0', '1', '2021-12-15','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('402', '7', '1', '1', '2021-12-15');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2021-12-15', 7, 402, 0, 0
                    , 240.00, 1, 0, 0, 1, '2021-12-15 21:39:35')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2021-12-15 21:39:35' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('402', '7', '1', '0', '1220', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '1', '1', '2021-12-15','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:09:35";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 21:39:35", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 21:39:35', '1', 'sucess', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:09:37";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 21:39:37", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2021-12-15 21:39:37', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:24:03";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 21:54:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-15 21:54:03', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:24:15";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 21:54:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesReportController.php', '2021-12-15 21:54:15', '1', '', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 18:26:30";
UPDATE user SET loginip = "41.233.39.117", lastactivetime = "2021-12-15 21:56:30", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-15 21:56:30', '1', 'show', '41.233.39.117', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 1;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 19:27:25";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 22:57:25", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 22:57:25', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 19:27:26";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 22:57:26", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2021-12-15 22:57:26', '5', '', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 19:27:42";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 22:57:42", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 22:57:42', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 19:27:43";
UPDATE user SET loginip = "41.45.236.6", lastactivetime = "2021-12-15 22:57:43", deviceType = "DESKTOP" WHERE userid = 5;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 22:57:43', '5', 'addsellBill', '41.45.236.6', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 19:52:57";
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 19:53:20";
UPDATE user SET loginip = "197.196.209.81", lastactivetime = "2021-12-15 23:23:20", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2021-12-15 23:23:20', '1', '', '197.196.209.81', '', 'MOBILE');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 19:53:20";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 19:53:52";
UPDATE user SET loginip = "197.196.209.81", lastactivetime = "2021-12-15 23:23:52", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('saveController.php', '2021-12-15 23:23:52', '1', 'show', '197.196.209.81', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 19:54:57";
UPDATE user SET loginip = "197.196.209.81", lastactivetime = "2021-12-15 23:24:57", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 23:24:57', '1', 'show', '197.196.209.81', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2021-12-15 19:55:11";
UPDATE user SET loginip = "197.196.209.81", lastactivetime = "2021-12-15 23:25:11", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2021-12-15 23:25:11', '1', 'show', '197.196.209.81', '', 'MOBILE');
