UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 13:23:51";
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 < "2023-12-08 14:16:28";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 17:46:29", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2023-12-08 17:46:29', '7', '', '197.192.236.7', '', '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 = '0', 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 = '2023-12-08',workerbetweenstores = '1',workshoptimeout = '24',drivertimeout = '3',currancy = 'جنيه',serial='9c2d4cf4cf5d4e24d5070164705832c3a5d1287f641a2960e48e04ae57a2ad0a5441322ca7cf34efd63003fdb348adbd0b61197c7c87d8dd5bc298c352482bc6',allowdateedit = '0', clientcode = '1' ,clientserial = '1',timezone = 'Africa/Cairo' , expiredate ='1' , production ='1' , description='1' , service ='1' , date='1' , limitamount = '0' , measuringunit = '1' , print_amount = '0' , billid = '0' , precentages = '1' , realprice = '1' ,delegate_seller = '0' , storeserial = '1' ,clientfieldrequired ='0' , clientcodname='0' , colortype = '0' , nakdyOnly = '0' , nakdyKashf = '0' , discount_pres_direct = '0' , general_discount = '0' , sells_return = '0' ,scunitname ='0',vatValue = '0.00',syncstructure = '1',showPrevPrices = '0',isOpticProg='1',reportsPlusHours = '2' , showM5zon = '1',restaurantStoreId = '1',restuarantPrintTimeout = '8',sumSameProductForStore = '0', editAllPrice = '1', isCafe = '0' ,isRestaurent = '0' ,productDays = '0',thereIsRestTax = '0',restTaxVal = '0',restPrintLang = '0',taxNameFlag = '0',parcodeDigits = '5' ,specializedParcodeDigits = '7', clientDefaultDebtLimit = '10000' , clientDefaultDebtLimitControl = '0',usedParcode = '0' ,productbycodeimage = '' ,commentClient='تعليق على العميل ',Inventoryevaluation='first',Profitevaluation='first' , delivery='-2',premiums = '0',operationnumEdit = '0',noOfDecimalPlaces = '2',unReviewBills = '0', unReviewBillsPass = '123',billReviewNote = '',tamweenBakery = '0',three_months = '0',six_months = '0',twelve_months = '0',eighteen_months = '0',twentyfour_months = '0',thirty_months = '0',sixthirty_months = '0',fortytwo_months = '0',fortyeight_months = '0',mandobCollectionRatio='0',takeAwayClient = '0',restaurantServiceOn = ',-2,-1,1,',earlyrepayment = '0',visaPay = '0',headerPrint='',headerPrintSand='',printSand='0',makeDailyEntry='0',clientShowTawla='0',billRest='1',suppIsClientToo='0',isCarBill='0',expensesproduct='1',projectshownew='1',showparcode='0',changeBuyPriceChangeSellInBuyBillCtrl = '0',changeBuyPriceChangeSellInProductCtrl = '0',inventoryvaluation = '1',showBillCollectionSearch='0' WHERE programsettingsid = '1';
UPDATE 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 = '0', 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 = '2023-12-08',workerbetweenstores = '1',workshoptimeout = '24',drivertimeout = '3',currancy = 'جنيه',serial='9c2d4cf4cf5d4e24d5070164705832c3a5d1287f641a2960e48e04ae57a2ad0a5441322ca7cf34efd63003fdb348adbd0b61197c7c87d8dd5bc298c352482bc6',allowdateedit = '0', clientcode = '1' ,clientserial = '1',timezone = 'Africa/Cairo' , expiredate ='1' , production ='1' , description='1' , service ='1' , date='1' , limitamount = '0' , measuringunit = '1' , print_amount = '0' , billid = '0' , precentages = '1' , realprice = '1' ,delegate_seller = '0' , storeserial = '1' ,clientfieldrequired ='0' , clientcodname='0' , colortype = '0' , nakdyOnly = '0' , nakdyKashf = '0' , discount_pres_direct = '0' , general_discount = '0' , sells_return = '0' ,scunitname ='0',vatValue = '0.00',syncstructure = '1',showPrevPrices = '0',isOpticProg='1',reportsPlusHours = '2' , showM5zon = '1',restaurantStoreId = '1',restuarantPrintTimeout = '8',sumSameProductForStore = '0', editAllPrice = '1', isCafe = '0' ,isRestaurent = '0' ,productDays = '0',thereIsRestTax = '0',restTaxVal = '0',restPrintLang = '0',taxNameFlag = '0',parcodeDigits = '5' ,specializedParcodeDigits = '7', clientDefaultDebtLimit = '10000' , clientDefaultDebtLimitControl = '0',usedParcode = '0' ,productbycodeimage = '' ,commentClient='تعليق على العميل ',Inventoryevaluation='first',Profitevaluation='first' , delivery='-2',premiums = '0',operationnumEdit = '0',noOfDecimalPlaces = '2',unReviewBills = '0', unReviewBillsPass = '123',billReviewNote = '',tamweenBakery = '0',three_months = '0',six_months = '0',twelve_months = '0',eighteen_months = '0',twentyfour_months = '0',thirty_months = '0',sixthirty_months = '0',fortytwo_months = '0',fortyeight_months = '0',mandobCollectionRatio='0',takeAwayClient = '0',restaurantServiceOn = ',-2,-1,1,',earlyrepayment = '0',visaPay = '0',headerPrint='',headerPrintSand='',printSand='0',makeDailyEntry='0',clientShowTawla='0',billRest='1',suppIsClientToo='0',isCarBill='0',expensesproduct='1',projectshownew='1',showparcode='0',changeBuyPriceChangeSellInBuyBillCtrl = '0',changeBuyPriceChangeSellInProductCtrl = '0',inventoryvaluation = '1',showBillCollectionSearch='0' WHERE programsettingsid = '1';
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 14:16:34";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 14:35:56";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 18:05:56", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 18:05:56', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 14:36:03";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 18:06:03", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 18:06:03', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 14:36:07";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 18:06:07", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 18:06:07', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 14:36:14";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 18:06:14", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 18:06:14', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 16:28:53";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 19:58:53", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 19:58:53', '7', 'addAndRetuen', '197.192.236.7', '', '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 065733ef6b94bb
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(160,@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 ('2023-12-08 18:06:14', '065733ef6b94bb', '160', '760.00', '860', '0', '1', '1100', '1100', '1000', '100', '5', '2023-12-08 19:58:53', '', '7', '0', 'ام بسمله المهاجرين', '5', '1', '3', '0', 'ام بسمله المهاجرين', '2' ,'0','','','','','-1','0','0','0','0','0','1100','0','','0','0','1000','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '860', userid = '7' WHERE clientid = '160';
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 ('160','760.00','100','0','اضافة فاتورة مبيعات','15120', '860', '2023-12-08 19:58:53', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '1100', '0', null, '0', null, null,'', '0','1','1','100','1');
UPDATE client SET  inUse = 0 where clientid = 160;
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 16345;
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 ('550','01479', '15120', '1', '1479', '1', '570', '570', '0', '', '0', '2023-12-08 19:58:53', '1479', '0.00', '0', '5','0','','','0','0','0','0','0','0','0','0','','16345-1,');
UPDATE sellbilldetail SET  lastbuyprice = 550.00 , meanbuyprice = 550.00, lastbuyprice_withDiscount = 550.00, meanbuyprice_withDiscount = 550.00
                where sellbilldetailid = 44870;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1479, '2023-12-08', 570, 550, 550
                    , 550, 550, 550, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+570, sellCostBuyPrice =sellCostBuyPrice+550
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+550, sellCostMeanBuyPrice = sellCostMeanBuyPrice+550
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+550, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+550
                            , 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, '2023-12-08', 570, 550, 550
                    , 550, 550, 550, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+570, sellCostBuyPrice =sellCostBuyPrice+550
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+550, sellCostMeanBuyPrice = sellCostMeanBuyPrice+550
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+550, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+550
                            , 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 = '7', storedetaildate = '2023-12-08 19:58:53' WHERE storedetailid = '5449';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1479', '5', '1', '1', '15120', 'اضافة فاتورة مبيعات', 'sellbillController.php', '1.00', '0', '7', '2023-12-08 19:58:53','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 16343;
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 ('510','01478', '15120', '1', '1478', '1', '530', '530', '0', '', '0', '2023-12-08 19:58:53', '1478', '0.00', '0', '5','0','','','0','0','0','0','0','0','0','0','','16343-1,');
UPDATE sellbilldetail SET  lastbuyprice = 510.00 , meanbuyprice = 510.00, lastbuyprice_withDiscount = 510.00, meanbuyprice_withDiscount = 510.00
                where sellbilldetailid = 44871;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1478, '2023-12-08', 530, 510, 510
                    , 510, 510, 510, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+530, sellCostBuyPrice =sellCostBuyPrice+510
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+510, sellCostMeanBuyPrice = sellCostMeanBuyPrice+510
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+510, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+510
                            , 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, '2023-12-08', 530, 510, 510
                    , 510, 510, 510, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+530, sellCostBuyPrice =sellCostBuyPrice+510
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+510, sellCostMeanBuyPrice = sellCostMeanBuyPrice+510
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+510, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+510
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '2', userid = '7', storedetaildate = '2023-12-08 19:58:53' WHERE storedetailid = '5448';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1478', '5', '1', '1', '15120', 'اضافة فاتورة مبيعات', 'sellbillController.php', '3.00', '2', '7', '2023-12-08 19:58:53','0','0');
UPDATE save SET  savecurrentvalue = '2140',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1140.00','1000', '0', '5', 'اضافة فاتورة مبيعات', '15120', '2140', '2023-12-08 19:58:53', '7',  'sellbillController.php','160','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2023-12-08', 1100, 1060, 1060
                    , 1060, 1060, 1060, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1100, 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 (160, '2023-12-08', 1100, 1060, 1060
                    , 1060, 1060, 1060, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1100, 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, 1100, 1060, 1060
                    , 1060, 1060, 1060, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+1100, netSellCostBuyPrice = netSellCostBuyPrice+1060
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+1060
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+1060
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+1060
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+1060
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 065733ef6b94bb and sellbillId = 15120 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 16:28:54";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 19:58:54", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 19:58:54', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 16:30:44";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 20:00:44", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2023-12-08 20:00:44', '7', '', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 16:30:49";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 20:00:49", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 20:00:49', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 16:33:32";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 20:03:32", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 20:03:32', '7', 'addAndRetuen', '197.192.236.7', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 0657359d23631b
-- ----------------------------------------------------------------------------------------------------

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 ('2023-12-08 20:00:50', '0657359d23631b', '1', '0.00', '0', '20', '1', '400', '380', '380', '0', '5', '2023-12-08 20:03:33', '', '7', '0', 'نقدي', '5', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','380','0','','0','0','380','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','اضافة فاتورة مبيعات','15121', '0', '2023-12-08 20:03:33', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '380', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 16487;
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 ('300','01497', '15121', '1', '1497', '1', '400', '400', '0', '', '1', '2023-12-08 20:03:33', '1497', '0.00', '0', '5','0','','','0','0','0','0','0','0','1','0','','16487-1,');
UPDATE sellbilldetail SET  lastbuyprice = 300.00 , meanbuyprice = 300.00, lastbuyprice_withDiscount = 300.00, meanbuyprice_withDiscount = 300.00
                where sellbilldetailid = 44872;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1497, '2023-12-08', 380, 300, 300
                    , 300, 300, 300, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+380, sellCostBuyPrice =sellCostBuyPrice+300
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+300, sellCostMeanBuyPrice = sellCostMeanBuyPrice+300
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+300, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+300
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+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, '2023-12-08', 380, 300, 300
                    , 300, 300, 300, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+380, sellCostBuyPrice =sellCostBuyPrice+300
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+300, sellCostMeanBuyPrice = sellCostMeanBuyPrice+300
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+300, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+300
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '12', userid = '7', storedetaildate = '2023-12-08 20:03:33' WHERE storedetailid = '5484';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1497', '5', '1', '1', '15121', 'اضافة فاتورة مبيعات', 'sellbillController.php', '13.00', '12', '7', '2023-12-08 20:03:33','0','0');
UPDATE save SET  savecurrentvalue = '2520',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2140.00','380', '0', '5', 'اضافة فاتورة مبيعات', '15121', '2520', '2023-12-08 20:03:33', '7',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2023-12-08', 380, 300, 300
                    , 300, 300, 300, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+380, sellCostBuyPrice =sellCostBuyPrice+300
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+300, sellCostMeanBuyPrice = sellCostMeanBuyPrice+300
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+300, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+300
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2023-12-08', 380, 300, 300
                    , 300, 300, 300, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+380, sellCostBuyPrice =sellCostBuyPrice+300
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+300, sellCostMeanBuyPrice = sellCostMeanBuyPrice+300
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+300, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+300
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, 380, 300, 300
                    , 300, 300, 300, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+380, netSellCostBuyPrice = netSellCostBuyPrice+300
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+300
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+300
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+300
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+300
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 0657359d23631b and sellbillId = 15121 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 16:33:33";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 20:03:33", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 20:03:33', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 16:34:10";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 20:04:10", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 20:04:10', '7', 'addAndRetuen', '197.192.236.7', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 065735a7616734
-- ----------------------------------------------------------------------------------------------------

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 ('2023-12-08 20:03:34', '065735a7616734', '1', '0.00', '0', '0', '1', '450', '450', '450', '0', '5', '2023-12-08 20:04:10', '', '7', '0', 'نقدي', '5', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','450','0','','0','0','450','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','اضافة فاتورة مبيعات','15122', '0', '2023-12-08 20:04:10', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '450', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 16531;
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 ('350','01498', '15122', '1', '1498', '1', '450', '450', '0', '', '1', '2023-12-08 20:04:10', '1498', '0.00', '0', '5','0','','','0','0','0','0','0','0','1','0','','16531-1,');
UPDATE sellbilldetail SET  lastbuyprice = 350.00 , meanbuyprice = 350.00, lastbuyprice_withDiscount = 350.00, meanbuyprice_withDiscount = 350.00
                where sellbilldetailid = 44873;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1498, '2023-12-08', 450, 350, 350
                    , 350, 350, 350, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+450, sellCostBuyPrice =sellCostBuyPrice+350
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+350, sellCostMeanBuyPrice = sellCostMeanBuyPrice+350
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+350, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+350
                            , 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, '2023-12-08', 450, 350, 350
                    , 350, 350, 350, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+450, sellCostBuyPrice =sellCostBuyPrice+350
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+350, sellCostMeanBuyPrice = sellCostMeanBuyPrice+350
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+350, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+350
                            , 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 = '2023-12-08 20:04:10' WHERE storedetailid = '5483';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1498', '5', '1', '1', '15122', 'اضافة فاتورة مبيعات', 'sellbillController.php', '28.00', '27', '7', '2023-12-08 20:04:10','0','0');
UPDATE save SET  savecurrentvalue = '2970',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2520.00','450', '0', '5', 'اضافة فاتورة مبيعات', '15122', '2970', '2023-12-08 20:04:10', '7',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2023-12-08', 450, 350, 350
                    , 350, 350, 350, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+450, sellCostBuyPrice =sellCostBuyPrice+350
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+350, sellCostMeanBuyPrice = sellCostMeanBuyPrice+350
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+350, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+350
                            , 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, '2023-12-08', 450, 350, 350
                    , 350, 350, 350, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+450, sellCostBuyPrice =sellCostBuyPrice+350
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+350, sellCostMeanBuyPrice = sellCostMeanBuyPrice+350
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+350, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+350
                            , 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, 450, 350, 350
                    , 350, 350, 350, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+450, netSellCostBuyPrice = netSellCostBuyPrice+350
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+350
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+350
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+350
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+350
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 065735a7616734 and sellbillId = 15122 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 16:34:12";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 20:04:12", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 20:04:12', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 17:55:18";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:25:18", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2023-12-08 21:25:18', '7', '', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:18";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:24", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:27', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:31";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:32", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:32', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:33";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:33", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:33', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:35";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:35", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:35', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:36";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:36", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:37', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:38";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:38", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:38', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:39";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:39", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:39', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:40";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:40", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:40', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:41";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:41", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:41', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:42";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:42", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:43', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:43";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:43", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:43', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:44";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:44", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:44', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:44";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:44", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:44', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:45";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:45", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:45', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:45";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:45", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:45', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:46";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:46", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:46', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:47";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:47", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:47', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:04:48";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:34:48", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:34:48', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:05:15";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:35:15", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:35:16', '7', 'addAndRetuen', '197.192.236.7', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 065736fd0547c7
-- ----------------------------------------------------------------------------------------------------

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 ('2023-12-08 21:34:40', '065736fd0547c7', '1', '0.00', '0', '0', '1', '210', '210', '210', '0', '5', '2023-12-08 21:35:16', '', '7', '0', 'نقدي', '5', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','210','0','','0','0','210','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','اضافة فاتورة مبيعات','15123', '0', '2023-12-08 21:35:16', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '210', '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 ('170','00861', '15123', '1', '861', '1', '210', '210', '0', '', '1', '2023-12-08 21:35:16', '861', '0.00', '0', '5','0','','','0','0','0','0','0','0','1','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 210.00 , meanbuyprice = 190.00, lastbuyprice_withDiscount = 210.00, meanbuyprice_withDiscount = 190.00
                where sellbilldetailid = 44874;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (861, '2023-12-08', 210, 170, 210
                    , 190, 210, 190, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+210, sellCostBuyPrice =sellCostBuyPrice+170
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+210, sellCostMeanBuyPrice = sellCostMeanBuyPrice+190
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+210, 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 (5, '2023-12-08', 210, 170, 210
                    , 190, 210, 190, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+210, sellCostBuyPrice =sellCostBuyPrice+170
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+210, sellCostMeanBuyPrice = sellCostMeanBuyPrice+190
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+210, 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 = '-4', userid = '7', storedetaildate = '2023-12-08 21:35:16' WHERE storedetailid = '3042';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('861', '5', '1', '1', '15123', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-3.00', '-4', '7', '2023-12-08 21:35:16','0','0');
UPDATE save SET  savecurrentvalue = '3180',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2970.00','210', '0', '5', 'اضافة فاتورة مبيعات', '15123', '3180', '2023-12-08 21:35:16', '7',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2023-12-08', 210, 170, 210
                    , 190, 210, 190, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+210, sellCostBuyPrice =sellCostBuyPrice+170
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+210, sellCostMeanBuyPrice = sellCostMeanBuyPrice+190
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+210, 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;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2023-12-08', 210, 170, 210
                    , 190, 210, 190, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+210, sellCostBuyPrice =sellCostBuyPrice+170
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+210, sellCostMeanBuyPrice = sellCostMeanBuyPrice+190
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+210, 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;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, 210, 170, 210
                    , 190, 210, 190, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+210, netSellCostBuyPrice = netSellCostBuyPrice+170
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+210
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+190
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+210
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+190
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 065736fd0547c7 and sellbillId = 15123 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:05:18";
UPDATE user SET loginip = "197.192.236.7", lastactivetime = "2023-12-08 21:35:18", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:35:18', '7', 'addsellBill', '197.192.236.7', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:18:02";
UPDATE user SET loginip = "197.192.206.254", lastactivetime = "2023-12-08 21:48:02", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:48:02', '7', 'addsellBill', '197.192.206.254', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:18:59";
UPDATE user SET loginip = "197.192.206.254", lastactivetime = "2023-12-08 21:48:59", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:48:59', '7', 'addAndRetuen', '197.192.206.254', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 0657372f2cfd33
-- ----------------------------------------------------------------------------------------------------

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 ('2023-12-08 21:48:02', '0657372f2cfd33', '1', '0.00', '0', '0', '1', '520', '520', '520', '0', '5', '2023-12-08 21:48:59', '', '7', '0', 'نقدي', '5', '0', '3', '0', 'نقدي', '2' ,'0','','','','','-1','0','0','0','0','0','520','0','','0','0','520','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','اضافة فاتورة مبيعات','15124', '0', '2023-12-08 21:48:59', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '520', '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 ('400','00941', '15124', '1', '941', '1', '210.00', '210', '0', '', '2', '2023-12-08 21:48:59', '941', '0.00', '0', '5','0','','','0','0','0','0','0','0','2','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 200.00 , meanbuyprice = 300.00, lastbuyprice_withDiscount = 200.00, meanbuyprice_withDiscount = 300.00
                where sellbilldetailid = 44875;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (941, '2023-12-08', 210, 400, 200
                    , 300, 200, 300, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+210, sellCostBuyPrice =sellCostBuyPrice+400
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+200, sellCostMeanBuyPrice = sellCostMeanBuyPrice+300
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+200, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+300
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+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, '2023-12-08', 210, 400, 200
                    , 300, 200, 300, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+210, sellCostBuyPrice =sellCostBuyPrice+400
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+200, sellCostMeanBuyPrice = sellCostMeanBuyPrice+300
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+200, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+300
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '100', userid = '7', storedetaildate = '2023-12-08 21:48:59' WHERE storedetailid = '3118';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('941', '5', '1', '1', '15124', 'اضافة فاتورة مبيعات', 'sellbillController.php', '101.00', '100', '7', '2023-12-08 21:48:59','0','0');
INSERT INTO sellbilldetail (buyprice, parcode, sellbillid, sellbilldetailcatid, sellbilldetailproductid, sellbilldetailquantity, sellbilldetailprice, sellbilldetailtotalprice, discountvalue, note, pricetype, sellbilldetaildate, productunitid, buydiscount, buydiscounttype,storeid,discounttype,lastbuyprice,meanbuyprice,lastbuyprice_withDiscount,meanbuyprice_withDiscount,otherdetailquantity,sizeid,colorid,onlineOrderId,pricetypepro,playstationPlayId,soldSerialsInDetails,buyPricesHistoryBookIdQuantity) VALUES ('280','01440', '15124', '1', '1440', '1', '310.00', '310', '0', '', '2', '2023-12-08 21:48:59', '1440', '0.00', '0', '5','0','','','0','0','0','0','0','0','2','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 280.00 , meanbuyprice = 280.00, lastbuyprice_withDiscount = 280.00, meanbuyprice_withDiscount = 280.00
                where sellbilldetailid = 44876;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1440, '2023-12-08', 310, 280, 280
                    , 280, 280, 280, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+310, sellCostBuyPrice =sellCostBuyPrice+280
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+280, sellCostMeanBuyPrice = sellCostMeanBuyPrice+280
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+280, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+280
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (5, '2023-12-08', 310, 280, 280
                    , 280, 280, 280, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+310, sellCostBuyPrice =sellCostBuyPrice+280
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+280, sellCostMeanBuyPrice = sellCostMeanBuyPrice+280
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+280, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+280
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '5', userid = '7', storedetaildate = '2023-12-08 21:48:59' WHERE storedetailid = '5300';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1440', '5', '1', '1', '15124', 'اضافة فاتورة مبيعات', 'sellbillController.php', '6.00', '5', '7', '2023-12-08 21:48:59','0','0');
UPDATE save SET  savecurrentvalue = '3700',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('3180.00','520', '0', '5', 'اضافة فاتورة مبيعات', '15124', '3700', '2023-12-08 21:48:59', '7',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2023-12-08', 520, 680, 480
                    , 580, 480, 580, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+520, sellCostBuyPrice =sellCostBuyPrice+680
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+480, sellCostMeanBuyPrice = sellCostMeanBuyPrice+580
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+480, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+580
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES (1, '2023-12-08', 520, 680, 480
                    , 580, 480, 580, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+520, sellCostBuyPrice =sellCostBuyPrice+680
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+480, sellCostMeanBuyPrice = sellCostMeanBuyPrice+580
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+480, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+580
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, 520, 680, 480
                    , 580, 480, 580, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+520, netSellCostBuyPrice = netSellCostBuyPrice+680
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+480
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+580
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+480
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+580
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 0657372f2cfd33 and sellbillId = 15124 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:19:00";
UPDATE user SET loginip = "197.192.206.254", lastactivetime = "2023-12-08 21:49:00", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-12-08 21:49:00', '7', 'addsellBill', '197.192.206.254', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:28:00";
UPDATE user SET loginip = "197.192.206.254", lastactivetime = "2023-12-08 21:58:00", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2023-12-08 21:58:00', '7', '', '197.192.206.254', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:28:04";
UPDATE user SET loginip = "197.192.206.254", lastactivetime = "2023-12-08 21:58:04", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2023-12-08 21:58:04', '7', '', '197.192.206.254', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:28:13";
UPDATE user SET loginip = "197.192.206.254", lastactivetime = "2023-12-08 21:58:13", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2023-12-08 21:58:13', '7', 'add', '197.192.206.254', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('-1', 'اودي', '', '3500', '2023-12-08', '7', '0','-1','5','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '200',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('3700.00','3500', '1', '5', 'إضافة مصروف', '4240', '200', '2023-12-08 21:58:14', '7',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '3500', '3500', '2023-12-08', '7', '0', '0', '2023-12-08 21:58:14','اضافة اسم مصروف( اودي )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8980', '160', '3500', '','0');
UPDATE accountstree SET name = '', customName = '', parent = '10', itemtype = '1', itemfrom = '0', notes = '', del = '1', userid = '1', mydate = '2021-12-01', itemtype2 = '1', theValue = '-2890498', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '160';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8980', '139', '3500', '','0');
UPDATE accountstree SET name = 'خزينة محل عبدالله', customName = 'خزينة محل عبدالله', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2022-07-06', itemtype2 = '1', theValue = '-2445588', theOrder = '0', layingOrder = '',reportid = '0' WHERE id = '139';
UPDATE expenses SET expensestypeid = '-1', expensesname = 'اودي', expensesdetails = '', expensesValue = '3500.00', expensesdate = '2023-12-08', userid = '7', conditions = '0',saveid = '5' , dailyentryid = '8980', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '4240';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:28:14";
UPDATE user SET loginip = "197.192.206.254", lastactivetime = "2023-12-08 21:58:14", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2023-12-08 21:58:14', '7', 'sucess', '197.192.206.254', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:28:16";
UPDATE user SET loginip = "197.192.206.254", lastactivetime = "2023-12-08 21:58:16", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2023-12-08 21:58:16', '7', 'show', '197.192.206.254', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:28:19";
UPDATE user SET loginip = "197.192.206.254", lastactivetime = "2023-12-08 21:58:20", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2023-12-08 21:58:20', '7', '', '197.192.206.254', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:28:30";
UPDATE user SET loginip = "197.192.206.254", lastactivetime = "2023-12-08 21:58:30", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2023-12-08 21:58:30', '7', 'add', '197.192.206.254', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('2', 'عماد', '', '150', '2023-12-08', '7', '0','-1','5','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '50',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('200.00','150', '1', '5', 'إضافة مصروف', '4241', '50', '2023-12-08 21:58:30', '7',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '150', '150', '2023-12-08', '7', '0', '0', '2023-12-08 21:58:30','اضافة اسم مصروف( عماد )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8981', '145', '150', '','0');
UPDATE accountstree SET name = 'مرتبات', customName = 'مرتبات', parent = '14', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-08', itemtype2 = '0', theValue = '468250', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '145';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8981', '139', '150', '','0');
UPDATE accountstree SET name = 'خزينة محل عبدالله', customName = 'خزينة محل عبدالله', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2022-07-06', itemtype2 = '1', theValue = '-2445738', theOrder = '0', layingOrder = '',reportid = '0' WHERE id = '139';
UPDATE expenses SET expensestypeid = '2', expensesname = 'عماد', expensesdetails = '', expensesValue = '150.00', expensesdate = '2023-12-08', userid = '7', conditions = '0',saveid = '5' , dailyentryid = '8981', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '4241';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:28:30";
UPDATE user SET loginip = "197.192.206.254", lastactivetime = "2023-12-08 21:58:30", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2023-12-08 21:58:30', '7', 'sucess', '197.192.206.254', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 18:28:32";
UPDATE user SET loginip = "197.192.206.254", lastactivetime = "2023-12-08 21:58:32", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2023-12-08 21:58:32', '7', 'show', '197.192.206.254', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 19:16:20";
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 = '0', 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 = '2023-12-08',workerbetweenstores = '1',workshoptimeout = '24',drivertimeout = '3',currancy = 'جنيه',serial='9c2d4cf4cf5d4e24d5070164705832c3a5d1287f641a2960e48e04ae57a2ad0a5441322ca7cf34efd63003fdb348adbd0b61197c7c87d8dd5bc298c352482bc6',allowdateedit = '0', clientcode = '1' ,clientserial = '1',timezone = 'Africa/Cairo' , expiredate ='1' , production ='1' , description='1' , service ='1' , date='1' , limitamount = '0' , measuringunit = '1' , print_amount = '0' , billid = '0' , precentages = '1' , realprice = '1' ,delegate_seller = '0' , storeserial = '1' ,clientfieldrequired ='0' , clientcodname='0' , colortype = '0' , nakdyOnly = '0' , nakdyKashf = '0' , discount_pres_direct = '0' , general_discount = '0' , sells_return = '0' ,scunitname ='0',vatValue = '0.00',syncstructure = '1',showPrevPrices = '0',isOpticProg='1',reportsPlusHours = '2' , showM5zon = '1',restaurantStoreId = '1',restuarantPrintTimeout = '8',sumSameProductForStore = '0', editAllPrice = '1', isCafe = '0' ,isRestaurent = '0' ,productDays = '0',thereIsRestTax = '0',restTaxVal = '0',restPrintLang = '0',taxNameFlag = '0',parcodeDigits = '5' ,specializedParcodeDigits = '7', clientDefaultDebtLimit = '10000' , clientDefaultDebtLimitControl = '0',usedParcode = '0' ,productbycodeimage = '' ,commentClient='تعليق على العميل ',Inventoryevaluation='first',Profitevaluation='first' , delivery='-2',premiums = '0',operationnumEdit = '0',noOfDecimalPlaces = '2',unReviewBills = '0', unReviewBillsPass = '123',billReviewNote = '',tamweenBakery = '0',three_months = '0',six_months = '0',twelve_months = '0',eighteen_months = '0',twentyfour_months = '0',thirty_months = '0',sixthirty_months = '0',fortytwo_months = '0',fortyeight_months = '0',mandobCollectionRatio='0',takeAwayClient = '0',restaurantServiceOn = ',-2,-1,1,',earlyrepayment = '0',visaPay = '0',headerPrint='',headerPrintSand='',printSand='0',makeDailyEntry='0',clientShowTawla='0',billRest='1',suppIsClientToo='0',isCarBill='0',expensesproduct='1',projectshownew='1',showparcode='0',changeBuyPriceChangeSellInBuyBillCtrl = '0',changeBuyPriceChangeSellInProductCtrl = '0',inventoryvaluation = '1',showBillCollectionSearch='0' WHERE programsettingsid = '1';
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 19:16: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

;
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 < "2023-12-08 19:16:28";
UPDATE user SET loginip = "154.191.25.227", lastactivetime = "2023-12-08 22:46:28", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2023-12-08 22:46:28', '1', '', '154.191.25.227', '', '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 < "2023-12-08 19:16:29";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 19:18:35";
UPDATE user SET loginip = "154.191.25.227", lastactivetime = "2023-12-08 22:48:35", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2023-12-08 22:48:35', '1', '', '154.191.25.227', '', '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 < "2023-12-08 19:18:35";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 19:18:43";
UPDATE user SET loginip = "154.191.25.227", lastactivetime = "2023-12-08 22:48:43", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-12-08 22:48:43', '1', '', '154.191.25.227', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 19:18:53";
UPDATE user SET loginip = "154.191.25.227", lastactivetime = "2023-12-08 22:48:53", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-12-08 22:48:53', '1', 'show', '154.191.25.227', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 19:19:15";
UPDATE user SET loginip = "154.191.25.227", lastactivetime = "2023-12-08 22:49:15", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-12-08 22:49:15', '1', '', '154.191.25.227', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 19:24:37";
UPDATE user SET loginip = "154.191.25.227", lastactivetime = "2023-12-08 22:54:37", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-12-08 22:54:37', '1', 'add', '154.191.25.227', '', 'MOBILE');
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 ('ست الحبايب 458','','1','350','370', '420','390', '2023-12-08', '0', '1', '0', '', '0', '0', '0', '0', '0', '350','350','350','350','350','0','5.71','11.43','20','.','0','0','0','0','0','','','0','0','0');
UPDATE product SET productName = 'ست الحبايب 458', productDescription = '', productCatId = '1', productBuyPrice = '350', productSellAllPrice = '370', productSellUnitPrice = '420', productSellHalfPrice = '390', productDate = '2023-12-08', conditions = '0', userId = '1', limitamount = '0', parcode = '01500',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '350',lastbuyprice_withDiscount = '350',meanbuyprice = '350',meanbuyprice_withDiscount = '350' , productbuypricereal = '350' , buypricereal_precentage = '0' , buytotal_precentage = '5.71' , buyhalf_precentage = '11.43' , buypart_precentage = '20',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1500';
INSERT INTO productunit (unitid, productid, productnumber, productunitdate, userid, conditions,proUnitParcode,proUnitSellAllPrice,proUnitSellHalfPrice,proUnitSellUnitPrice,proUnitBuyPrice) VALUES ('1', '1500', '1', '2023-12-08', '1', '0','0150001','370','390','420','350');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1500', '1', '15', '1', '2023-12-08');
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1500', '1', '15', '0', '1500', 'إضافة منتج', 'productController.php', '0', '15', '1', '2023-12-08','0','0');
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1500, 1,'2023-12-08 22:54:38',1)
                ON DUPLICATE KEY UPDATE productid = 1500, edited = 1, sysdate = '2023-12-08 22:54:38', userid = 1;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '5250', '5250', '2023-12-08', '1', '0', '0', '2023-12-08 22:54:38','إضافة منتج ست الحبايب 458 الكمية 15','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8982', '19', '5250', '','0');
UPDATE accountstree SET name = 'البضاعة (بضاعة أول المدة)', customName = 'البضاعة (بضاعة أول المدة)', parent = '6', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '14934165.95', theOrder = '0', layingOrder = '121',reportid = '0' WHERE id = '19';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8982', '7', '5250', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '15692446.75', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
UPDATE product SET productName = 'ست الحبايب 458', productDescription = '', productCatId = '1', productBuyPrice = '350.00', productSellAllPrice = '370.00', productSellUnitPrice = '420.00', productSellHalfPrice = '390.00', productDate = '2023-12-08', conditions = '0', userId = '1', limitamount = '0', parcode = '01500',type ='0', expireDate = '0' , dailyentryId = '8982',isService = '0',isOptic = '0',lastbuyprice = '350',lastbuyprice_withDiscount = '350',meanbuyprice = '350',meanbuyprice_withDiscount = '350' , productbuypricereal = '350' , buypricereal_precentage = '0' , buytotal_precentage = '5.71' , buyhalf_precentage = '11.43' , buypart_precentage = '20',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1500';
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 ('ست الحبايب 463','','1','335','355', '395','375', '2023-12-08', '0', '1', '0', '', '0', '0', '0', '0', '0', '335','335','335','335','335','0','5.97','11.94','17.91','.','0','0','0','0','0','','','0','0','0');
UPDATE product SET productName = 'ست الحبايب 463', productDescription = '', productCatId = '1', productBuyPrice = '335', productSellAllPrice = '355', productSellUnitPrice = '395', productSellHalfPrice = '375', productDate = '2023-12-08', conditions = '0', userId = '1', limitamount = '0', parcode = '01501',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '335',lastbuyprice_withDiscount = '335',meanbuyprice = '335',meanbuyprice_withDiscount = '335' , productbuypricereal = '335' , buypricereal_precentage = '0' , buytotal_precentage = '5.97' , buyhalf_precentage = '11.94' , buypart_precentage = '17.91',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1501';
INSERT INTO productunit (unitid, productid, productnumber, productunitdate, userid, conditions,proUnitParcode,proUnitSellAllPrice,proUnitSellHalfPrice,proUnitSellUnitPrice,proUnitBuyPrice) VALUES ('1', '1501', '1', '2023-12-08', '1', '0','0150101','355','375','395','335');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1501', '1', '16', '1', '2023-12-08');
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1501', '1', '16', '0', '1501', 'إضافة منتج', 'productController.php', '0', '16', '1', '2023-12-08','0','0');
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1501, 1,'2023-12-08 22:54:38',1)
                ON DUPLICATE KEY UPDATE productid = 1501, edited = 1, sysdate = '2023-12-08 22:54:38', userid = 1;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '5360', '5360', '2023-12-08', '1', '0', '0', '2023-12-08 22:54:38','إضافة منتج ست الحبايب 463 الكمية 16','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8983', '19', '5360', '','0');
UPDATE accountstree SET name = 'البضاعة (بضاعة أول المدة)', customName = 'البضاعة (بضاعة أول المدة)', parent = '6', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '14939525.95', theOrder = '0', layingOrder = '121',reportid = '0' WHERE id = '19';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8983', '7', '5360', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '15697806.75', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
UPDATE product SET productName = 'ست الحبايب 463', productDescription = '', productCatId = '1', productBuyPrice = '335.00', productSellAllPrice = '355.00', productSellUnitPrice = '395.00', productSellHalfPrice = '375.00', productDate = '2023-12-08', conditions = '0', userId = '1', limitamount = '0', parcode = '01501',type ='0', expireDate = '0' , dailyentryId = '8983',isService = '0',isOptic = '0',lastbuyprice = '335',lastbuyprice_withDiscount = '335',meanbuyprice = '335',meanbuyprice_withDiscount = '335' , productbuypricereal = '335' , buypricereal_precentage = '0' , buytotal_precentage = '5.97' , buyhalf_precentage = '11.94' , buypart_precentage = '17.91',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1501';
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 ('اسيا 1053','','1','380','390', '440','420', '2023-12-08', '0', '1', '0', '', '0', '0', '0', '0', '0', '380','380','380','380','380','0','2.63','10.53','15.79','.','0','0','0','0','0','','','0','0','0');
UPDATE product SET productName = 'اسيا 1053', productDescription = '', productCatId = '1', productBuyPrice = '380', productSellAllPrice = '390', productSellUnitPrice = '440', productSellHalfPrice = '420', productDate = '2023-12-08', conditions = '0', userId = '1', limitamount = '0', parcode = '01502',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '380',lastbuyprice_withDiscount = '380',meanbuyprice = '380',meanbuyprice_withDiscount = '380' , productbuypricereal = '380' , buypricereal_precentage = '0' , buytotal_precentage = '2.63' , buyhalf_precentage = '10.53' , buypart_precentage = '15.79',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1502';
INSERT INTO productunit (unitid, productid, productnumber, productunitdate, userid, conditions,proUnitParcode,proUnitSellAllPrice,proUnitSellHalfPrice,proUnitSellUnitPrice,proUnitBuyPrice) VALUES ('1', '1502', '1', '2023-12-08', '1', '0','0150201','390','420','440','380');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1502', '1', '17', '1', '2023-12-08');
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1502', '1', '17', '0', '1502', 'إضافة منتج', 'productController.php', '0', '17', '1', '2023-12-08','0','0');
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1502, 1,'2023-12-08 22:54:38',1)
                ON DUPLICATE KEY UPDATE productid = 1502, edited = 1, sysdate = '2023-12-08 22:54:38', userid = 1;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '6460', '6460', '2023-12-08', '1', '0', '0', '2023-12-08 22:54:38','إضافة منتج اسيا 1053 الكمية 17','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8984', '19', '6460', '','0');
UPDATE accountstree SET name = 'البضاعة (بضاعة أول المدة)', customName = 'البضاعة (بضاعة أول المدة)', parent = '6', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '14945985.95', theOrder = '0', layingOrder = '121',reportid = '0' WHERE id = '19';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8984', '7', '6460', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '15704266.75', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
UPDATE product SET productName = 'اسيا 1053', productDescription = '', productCatId = '1', productBuyPrice = '380.00', productSellAllPrice = '390.00', productSellUnitPrice = '440.00', productSellHalfPrice = '420.00', productDate = '2023-12-08', conditions = '0', userId = '1', limitamount = '0', parcode = '01502',type ='0', expireDate = '0' , dailyentryId = '8984',isService = '0',isOptic = '0',lastbuyprice = '380',lastbuyprice_withDiscount = '380',meanbuyprice = '380',meanbuyprice_withDiscount = '380' , productbuypricereal = '380' , buypricereal_precentage = '0' , buytotal_precentage = '2.63' , buyhalf_precentage = '10.53' , buypart_precentage = '15.79',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1502';
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 ('اسيا 1050','','1','340','360', '410','380', '2023-12-08', '0', '1', '0', '', '0', '0', '0', '0', '0', '340','340','340','340','340','0','5.88','11.76','20.59','.','0','0','0','0','0','','','0','0','0');
UPDATE product SET productName = 'اسيا 1050', productDescription = '', productCatId = '1', productBuyPrice = '340', productSellAllPrice = '360', productSellUnitPrice = '410', productSellHalfPrice = '380', productDate = '2023-12-08', conditions = '0', userId = '1', limitamount = '0', parcode = '01503',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '340',lastbuyprice_withDiscount = '340',meanbuyprice = '340',meanbuyprice_withDiscount = '340' , productbuypricereal = '340' , buypricereal_precentage = '0' , buytotal_precentage = '5.88' , buyhalf_precentage = '11.76' , buypart_precentage = '20.59',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1503';
INSERT INTO productunit (unitid, productid, productnumber, productunitdate, userid, conditions,proUnitParcode,proUnitSellAllPrice,proUnitSellHalfPrice,proUnitSellUnitPrice,proUnitBuyPrice) VALUES ('1', '1503', '1', '2023-12-08', '1', '0','0150301','360','380','410','340');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1503', '1', '20', '1', '2023-12-08');
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1503', '1', '20', '0', '1503', 'إضافة منتج', 'productController.php', '0', '20', '1', '2023-12-08','0','0');
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1503, 1,'2023-12-08 22:54:38',1)
                ON DUPLICATE KEY UPDATE productid = 1503, edited = 1, sysdate = '2023-12-08 22:54:38', userid = 1;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '6800', '6800', '2023-12-08', '1', '0', '0', '2023-12-08 22:54:38','إضافة منتج اسيا 1050 الكمية 20','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8985', '19', '6800', '','0');
UPDATE accountstree SET name = 'البضاعة (بضاعة أول المدة)', customName = 'البضاعة (بضاعة أول المدة)', parent = '6', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '14952785.95', theOrder = '0', layingOrder = '121',reportid = '0' WHERE id = '19';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8985', '7', '6800', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '15711066.75', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
UPDATE product SET productName = 'اسيا 1050', productDescription = '', productCatId = '1', productBuyPrice = '340.00', productSellAllPrice = '360.00', productSellUnitPrice = '410.00', productSellHalfPrice = '380.00', productDate = '2023-12-08', conditions = '0', userId = '1', limitamount = '0', parcode = '01503',type ='0', expireDate = '0' , dailyentryId = '8985',isService = '0',isOptic = '0',lastbuyprice = '340',lastbuyprice_withDiscount = '340',meanbuyprice = '340',meanbuyprice_withDiscount = '340' , productbuypricereal = '340' , buypricereal_precentage = '0' , buytotal_precentage = '5.88' , buyhalf_precentage = '11.76' , buypart_precentage = '20.59',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1503';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 19:24:40";
UPDATE user SET loginip = "154.191.25.227", lastactivetime = "2023-12-08 22:54:40", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-12-08 22:54:40', '1', '', '154.191.25.227', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 19:24:41";
UPDATE user SET loginip = "154.191.25.227", lastactivetime = "2023-12-08 22:54:41", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-12-08 22:54:41', '1', '', '154.191.25.227', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 19:25:59";
UPDATE user SET loginip = "154.191.25.227", lastactivetime = "2023-12-08 22:55:59", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-12-08 22:55:59', '1', 'add', '154.191.25.227', '', 'MOBILE');
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(1737,1,7,1502,17,'2023-12-08',1,0, '' ,0,0,0,0,0,'2023-12-08 22:55:59',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2023-12-08' WHERE storedetailid = '5495';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-12-08', 1, 1502, 0, 0
                    , 380.00, -17, 0, 0, 1, '2023-12-08 22:55:59')
                ON DUPLICATE KEY UPDATE buyprice = 380.00,
                        buyQuantity =buyQuantity+-17, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-12-08 22:55:59' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "17*2023-12-08*380.00," WHERE transferproductid = 7618;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1502', '1', '17', '1', '7618', 'تحويل منتجات من المخزن', 'storemovementController.php', '17.00', '0', '1', '2023-12-08','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1502', '7', '17', '1', '2023-12-08');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-12-08', 7, 1502, 0, 0
                    , 380.00, 17, 0, 0, 1, '2023-12-08 22:55:59')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+17, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-12-08 22:55:59' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1502', '7', '17', '0', '7618', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '17', '1', '2023-12-08','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', '1503', '20', '2023-12-08', '1', '0','1737',null,null,'2023-12-08 22:55:59',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2023-12-08' WHERE storedetailid = '5496';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-12-08', 1, 1503, 0, 0
                    , 340.00, -20, 0, 0, 1, '2023-12-08 22:55:59')
                ON DUPLICATE KEY UPDATE buyprice = 340.00,
                        buyQuantity =buyQuantity+-20, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-12-08 22:55:59' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "20*2023-12-08*340.00," WHERE transferproductid = 7619;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1503', '1', '20', '1', '7619', 'تحويل منتجات من المخزن', 'storemovementController.php', '20.00', '0', '1', '2023-12-08','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1503', '7', '20', '1', '2023-12-08');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-12-08', 7, 1503, 0, 0
                    , 340.00, 20, 0, 0, 1, '2023-12-08 22:55:59')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+20, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-12-08 22:55:59' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1503', '7', '20', '0', '7619', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '20', '1', '2023-12-08','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', '1500', '15', '2023-12-08', '1', '0','1737',null,null,'2023-12-08 22:55:59',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2023-12-08' WHERE storedetailid = '5493';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-12-08', 1, 1500, 0, 0
                    , 350.00, -15, 0, 0, 1, '2023-12-08 22:55:59')
                ON DUPLICATE KEY UPDATE buyprice = 350.00,
                        buyQuantity =buyQuantity+-15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-12-08 22:55:59' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "15*2023-12-08*350.00," WHERE transferproductid = 7620;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1500', '1', '15', '1', '7620', 'تحويل منتجات من المخزن', 'storemovementController.php', '15.00', '0', '1', '2023-12-08','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1500', '7', '15', '1', '2023-12-08');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-12-08', 7, 1500, 0, 0
                    , 350.00, 15, 0, 0, 1, '2023-12-08 22:55:59')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+15, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-12-08 22:55:59' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1500', '7', '15', '0', '7620', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '15', '1', '2023-12-08','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', '1501', '16', '2023-12-08', '1', '0','1737',null,null,'2023-12-08 22:55:59',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2023-12-08' WHERE storedetailid = '5494';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-12-08', 1, 1501, 0, 0
                    , 335.00, -16, 0, 0, 1, '2023-12-08 22:55:59')
                ON DUPLICATE KEY UPDATE buyprice = 335.00,
                        buyQuantity =buyQuantity+-16, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-12-08 22:55:59' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "16*2023-12-08*335.00," WHERE transferproductid = 7621;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1501', '1', '16', '1', '7621', 'تحويل منتجات من المخزن', 'storemovementController.php', '16.00', '0', '1', '2023-12-08','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1501', '7', '16', '1', '2023-12-08');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-12-08', 7, 1501, 0, 0
                    , 335.00, 16, 0, 0, 1, '2023-12-08 22:55:59')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+16, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-12-08 22:55:59' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1501', '7', '16', '0', '7621', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '16', '1', '2023-12-08','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 19:26:00";
UPDATE user SET loginip = "154.191.25.227", lastactivetime = "2023-12-08 22:56:00", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-12-08 22:56:00', '1', 'sucess', '154.191.25.227', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 19:26:02";
UPDATE user SET loginip = "154.191.25.227", lastactivetime = "2023-12-08 22:56:02", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-12-08 22:56:02', '1', 'show', '154.191.25.227', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-12-08 19:28:10";
UPDATE user SET loginip = "154.191.25.227", lastactivetime = "2023-12-08 22:58:10", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-12-08 22:58:10', '1', '', '154.191.25.227', '', 'MOBILE');
