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-07-26 21:35:21";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:05:21", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2023-07-27 01:05:21', '1', '', '196.135.143.43', '', 'MOBILE');
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-07-27',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-07-27',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-07-26 21:35:24";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-26 21:35:57";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:05:57", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2023-07-27 01:05:57', '1', '', '196.135.143.43', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-26 21:36:17";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:06:17", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2023-07-27 01:06:17', '1', '', '196.135.143.43', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-26 21:36:38";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:06:38", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2023-07-27 01:06:38', '1', 'add', '196.135.143.43', '', 'MOBILE');
BEGIN;
INSERT INTO transfermoney (saveidfrom, saveidto, transfermoneyvalue, transfermoneydate, userid, conditions, dailyentryid , comment) VALUES ('7','9', '5070.00', '2023-07-27', '1', '0', '0','');
UPDATE save SET  savecurrentvalue = '0',  userid = '1' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('5070.00','5070.00', '1', '7', 'تحويل امول الى الخزنة  [ الشيخ وليد ] ', '593', '0', '2023-07-27 01:06:38', '1',  'transfermoneyController.php','0','');
UPDATE save SET  savecurrentvalue = '7251635',  userid = '1' WHERE saveid = '9';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('7246565.00','5070.00', '0', '9', 'تحويل امول من الخزنة  [ خزينة محل العميد ] ', '593', '7251635', '2023-07-27 01:06:38', '1',  'transfermoneyController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '5070', '5070', '2023-07-27', '1', '0', '0', '2023-07-27 01:06:38','اضافة تحويل من خزينة محل العميد الى الشيخ وليد','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8066', '156', '5070.00', '','0');
UPDATE accountstree SET name = 'الشيخ وليد', customName = 'الشيخ وليد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-09', itemtype2 = '1', theValue = '7251635', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '156';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8066', '141', '5070.00', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-1527417', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE transfermoney SET saveidfrom = '7', saveidto = '9', transfermoneyvalue = '5070.00', transfermoneydate = '2023-07-27', userid = '1', conditions = '0' , dailyentryid = '8066' , comment = '' WHERE transfermoneyid = '593';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-26 21:36:39";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:06:39", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2023-07-27 01:06:39', '1', 'sucess', '196.135.143.43', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-26 21:36:45";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:06:46", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2023-07-27 01:06:46', '1', 'show', '196.135.143.43', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-26 21:36:46";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:06:47", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2023-07-27 01:06:47', '1', '', '196.135.143.43', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-26 21:37:04";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:07:04", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2023-07-27 01:07:05', '1', 'show', '196.135.143.43', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-26 21:37:25";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:07:25", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 01:07:25', '1', 'showDetail', '196.135.143.43', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-26 21:39:08";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:09:08", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2023-07-27 01:09:09', '1', 'showDetail', '196.135.143.43', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-26 21:40:31";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:10:31", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 01:10:31', '1', 'showDetail', '196.135.143.43', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-26 21:42:04";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:12:04", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 01:12:04', '1', 'showDetail', '196.135.143.43', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-26 21:43:21";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:13:21", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 01:13:21', '1', 'showDetail', '196.135.143.43', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-26 21:43:58";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:13:58", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 01:13:58', '1', 'showDetail', '196.135.143.43', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-26 21:47:41";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:17:42", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2023-07-27 01:17:42', '1', 'show', '196.135.143.43', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-26 21:48:11";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:18:11", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2023-07-27 01:18:11', '1', 'showDetail', '196.135.143.43', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-26 21:48:39";
UPDATE user SET loginip = "196.135.143.43", lastactivetime = "2023-07-27 01:18:39", deviceType = "MOBILE" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('returnsellbillController.php', '2023-07-27 01:18:39', '1', 'showDetail', '196.135.143.43', '', 'MOBILE');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 06:28:03";
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-07-27 06:28:13";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 09:58:13", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2023-07-27 09:58:13', '4', '', '197.61.41.31', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 06:28:14";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 06:28:16";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 09:58:16", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 09:58:16', '4', 'addsellBill', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 06:29:16";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 09:59:16", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 09:59:16', '4', 'addAndRetuen', '197.61.41.31', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 064c2158854a01
-- ----------------------------------------------------------------------------------------------------

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-07-27 09:58:16', '064c2158854a01', '1', '0.00', '0', '0', '1', '530', '530', '530', '0', '7', '2023-07-27 09:59:17', '', '4', '0', 'نقدي', '7', '0', '3', '0', 'نقدي', '2' ,'0','','','','','-1','0','0','0','0','0','530','0','','0','0','530','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '4' WHERE clientid = '1';
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('1','0.00','0','0','اضافة فاتورة مبيعات','13839', '0', '2023-07-27 09:59:17', '4', 'sellbillController.php', 'اضافة فاتورة مبيعات', '530', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+2 where id = 15873;
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 ('250','01418', '13839', '1', '1418', '2', '265', '530', '0', '', '0', '2023-07-27 09:59:17', '1418', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','15873-2,');
UPDATE sellbilldetail SET  lastbuyprice = 250.00 , meanbuyprice = 250.00, lastbuyprice_withDiscount = 250.00, meanbuyprice_withDiscount = 250.00
                where sellbilldetailid = 41040;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1418, '2023-07-27', 530, 500, 500
                    , 500, 500, 500, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 2, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+530, sellCostBuyPrice =sellCostBuyPrice+500
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+500, sellCostMeanBuyPrice = sellCostMeanBuyPrice+500
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+500, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+500
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+2
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (7, '2023-07-27', 530, 500, 500
                    , 500, 500, 500, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+530, sellCostBuyPrice =sellCostBuyPrice+500
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+500, sellCostMeanBuyPrice = sellCostMeanBuyPrice+500
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+500, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+500
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '24', userid = '4', storedetaildate = '2023-07-27 09:59:17' WHERE storedetailid = '5236';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1418', '7', '2', '1', '13839', 'اضافة فاتورة مبيعات', 'sellbillController.php', '26.00', '24', '4', '2023-07-27 09:59:17','0','0');
UPDATE save SET  savecurrentvalue = '530',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('0.00','530', '0', '7', 'اضافة فاتورة مبيعات', '13839', '530', '2023-07-27 09:59:17', '4',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2023-07-27', 530, 500, 500
                    , 500, 500, 500, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+530, sellCostBuyPrice =sellCostBuyPrice+500
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+500, sellCostMeanBuyPrice = sellCostMeanBuyPrice+500
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+500, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+500
                            , 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-07-27', 530, 500, 500
                    , 500, 500, 500, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+530, sellCostBuyPrice =sellCostBuyPrice+500
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+500, sellCostMeanBuyPrice = sellCostMeanBuyPrice+500
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+500, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+500
                            , 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, 530, 500, 500
                    , 500, 500, 500, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+530, netSellCostBuyPrice = netSellCostBuyPrice+500
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+500
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+500
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+500
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+500
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 064c2158854a01 and sellbillId = 13839 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 06:29:17";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 09:59:17", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 09:59:17', '4', 'addsellBill', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 06:29:19";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 09:59:19", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2023-07-27 09:59:19', '4', '', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 06:29:29";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 09:59:29", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 09:59:30', '4', 'addsellBill', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 07:26:24";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 10:56:24", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2023-07-27 10:56:25', '4', '', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 07:26:27";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 10:56:27", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 10:56:27', '4', 'addsellBill', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:35:18";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:05:18", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 12:05:18', '4', 'addsellBill', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:36:01";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:06:01", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 12:06:01', '4', 'addAndRetuen', '197.61.41.31', '', '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 064c2334ed5cde
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(343,@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-07-27 12:05:18', '064c2334ed5cde', '343', '21965.00', '23995', '0', '1', '2030', '2030', '0', '2030', '7', '2023-07-27 12:06:01', '', '4', '0', 'ابو امل كفر غنام ', '7', '1', '3', '0', 'ابو امل كفر غنام ', '7' ,'0','','','','','-1','0','0','0','0','0','2030','0','','0','0','0','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '23995', userid = '4' WHERE clientid = '343';
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 ('343','21965.00','2030','0','اضافة فاتورة مبيعات','13840', '23995', '2023-07-27 12:06:01', '4', 'sellbillController.php', 'اضافة فاتورة مبيعات', '2030', '0', null, '0', null, null,'', '0','1','1','2030','1');
UPDATE client SET  inUse = 0 where clientid = 343;
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+6 where id = 15833;
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','01432', '13840', '1', '1432', '6', '290', '1740', '0', '', '0', '2023-07-27 12:06:01', '1432', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','15833-6,');
UPDATE sellbilldetail SET  lastbuyprice = 280.00 , meanbuyprice = 280.00, lastbuyprice_withDiscount = 280.00, meanbuyprice_withDiscount = 280.00
                where sellbilldetailid = 41041;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1432, '2023-07-27', 1740, 1680, 1680
                    , 1680, 1680, 1680, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 6, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1740, sellCostBuyPrice =sellCostBuyPrice+1680
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1680, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1680
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1680, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1680
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+6
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (7, '2023-07-27', 1740, 1680, 1680
                    , 1680, 1680, 1680, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1740, sellCostBuyPrice =sellCostBuyPrice+1680
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1680, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1680
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1680, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1680
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '31', userid = '4', storedetaildate = '2023-07-27 12:06:01' WHERE storedetailid = '5278';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1432', '7', '6', '1', '13840', 'اضافة فاتورة مبيعات', 'sellbillController.php', '37.00', '31', '4', '2023-07-27 12:06:01','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 ('290','01387', '13840', '1', '1387', '1', '290.00', '290', '0', '', '0', '2023-07-27 12:06:01', '1387', '0.00', '0', '7','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 290.00 , meanbuyprice = 290.00, lastbuyprice_withDiscount = 290.00, meanbuyprice_withDiscount = 290.00
                where sellbilldetailid = 41042;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1387, '2023-07-27', 290, 290, 290
                    , 290, 290, 290, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+290, sellCostBuyPrice =sellCostBuyPrice+290
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+290, sellCostMeanBuyPrice = sellCostMeanBuyPrice+290
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+290, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+290
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (7, '2023-07-27', 290, 290, 290
                    , 290, 290, 290, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+290, sellCostBuyPrice =sellCostBuyPrice+290
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+290, sellCostMeanBuyPrice = sellCostMeanBuyPrice+290
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+290, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+290
                            , 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 = '21', userid = '4', storedetaildate = '2023-07-27 12:06:01' WHERE storedetailid = '5129';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1387', '7', '1', '1', '13840', 'اضافة فاتورة مبيعات', 'sellbillController.php', '22.00', '21', '4', '2023-07-27 12:06:01','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2023-07-27', 2030, 1970, 1970
                    , 1970, 1970, 1970, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+2030, sellCostBuyPrice =sellCostBuyPrice+1970
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1970, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1970
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1970, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1970
                            , 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 (343, '2023-07-27', 2030, 1970, 1970
                    , 1970, 1970, 1970, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+2030, sellCostBuyPrice =sellCostBuyPrice+1970
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1970, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1970
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1970, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1970
                            , 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, 2030, 1970, 1970
                    , 1970, 1970, 1970, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+2030, netSellCostBuyPrice = netSellCostBuyPrice+1970
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+1970
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+1970
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+1970
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+1970
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 064c2334ed5cde and sellbillId = 13840 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:36:01";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:06:01", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 12:06:02', '4', 'addsellBill', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:36:04";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:06:04", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2023-07-27 12:06:04', '4', '', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:36:17";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:06:17", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2023-07-27 12:06:17', '4', 'add', '197.61.41.31', '', 'DESKTOP');
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;

-- ----------------------------------------------------------------------------------------------------
-- clientPayedDeptController add - with modelid =20808
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(343,@clientdebt,@clientname);
UPDATE client SET  clientdebt = '21495' , clientdate = '2023-07-27 12:06:17', userid = '4' WHERE clientid = '343';
UPDATE client SET  inUse = 0 where clientid = 343;
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 ('343','23995.00','2500','1','ايصال تحصيل (( قبض من عميل ))','20808', '21495', '2023-07-27 12:06:04', '4', 'clientPayedDeptController.php', '   ', '2500', '0', null, '0', null, null,'', '-1','1','1','1','1');
UPDATE save SET  savecurrentvalue = '3030',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('530.00','2500', '0', '7', 'ايصال تحصيل (( قبض من عميل ))', '20808', '3030', '2023-07-27 12:06:17', '4',  'clientPayedDeptController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '2500', '2500', '2023-07-27', '4', '0', '0', '2023-07-27 12:06:17','اضافة ايصال سداد للعميل ابو امل كفر غنام ','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8067', '141', '2500', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-1524917', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8067', '420', '2500', '','0');
UPDATE accountstree SET name = 'ابو امل كفر غنام ', customName = 'ابو امل كفر غنام ', parent = '23', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '4', mydate = '2023-03-09', itemtype2 = '1', theValue = '-72000', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '420';
UPDATE clientdebtchange SET clientid = '343', clientdebtchangebefore = '23995.00', clientdebtchangeamount = '2500.00', clientdebtchangetype = '1', processname = 'ايصال تحصيل (( قبض من عميل ))', clientdebtchangemodelid = '20808', clientdebtchangeafter = '21495.00', clientdebtchangedate = '2023-07-27 12:06:04', userid = '4', tablename = 'clientPayedDeptController.php', comment = '   ', totalOperationCost = '2500.00',discount='', reciptid=null, dailyentryid = '8067',seller = '0',currencyId='1',conversionFactor='1',payedInCurrency='1',saveConversionFactor='1' WHERE clientdebtchangeid = '20808';
COMMIT;

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

UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:36:18";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:06:18", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2023-07-27 12:06:18', '4', 'sucess', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:36:19";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:06:19", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2023-07-27 12:06:19', '4', '', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:36:19";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:06:19", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2023-07-27 12:06:20', '4', '', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:36:25";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:06:25", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2023-07-27 12:06:25', '4', 'show', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:36:27";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:06:27", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2023-07-27 12:06:27', '4', 'editprint', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:36:29";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:06:29", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 12:06:29', '4', 'showDetail', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:37:00";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:07:00", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 12:07:00', '4', 'addsellBill', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:45:11";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:15:11", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 12:15:11', '4', 'addsellBill', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:50:32";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:20:32", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2023-07-27 12:20:32', '4', '', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:50:36";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:20:36", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 12:20:36', '4', 'addsellBill', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:52:09";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:22:09", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2023-07-27 12:22:09', '4', '', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:52:13";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:22:13", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 12:22:13', '4', 'addsellBill', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:53:37";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:23:37", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2023-07-27 12:23:37', '4', '', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:53:50";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:23:50", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2023-07-27 12:23:50', '4', 'add', '197.61.41.31', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('-1', 'قبض احمد نبروة بالمصروف', '', '415', '2023-07-27', '4', '0','-1','7','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '2615',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('3030.00','415', '1', '7', 'إضافة مصروف', '3622', '2615', '2023-07-27 12:23:50', '4',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '415', '415', '2023-07-27', '4', '0', '0', '2023-07-27 12:23:50','اضافة اسم مصروف( قبض احمد نبروة بالمصروف )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8068', '160', '415', '','0');
UPDATE accountstree SET name = '', customName = '', parent = '10', itemtype = '1', itemfrom = '0', notes = '', del = '1', userid = '1', mydate = '2021-12-01', itemtype2 = '1', theValue = '-2251013', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '160';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8068', '141', '415', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-1525332', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE expenses SET expensestypeid = '-1', expensesname = 'قبض احمد نبروة بالمصروف', expensesdetails = '', expensesValue = '415.00', expensesdate = '2023-07-27', userid = '4', conditions = '0',saveid = '7' , dailyentryid = '8068', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '3622';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:53:50";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:23:51", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2023-07-27 12:23:51', '4', 'sucess', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:53:52";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:23:52", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2023-07-27 12:23:52', '4', 'show', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:53:53";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:23:53", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2023-07-27 12:23:53', '4', '', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:54:01";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:24:01", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2023-07-27 12:24:01', '4', 'add', '197.61.41.31', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('-1', 'العميد', '', '1000', '2023-07-27', '4', '0','-1','7','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '1615',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('2615.00','1000', '1', '7', 'إضافة مصروف', '3623', '1615', '2023-07-27 12:24:01', '4',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '1000', '1000', '2023-07-27', '4', '0', '0', '2023-07-27 12:24:01','اضافة اسم مصروف( العميد )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8069', '160', '1000', '','0');
UPDATE accountstree SET name = '', customName = '', parent = '10', itemtype = '1', itemfrom = '0', notes = '', del = '1', userid = '1', mydate = '2021-12-01', itemtype2 = '1', theValue = '-2252013', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '160';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8069', '141', '1000', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-1526332', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE expenses SET expensestypeid = '-1', expensesname = 'العميد', expensesdetails = '', expensesValue = '1000.00', expensesdate = '2023-07-27', userid = '4', conditions = '0',saveid = '7' , dailyentryid = '8069', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '3623';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:54:02";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:24:02", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2023-07-27 12:24:02', '4', 'sucess', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:54:04";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:24:04", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2023-07-27 12:24:04', '4', 'show', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 08:54:28";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 12:24:28", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2023-07-27 12:24:28', '4', '', '197.61.41.31', '', 'DESKTOP');
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:19:23";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:49:23", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2023-07-27 12:49:24', '1', '', '156.210.49.100', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:19:24";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:19:41";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:49:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 12:49:41', '1', 'addsellBill', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:20:10";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:50:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:50:10', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:20:14";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:50:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:50:14', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:20:30";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:50:30", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storedetailController.php', '2023-07-27 12:50:30', '1', '', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:20:31";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:50:31", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('profitreportController.php', '2023-07-27 12:50:31', '1', '', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:20:36";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:50:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:50:36', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:20:50";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:50:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:50:50', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE product SET productName = '4049 الشركه', productDescription = '', productCatId = '1', productBuyPrice = '320.00', productSellAllPrice = '330', productSellUnitPrice = '330', productSellHalfPrice = '330', productDate = '2023-07-26', conditions = '0', userId = '1', limitamount = '0', parcode = '01438',type ='0', expireDate = '0' , dailyentryId = '8049',isService = '0',isOptic = '0',lastbuyprice = '320.00',lastbuyprice_withDiscount = '320',meanbuyprice = '320.00',meanbuyprice_withDiscount = '320' , productbuypricereal = '320.00' , buypricereal_precentage = '0.00' , buytotal_precentage = '0.00' , buyhalf_precentage = '6.25' , buypart_precentage = '18.75',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1438';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1438, 1,'2023-07-27 12:51:19',1)
                ON DUPLICATE KEY UPDATE productid = 1438, edited = 1, sysdate = '2023-07-27 12:51:19', userid = 1;
UPDATE product SET productName = '4049 الشركه', productDescription = '', productCatId = '1', productBuyPrice = '320.00', productSellAllPrice = '330.00', productSellUnitPrice = '330.00', productSellHalfPrice = '350', productDate = '2023-07-26', conditions = '0', userId = '1', limitamount = '0', parcode = '01438',type ='0', expireDate = '0' , dailyentryId = '8049',isService = '0',isOptic = '0',lastbuyprice = '320.00',lastbuyprice_withDiscount = '320',meanbuyprice = '320.00',meanbuyprice_withDiscount = '320' , productbuypricereal = '320.00' , buypricereal_precentage = '0.00' , buytotal_precentage = '0.00' , buyhalf_precentage = '6.25' , buypart_precentage = '18.75',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1438';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1438, 1,'2023-07-27 12:51:24',1)
                ON DUPLICATE KEY UPDATE productid = 1438, edited = 1, sysdate = '2023-07-27 12:51:24', userid = 1;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:21:24";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:51:24", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:51:24', '1', 'edit', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:21:50";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:51:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:51:51', '1', 'update', '156.210.49.100', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 1438;
UPDATE productunit SET unitid = '1', productid = '1438', productnumber = '1.00', productunitdate = '2023-07-27', userid = '1', conditions = '0',proUnitParcode='0143801',proUnitSellAllPrice='320',proUnitSellHalfPrice='340',proUnitSellUnitPrice ='380',proUnitBuyPrice='320' WHERE productunitid = '1438';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1438, 1,'2023-07-27 12:51:51',1)
                ON DUPLICATE KEY UPDATE productid = 1438, edited = 1, sysdate = '2023-07-27 12:51:51', userid = 1;
UPDATE product SET productName = '4049 الشركه', productDescription = '', productCatId = '1', productBuyPrice = '320', productSellAllPrice = '330', productSellUnitPrice = '380', productSellHalfPrice = '350', productDate = '2023-07-26', conditions = '0', userId = '1', limitamount = '0', parcode = '01438',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '320.00',lastbuyprice_withDiscount = '320',meanbuyprice = '320.00',meanbuyprice_withDiscount = '320' , productbuypricereal = '320' , buypricereal_precentage = '0' , buytotal_precentage = '0' , buyhalf_precentage = '6.25' , buypart_precentage = '18.75',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1438';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:21:53";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:51:53", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:51:53', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:22:06";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:52:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:52:06', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:22:09";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:52:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:52:09', '1', 'edit', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:22:25";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:52:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:52:25', '1', 'update', '156.210.49.100', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 1439;
UPDATE productunit SET unitid = '1', productid = '1439', productnumber = '1.00', productunitdate = '2023-07-27', userid = '1', conditions = '0',proUnitParcode='0143901',proUnitSellAllPrice='320',proUnitSellHalfPrice='340',proUnitSellUnitPrice ='380',proUnitBuyPrice='320' WHERE productunitid = '1439';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1439, 1,'2023-07-27 12:52:26',1)
                ON DUPLICATE KEY UPDATE productid = 1439, edited = 1, sysdate = '2023-07-27 12:52:26', userid = 1;
UPDATE product SET productName = '4048 الشركه', productDescription = '', productCatId = '1', productBuyPrice = '320', productSellAllPrice = '330', productSellUnitPrice = '380', productSellHalfPrice = '350', productDate = '2023-07-26', conditions = '0', userId = '1', limitamount = '0', parcode = '01439',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '320.00',lastbuyprice_withDiscount = '320',meanbuyprice = '320.00',meanbuyprice_withDiscount = '320' , productbuypricereal = '320' , buypricereal_precentage = '0' , buytotal_precentage = '3.13' , buyhalf_precentage = '9.38' , buypart_precentage = '18.75',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1439';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:22:27";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:52:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:52:27', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:22:36";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:52:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:52:36', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:22:42";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:52:42", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:52:42', '1', 'edit', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:22:56";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:52:56", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:52:56', '1', 'update', '156.210.49.100', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 1440;
UPDATE productunit SET unitid = '1', productid = '1440', productnumber = '1.00', productunitdate = '2023-07-27', userid = '1', conditions = '0',proUnitParcode='0144001',proUnitSellAllPrice='280',proUnitSellHalfPrice='300',proUnitSellUnitPrice ='340',proUnitBuyPrice='280' WHERE productunitid = '1440';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1440, 1,'2023-07-27 12:52:56',1)
                ON DUPLICATE KEY UPDATE productid = 1440, edited = 1, sysdate = '2023-07-27 12:52:56', userid = 1;
UPDATE product SET productName = '1008 الشركه', productDescription = '', productCatId = '1', productBuyPrice = '280', productSellAllPrice = '290', productSellUnitPrice = '350', productSellHalfPrice = '310', productDate = '2023-07-26', conditions = '0', userId = '1', limitamount = '0', parcode = '01440',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '280.00',lastbuyprice_withDiscount = '280',meanbuyprice = '280.00',meanbuyprice_withDiscount = '280' , productbuypricereal = '280' , buypricereal_precentage = '0' , buytotal_precentage = '3.57' , buyhalf_precentage = '10.71' , buypart_precentage = '25',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1440';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:22:58";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:52:58", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:52:58', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:23:08";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:53:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:53:08', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:23:12";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:53:12", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:53:12', '1', 'edit', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:23:30";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:53:30", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:53:30', '1', 'update', '156.210.49.100', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 1441;
UPDATE productunit SET unitid = '1', productid = '1441', productnumber = '1.00', productunitdate = '2023-07-27', userid = '1', conditions = '0',proUnitParcode='0144101',proUnitSellAllPrice='280',proUnitSellHalfPrice='300',proUnitSellUnitPrice ='340',proUnitBuyPrice='280' WHERE productunitid = '1441';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1441, 1,'2023-07-27 12:53:30',1)
                ON DUPLICATE KEY UPDATE productid = 1441, edited = 1, sysdate = '2023-07-27 12:53:30', userid = 1;
UPDATE product SET productName = '3037 الشركه', productDescription = '', productCatId = '1', productBuyPrice = '280', productSellAllPrice = '290', productSellUnitPrice = '350', productSellHalfPrice = '310', productDate = '2023-07-26', conditions = '0', userId = '1', limitamount = '0', parcode = '01441',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '280.00',lastbuyprice_withDiscount = '280',meanbuyprice = '280.00',meanbuyprice_withDiscount = '280' , productbuypricereal = '280' , buypricereal_precentage = '0' , buytotal_precentage = '3.57' , buyhalf_precentage = '10.71' , buypart_precentage = '25',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1441';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:23:32";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:53:32", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:53:32', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:23:43";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:53:43", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:53:43', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:23:46";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:53:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:53:46', '1', 'edit', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:24:10";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:54:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:54:10', '1', 'update', '156.210.49.100', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 1442;
UPDATE productunit SET unitid = '1', productid = '1442', productnumber = '1.00', productunitdate = '2023-07-27', userid = '1', conditions = '0',proUnitParcode='0144201',proUnitSellAllPrice='270',proUnitSellHalfPrice='290',proUnitSellUnitPrice ='330',proUnitBuyPrice='270' WHERE productunitid = '1442';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1442, 1,'2023-07-27 12:54:10',1)
                ON DUPLICATE KEY UPDATE productid = 1442, edited = 1, sysdate = '2023-07-27 12:54:10', userid = 1;
UPDATE product SET productName = '7074 الشركه', productDescription = '', productCatId = '1', productBuyPrice = '270', productSellAllPrice = '280', productSellUnitPrice = '340', productSellHalfPrice = '300', productDate = '2023-07-26', conditions = '0', userId = '1', limitamount = '0', parcode = '01442',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '270.00',lastbuyprice_withDiscount = '270',meanbuyprice = '270.00',meanbuyprice_withDiscount = '270' , productbuypricereal = '270' , buypricereal_precentage = '0' , buytotal_precentage = '3.7' , buyhalf_precentage = '11.11' , buypart_precentage = '25.93',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1442';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:24:12";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:54:12", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:54:12', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:24:26";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:54:26", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:54:26', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:24:30";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:54:30", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:54:30', '1', 'edit', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:24:47";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:54:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:54:47', '1', 'update', '156.210.49.100', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 1435;
UPDATE productunit SET unitid = '1', productid = '1435', productnumber = '1.00', productunitdate = '2023-07-27', userid = '1', conditions = '0',proUnitParcode='0143501',proUnitSellAllPrice='260',proUnitSellHalfPrice='280',proUnitSellUnitPrice ='320',proUnitBuyPrice='260' WHERE productunitid = '1435';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1435, 1,'2023-07-27 12:54:47',1)
                ON DUPLICATE KEY UPDATE productid = 1435, edited = 1, sysdate = '2023-07-27 12:54:47', userid = 1;
UPDATE product SET productName = '2024 الشركه', productDescription = '', productCatId = '1', productBuyPrice = '260', productSellAllPrice = '270', productSellUnitPrice = '330', productSellHalfPrice = '290', productDate = '2023-07-26', conditions = '0', userId = '1', limitamount = '0', parcode = '01435',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '260.00',lastbuyprice_withDiscount = '260',meanbuyprice = '260.00',meanbuyprice_withDiscount = '260' , productbuypricereal = '260' , buypricereal_precentage = '0' , buytotal_precentage = '3.85' , buyhalf_precentage = '11.54' , buypart_precentage = '26.92',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1435';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:24:49";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:54:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:54:49', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:24:57";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:54:57", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:54:57', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:25:00";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:55:00", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:55:00', '1', 'edit', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:25:17";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:55:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:55:17', '1', 'update', '156.210.49.100', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 1436;
UPDATE productunit SET unitid = '1', productid = '1436', productnumber = '1.00', productunitdate = '2023-07-27', userid = '1', conditions = '0',proUnitParcode='0143601',proUnitSellAllPrice='260',proUnitSellHalfPrice='280',proUnitSellUnitPrice ='320',proUnitBuyPrice='260' WHERE productunitid = '1436';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1436, 1,'2023-07-27 12:55:18',1)
                ON DUPLICATE KEY UPDATE productid = 1436, edited = 1, sysdate = '2023-07-27 12:55:18', userid = 1;
UPDATE product SET productName = '4045 الشركه', productDescription = '', productCatId = '1', productBuyPrice = '260', productSellAllPrice = '270', productSellUnitPrice = '330', productSellHalfPrice = '290', productDate = '2023-07-26', conditions = '0', userId = '1', limitamount = '0', parcode = '01436',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '260.00',lastbuyprice_withDiscount = '260',meanbuyprice = '260.00',meanbuyprice_withDiscount = '260' , productbuypricereal = '260' , buypricereal_precentage = '0' , buytotal_precentage = '3.85' , buyhalf_precentage = '11.54' , buypart_precentage = '26.92',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1436';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:25:19";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:55:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:55:19', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:25:28";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:55:28", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:55:28', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:25:30";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:55:30", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:55:30', '1', 'edit', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:25:46";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:55:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:55:46', '1', 'update', '156.210.49.100', '', 'DESKTOP');
BEGIN;
UPDATE productunit SET  conditions = 1 WHERE productunitid = 1437;
UPDATE productunit SET unitid = '1', productid = '1437', productnumber = '1.00', productunitdate = '2023-07-27', userid = '1', conditions = '0',proUnitParcode='0143701',proUnitSellAllPrice='340',proUnitSellHalfPrice='360',proUnitSellUnitPrice ='400',proUnitBuyPrice='340' WHERE productunitid = '1437';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1437, 1,'2023-07-27 12:55:46',1)
                ON DUPLICATE KEY UPDATE productid = 1437, edited = 1, sysdate = '2023-07-27 12:55:46', userid = 1;
UPDATE product SET productName = '4041 الشركه', productDescription = '', productCatId = '1', productBuyPrice = '340', productSellAllPrice = '350', productSellUnitPrice = '400', productSellHalfPrice = '370', productDate = '2023-07-26', conditions = '0', userId = '1', limitamount = '0', parcode = '01437',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '340.00',lastbuyprice_withDiscount = '340',meanbuyprice = '340.00',meanbuyprice_withDiscount = '340' , productbuypricereal = '340' , buypricereal_precentage = '0' , buytotal_precentage = '2.94' , buyhalf_precentage = '8.82' , buypart_precentage = '17.65',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1437';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:25:48";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:55:48", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:55:48', '1', 'show', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:25:57";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:55:57", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:55:57', '1', '', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:27:17";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:57:18", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:57:18', '1', 'add', '156.210.49.100', '', 'DESKTOP');
BEGIN;
INSERT INTO product (productName, productDescription, productCatId, productBuyPrice, productSellAllPrice, productSellUnitPrice, productSellHalfPrice, productDate, conditions, userId, limitamount, parcode,type, expireDate, dailyentryId,isService,isOptic,lastbuyprice,lastbuyprice_withDiscount,meanbuyprice,meanbuyprice_withDiscount , productbuypricereal , buypricereal_precentage , buytotal_precentage , buyhalf_precentage , buypart_precentage,logo,inMenu,obygyDetectionId,hasSizeAndColor,overAllAveragePrice,reviewType,online,updatebyuser,proExcelid,proExcelParcode,webApiId) VALUES ('9011 وصال','','1','275','285', '335','305', '2023-07-27', '0', '1', '0', '', '0', '0', '0', '0', '0', '275','275','275','275','275','0','3.64','10.91','21.82','.','0','0','0','0','0','','','0','0','0');
UPDATE product SET productName = '9011 وصال', productDescription = '', productCatId = '1', productBuyPrice = '275', productSellAllPrice = '285', productSellUnitPrice = '335', productSellHalfPrice = '305', productDate = '2023-07-27', conditions = '0', userId = '1', limitamount = '0', parcode = '01445',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '275',lastbuyprice_withDiscount = '275',meanbuyprice = '275',meanbuyprice_withDiscount = '275' , productbuypricereal = '275' , buypricereal_precentage = '0' , buytotal_precentage = '3.64' , buyhalf_precentage = '10.91' , buypart_precentage = '21.82',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1445';
INSERT INTO productunit (unitid, productid, productnumber, productunitdate, userid, conditions,proUnitParcode,proUnitSellAllPrice,proUnitSellHalfPrice,proUnitSellUnitPrice,proUnitBuyPrice) VALUES ('1', '1445', '1', '2023-07-27', '1', '0','0144501','285','305','335','275');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1445', '1', '48', '1', '2023-07-27');
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1445', '1', '48', '0', '1445', 'إضافة منتج', 'productController.php', '0', '48', '1', '2023-07-27','0','0');
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1445, 1,'2023-07-27 12:57:18',1)
                ON DUPLICATE KEY UPDATE productid = 1445, edited = 1, sysdate = '2023-07-27 12:57:18', userid = 1;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '13200', '13200', '2023-07-27', '1', '0', '0', '2023-07-27 12:57:18','إضافة منتج 9011 وصال الكمية 48','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8070', '19', '13200', '','0');
UPDATE accountstree SET name = 'البضاعة (بضاعة أول المدة)', customName = 'البضاعة (بضاعة أول المدة)', parent = '6', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '14450715.95', theOrder = '0', layingOrder = '121',reportid = '0' WHERE id = '19';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8070', '7', '13200', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '15208996.75', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
UPDATE product SET productName = '9011 وصال', productDescription = '', productCatId = '1', productBuyPrice = '275.00', productSellAllPrice = '285.00', productSellUnitPrice = '335.00', productSellHalfPrice = '305.00', productDate = '2023-07-27', conditions = '0', userId = '1', limitamount = '0', parcode = '01445',type ='0', expireDate = '0' , dailyentryId = '8070',isService = '0',isOptic = '0',lastbuyprice = '275',lastbuyprice_withDiscount = '275',meanbuyprice = '275',meanbuyprice_withDiscount = '275' , productbuypricereal = '275' , buypricereal_precentage = '0' , buytotal_precentage = '3.64' , buyhalf_precentage = '10.91' , buypart_precentage = '21.82',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1445';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:27:20";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:57:20", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:57:20', '1', '', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:28:21";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:58:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:58:21', '1', 'add', '156.210.49.100', '', 'DESKTOP');
BEGIN;
INSERT INTO product (productName, productDescription, productCatId, productBuyPrice, productSellAllPrice, productSellUnitPrice, productSellHalfPrice, productDate, conditions, userId, limitamount, parcode,type, expireDate, dailyentryId,isService,isOptic,lastbuyprice,lastbuyprice_withDiscount,meanbuyprice,meanbuyprice_withDiscount , productbuypricereal , buypricereal_precentage , buytotal_precentage , buyhalf_precentage , buypart_precentage,logo,inMenu,obygyDetectionId,hasSizeAndColor,overAllAveragePrice,reviewType,online,updatebyuser,proExcelid,proExcelParcode,webApiId) VALUES ('53 سكر تب','','1','260','270', '320','290', '2023-07-27', '0', '1', '0', '', '0', '0', '0', '0', '0', '260','260','260','260','260','0','3.85','11.54','23.08','.','0','0','0','0','0','','','0','0','0');
UPDATE product SET productName = '53 سكر تب', productDescription = '', productCatId = '1', productBuyPrice = '260', productSellAllPrice = '270', productSellUnitPrice = '320', productSellHalfPrice = '290', productDate = '2023-07-27', conditions = '0', userId = '1', limitamount = '0', parcode = '01446',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '260',lastbuyprice_withDiscount = '260',meanbuyprice = '260',meanbuyprice_withDiscount = '260' , productbuypricereal = '260' , buypricereal_precentage = '0' , buytotal_precentage = '3.85' , buyhalf_precentage = '11.54' , buypart_precentage = '23.08',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1446';
INSERT INTO productunit (unitid, productid, productnumber, productunitdate, userid, conditions,proUnitParcode,proUnitSellAllPrice,proUnitSellHalfPrice,proUnitSellUnitPrice,proUnitBuyPrice) VALUES ('1', '1446', '1', '2023-07-27', '1', '0','0144601','270','290','320','260');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1446', '1', '53', '1', '2023-07-27');
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1446', '1', '53', '0', '1446', 'إضافة منتج', 'productController.php', '0', '53', '1', '2023-07-27','0','0');
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1446, 1,'2023-07-27 12:58:21',1)
                ON DUPLICATE KEY UPDATE productid = 1446, edited = 1, sysdate = '2023-07-27 12:58:21', userid = 1;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '13780', '13780', '2023-07-27', '1', '0', '0', '2023-07-27 12:58:21','إضافة منتج 53 سكر تب الكمية 53','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8071', '19', '13780', '','0');
UPDATE accountstree SET name = 'البضاعة (بضاعة أول المدة)', customName = 'البضاعة (بضاعة أول المدة)', parent = '6', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '14464495.95', theOrder = '0', layingOrder = '121',reportid = '0' WHERE id = '19';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8071', '7', '13780', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '15222776.75', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
UPDATE product SET productName = '53 سكر تب', productDescription = '', productCatId = '1', productBuyPrice = '260.00', productSellAllPrice = '270.00', productSellUnitPrice = '320.00', productSellHalfPrice = '290.00', productDate = '2023-07-27', conditions = '0', userId = '1', limitamount = '0', parcode = '01446',type ='0', expireDate = '0' , dailyentryId = '8071',isService = '0',isOptic = '0',lastbuyprice = '260',lastbuyprice_withDiscount = '260',meanbuyprice = '260',meanbuyprice_withDiscount = '260' , productbuypricereal = '260' , buypricereal_precentage = '0' , buytotal_precentage = '3.85' , buyhalf_precentage = '11.54' , buypart_precentage = '23.08',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1446';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:28:23";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:58:23", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2023-07-27 12:58:23', '1', '', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:28:25";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:58:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-07-27 12:58:25', '1', '', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:28:51";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:58:51", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-07-27 12:58:52', '1', 'add', '156.210.49.100', '', 'DESKTOP');
DROP PROCEDURE IF EXISTS insertUniqueOptNum;;

CREATE PROCEDURE insertUniqueOptNum(IN optnum INT,IN storeidfrom INT,IN storeidto INT,IN productid INT,IN transferproductamount DECIMAL(10,2),IN transferproductdate DATE,IN userid INT,IN conditions INT,IN `comment` TEXT,IN deloperationnum INT,IN sizeid INT,IN colorid INT,IN driverid INT,IN drivertimeout INT,IN driverdate datetime,IN delivererid INT,IN deliverdate datetime,OUT inserted_id INT,OUT optnum_used INT)
BEGIN
DECLARE n INT DEFAULT 0;
DECLARE id INT DEFAULT 0;
DECLARE lastopt INT DEFAULT 0;


DECLARE EXIT HANDLER FOR SQLEXCEPTION
    BEGIN
    ROLLBACK;
    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
     @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
    SET @full_error = CONCAT("ERROR ", @errno, " (", @sqlstate, "): ", @text);
    SELECT @full_error;
    ROLLBACK;
END;



START TRANSACTION;


SELECT COUNT(*) FROM storemovement WHERE `operationnum` = optnum INTO n;
SELECT DISTINCT operationnum FROM storemovement WHERE operationnum != 0  ORDER BY operationnum DESC limit 1 INTO lastopt;
set lastopt = lastopt+1;

	IF n > 0 THEN


      INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions,comment,operationnum ,deloperationnum,sizeid,colorid,driverid,drivertimeout,driverdate,delivererid,deliverdate)
                VALUES (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,comment ,
                lastopt,
                deloperationnum,sizeid,colorid,driverid,drivertimeout,driverdate,delivererid,deliverdate);
            SELECT LAST_INSERT_ID(),lastopt INTO inserted_id,optnum_used;
ELSE

    INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions,comment,operationnum ,deloperationnum,sizeid,colorid,driverid,drivertimeout,driverdate,delivererid,deliverdate)
                VALUES (storeidfrom, storeidto, productid,transferproductamount, transferproductdate, userid, conditions ,comment
                ,optnum
                ,deloperationnum,sizeid,colorid,driverid,drivertimeout,driverdate,delivererid,deliverdate);
            SELECT LAST_INSERT_ID(),optnum INTO inserted_id,optnum_used;
	END IF;

COMMIT WORK; -- it is mandatory dont wait comit in php.as if sp didnot found comit before reaching the end it will rollback giving no errors at all

End;
;;

;
BEGIN;
CALL insertUniqueOptNum(1640,1,7,1446,28,'2023-07-27',1,0, '' ,0,0,0,0,0,'2023-07-27 12:58:52',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '25', userid = '1', storedetaildate = '2023-07-27' WHERE storedetailid = '5314';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-07-27', 1, 1446, 0, 0
                    , 260.00, -28, 0, 0, 1, '2023-07-27 12:58:52')
                ON DUPLICATE KEY UPDATE buyprice = 260.00,
                        buyQuantity =buyQuantity+-28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 12:58:52' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "28*2023-07-27*260.00," WHERE transferproductid = 7338;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1446', '1', '28', '1', '7338', 'تحويل منتجات من المخزن', 'storemovementController.php', '53.00', '25', '1', '2023-07-27','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1446', '7', '28', '1', '2023-07-27');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-07-27', 7, 1446, 0, 0
                    , 260.00, 28, 0, 0, 1, '2023-07-27 12:58:52')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 12:58:52' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1446', '7', '28', '0', '7338', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '28', '1', '2023-07-27','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', '1445', '24', '2023-07-27', '1', '0','1640',null,null,'2023-07-27 12:58:52',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '24', userid = '1', storedetaildate = '2023-07-27' WHERE storedetailid = '5313';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-07-27', 1, 1445, 0, 0
                    , 275.00, -24, 0, 0, 1, '2023-07-27 12:58:52')
                ON DUPLICATE KEY UPDATE buyprice = 275.00,
                        buyQuantity =buyQuantity+-24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 12:58:52' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "24*2023-07-27*275.00," WHERE transferproductid = 7339;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1445', '1', '24', '1', '7339', 'تحويل منتجات من المخزن', 'storemovementController.php', '48.00', '24', '1', '2023-07-27','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1445', '7', '24', '1', '2023-07-27');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-07-27', 7, 1445, 0, 0
                    , 275.00, 24, 0, 0, 1, '2023-07-27 12:58:52')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 12:58:52' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1445', '7', '24', '0', '7339', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '24', '1', '2023-07-27','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:28:52";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:58:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-07-27 12:58:52', '1', 'editshow', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:29:22";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 12:59:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-07-27 12:59:22', '1', '', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:31:56";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 13:01:56", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-07-27 13:01:56', '1', 'add', '156.210.49.100', '', 'DESKTOP');
DROP PROCEDURE IF EXISTS insertUniqueOptNum;;

CREATE PROCEDURE insertUniqueOptNum(IN optnum INT,IN storeidfrom INT,IN storeidto INT,IN productid INT,IN transferproductamount DECIMAL(10,2),IN transferproductdate DATE,IN userid INT,IN conditions INT,IN `comment` TEXT,IN deloperationnum INT,IN sizeid INT,IN colorid INT,IN driverid INT,IN drivertimeout INT,IN driverdate datetime,IN delivererid INT,IN deliverdate datetime,OUT inserted_id INT,OUT optnum_used INT)
BEGIN
DECLARE n INT DEFAULT 0;
DECLARE id INT DEFAULT 0;
DECLARE lastopt INT DEFAULT 0;


DECLARE EXIT HANDLER FOR SQLEXCEPTION
    BEGIN
    ROLLBACK;
    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
     @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
    SET @full_error = CONCAT("ERROR ", @errno, " (", @sqlstate, "): ", @text);
    SELECT @full_error;
    ROLLBACK;
END;



START TRANSACTION;


SELECT COUNT(*) FROM storemovement WHERE `operationnum` = optnum INTO n;
SELECT DISTINCT operationnum FROM storemovement WHERE operationnum != 0  ORDER BY operationnum DESC limit 1 INTO lastopt;
set lastopt = lastopt+1;

	IF n > 0 THEN


      INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions,comment,operationnum ,deloperationnum,sizeid,colorid,driverid,drivertimeout,driverdate,delivererid,deliverdate)
                VALUES (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,comment ,
                lastopt,
                deloperationnum,sizeid,colorid,driverid,drivertimeout,driverdate,delivererid,deliverdate);
            SELECT LAST_INSERT_ID(),lastopt INTO inserted_id,optnum_used;
ELSE

    INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions,comment,operationnum ,deloperationnum,sizeid,colorid,driverid,drivertimeout,driverdate,delivererid,deliverdate)
                VALUES (storeidfrom, storeidto, productid,transferproductamount, transferproductdate, userid, conditions ,comment
                ,optnum
                ,deloperationnum,sizeid,colorid,driverid,drivertimeout,driverdate,delivererid,deliverdate);
            SELECT LAST_INSERT_ID(),optnum INTO inserted_id,optnum_used;
	END IF;

COMMIT WORK; -- it is mandatory dont wait comit in php.as if sp didnot found comit before reaching the end it will rollback giving no errors at all

End;
;;

;
BEGIN;
CALL insertUniqueOptNum(1641,1,8,1446,28,'2023-07-27',1,0, '' ,0,0,0,0,0,'2023-07-27 13:01:56',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '-3', userid = '1', storedetaildate = '2023-07-27' WHERE storedetailid = '5314';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-07-27', 1, 1446, 0, 0
                    , 260.00, -28, 0, 0, 1, '2023-07-27 13:01:56')
                ON DUPLICATE KEY UPDATE buyprice = 260.00,
                        buyQuantity =buyQuantity+-28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 13:01:56' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "28*2023-07-27*260.00," WHERE transferproductid = 7340;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1446', '1', '28', '1', '7340', 'تحويل منتجات من المخزن', 'storemovementController.php', '25.00', '-3', '1', '2023-07-27','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1446', '8', '28', '1', '2023-07-27');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-07-27', 8, 1446, 0, 0
                    , 260.00, 28, 0, 0, 1, '2023-07-27 13:01:56')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+28, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 13:01:56' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1446', '8', '28', '0', '7340', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '28', '1', '2023-07-27','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('1', '8', '1445', '24', '2023-07-27', '1', '0','1641',null,null,'2023-07-27 13:01:56',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2023-07-27' WHERE storedetailid = '5313';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-07-27', 1, 1445, 0, 0
                    , 275.00, -24, 0, 0, 1, '2023-07-27 13:01:56')
                ON DUPLICATE KEY UPDATE buyprice = 275.00,
                        buyQuantity =buyQuantity+-24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 13:01:56' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "24*2023-07-27*275.00," WHERE transferproductid = 7341;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1445', '1', '24', '1', '7341', 'تحويل منتجات من المخزن', 'storemovementController.php', '24.00', '0', '1', '2023-07-27','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1445', '8', '24', '1', '2023-07-27');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-07-27', 8, 1445, 0, 0
                    , 275.00, 24, 0, 0, 1, '2023-07-27 13:01:56')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+24, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 13:01:56' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1445', '8', '24', '0', '7341', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '24', '1', '2023-07-27','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:31:56";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 13:01:56", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-07-27 13:01:56', '1', 'editshow', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 09:33:39";
UPDATE user SET loginip = "156.210.49.100", lastactivetime = "2023-07-27 13:03:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 13:03:39', '1', 'addsellBill', '156.210.49.100', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 10:17:03";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 13:47:03", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 13:47:03', '4', 'addsellBill', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 11:02:43";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 14:32:44", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2023-07-27 14:32:44', '4', '', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 11:09:47";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 14:39:47", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2023-07-27 14:39:47', '4', '', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 11:10:04";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 14:40:04", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2023-07-27 14:40:04', '4', 'show', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 11:10:15";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 14:40:15", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2023-07-27 14:40:15', '4', 'editprint', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 11:10:16";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 14:40:16", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2023-07-27 14:40:16', '4', 'editprint', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 11:10:21";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 14:40:21", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 14:40:21', '4', 'showDetail', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 11:10:28";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 14:40:28", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 14:40:28', '4', 'showDetail', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 11:10:49";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 14:40:49", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2023-07-27 14:40:49', '4', 'editprint', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 11:11:05";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 14:41:05", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2023-07-27 14:41:05', '4', 'show', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 11:11:12";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 14:41:12", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2023-07-27 14:41:12', '4', 'editprint', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 11:11:29";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 14:41:29", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2023-07-27 14:41:29', '4', '', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 11:53:51";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 15:23:51", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2023-07-27 15:23:51', '4', '', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 11:54:20";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 15:24:20", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 15:24:20', '4', 'addsellBill', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 12:05:14";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 15:35:15", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2023-07-27 15:35:15', '4', '', '197.61.41.31', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 13:04:12";
UPDATE user SET loginip = "197.61.41.31", lastactivetime = "2023-07-27 16:34:12", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 16:34:12', '4', 'addsellBill', '197.61.41.31', '', 'DESKTOP');
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 13:40:43";
UPDATE user SET loginip = "197.192.237.58", lastactivetime = "2023-07-27 17:10:43", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2023-07-27 17:10:43', '7', '', '197.192.237.58', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 13:40:43";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 13:41:06";
UPDATE user SET loginip = "197.192.237.58", lastactivetime = "2023-07-27 17:11:06", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 17:11:06', '7', 'addsellBill', '197.192.237.58', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 1;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 15:36:12";
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-07-27 15:56:32";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 19:26:32", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2023-07-27 19:26:32', '1', '', '156.210.55.83', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 15:56:32";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 15:56:43";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 19:26:43", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2023-07-27 19:26:43', '1', '', '156.210.55.83', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 15:56:53";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 19:26:53", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2023-07-27 19:26:53', '1', 'add', '156.210.55.83', '', 'DESKTOP');
BEGIN;
INSERT INTO transfermoney (saveidfrom, saveidto, transfermoneyvalue, transfermoneydate, userid, conditions, dailyentryid , comment) VALUES ('8','9', '18395.00', '2023-07-27', '1', '0', '0','');
UPDATE save SET  savecurrentvalue = '0',  userid = '1' WHERE saveid = '8';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('18395.00','18395.00', '1', '8', 'تحويل امول الى الخزنة  [ الشيخ وليد ] ', '594', '0', '2023-07-27 19:26:53', '1',  'transfermoneyController.php','0','');
UPDATE save SET  savecurrentvalue = '7270030',  userid = '1' WHERE saveid = '9';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('7251635.00','18395.00', '0', '9', 'تحويل امول من الخزنة  [ خزينة محل ابو كريم ] ', '594', '7270030', '2023-07-27 19:26:53', '1',  'transfermoneyController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '18395', '18395', '2023-07-27', '1', '0', '0', '2023-07-27 19:26:53','اضافة تحويل من خزينة محل ابو كريم الى الشيخ وليد','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8072', '156', '18395.00', '','0');
UPDATE accountstree SET name = 'الشيخ وليد', customName = 'الشيخ وليد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-09', itemtype2 = '1', theValue = '7270030', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '156';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8072', '142', '18395.00', '','0');
UPDATE accountstree SET name = 'خزينة محل ابو كريم', customName = 'خزينة محل ابو كريم', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-1616916', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '142';
UPDATE transfermoney SET saveidfrom = '8', saveidto = '9', transfermoneyvalue = '18395.00', transfermoneydate = '2023-07-27', userid = '1', conditions = '0' , dailyentryid = '8072' , comment = '' WHERE transfermoneyid = '594';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 15:56:54";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 19:26:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2023-07-27 19:26:54', '1', 'sucess', '156.210.55.83', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 15:56:56";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 19:26:56", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2023-07-27 19:26:56', '1', 'show', '156.210.55.83', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 15:56:56";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 19:26:56", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 19:26:56', '1', 'addsellBill', '156.210.55.83', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 16:02:11";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 19:32:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2023-07-27 19:32:11', '1', '', '156.210.55.83', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 16:02:53";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 19:32:53", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2023-07-27 19:32:53', '1', '', '156.210.55.83', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 16:02:59";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 19:32:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 19:32:59', '1', 'addsellBill', '156.210.55.83', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 16:09:08";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 19:39:08", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2023-07-27 19:39:08', '1', '', '156.210.55.83', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 16:09:17";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 19:39:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2023-07-27 19:39:17', '1', 'add', '156.210.55.83', '', 'DESKTOP');
BEGIN;
INSERT INTO transfermoney (saveidfrom, saveidto, transfermoneyvalue, transfermoneydate, userid, conditions, dailyentryid , comment) VALUES ('7','9', '1615.00', '2023-07-27', '1', '0', '0','');
UPDATE save SET  savecurrentvalue = '0',  userid = '1' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('1615.00','1615.00', '1', '7', 'تحويل امول الى الخزنة  [ الشيخ وليد ] ', '595', '0', '2023-07-27 19:39:17', '1',  'transfermoneyController.php','0','');
UPDATE save SET  savecurrentvalue = '7271645',  userid = '1' WHERE saveid = '9';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('7270030.00','1615.00', '0', '9', 'تحويل امول من الخزنة  [ خزينة محل العميد ] ', '595', '7271645', '2023-07-27 19:39:17', '1',  'transfermoneyController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '1615', '1615', '2023-07-27', '1', '0', '0', '2023-07-27 19:39:17','اضافة تحويل من خزينة محل العميد الى الشيخ وليد','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8073', '156', '1615.00', '','0');
UPDATE accountstree SET name = 'الشيخ وليد', customName = 'الشيخ وليد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-09', itemtype2 = '1', theValue = '7271645', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '156';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('8073', '141', '1615.00', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-1527947', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE transfermoney SET saveidfrom = '7', saveidto = '9', transfermoneyvalue = '1615.00', transfermoneydate = '2023-07-27', userid = '1', conditions = '0' , dailyentryid = '8073' , comment = '' WHERE transfermoneyid = '595';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 16:09:17";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 19:39:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2023-07-27 19:39:18', '1', 'sucess', '156.210.55.83', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 16:09:19";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 19:39:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2023-07-27 19:39:19', '1', 'show', '156.210.55.83', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 16:46:14";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 20:16:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-07-27 20:16:14', '1', '', '156.210.55.83', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 16:46:17";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 20:16:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-07-27 20:16:17', '1', 'show', '156.210.55.83', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 16:46:43";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 20:16:43", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-07-27 20:16:43', '1', 'show', '156.210.55.83', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 16:46:51";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 20:16:51", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-07-27 20:16:51', '1', '', '156.210.55.83', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 16:48:20";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 20:18:20", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-07-27 20:18:20', '1', 'add', '156.210.55.83', '', 'DESKTOP');
DROP PROCEDURE IF EXISTS insertUniqueOptNum;;

CREATE PROCEDURE insertUniqueOptNum(IN optnum INT,IN storeidfrom INT,IN storeidto INT,IN productid INT,IN transferproductamount DECIMAL(10,2),IN transferproductdate DATE,IN userid INT,IN conditions INT,IN `comment` TEXT,IN deloperationnum INT,IN sizeid INT,IN colorid INT,IN driverid INT,IN drivertimeout INT,IN driverdate datetime,IN delivererid INT,IN deliverdate datetime,OUT inserted_id INT,OUT optnum_used INT)
BEGIN
DECLARE n INT DEFAULT 0;
DECLARE id INT DEFAULT 0;
DECLARE lastopt INT DEFAULT 0;


DECLARE EXIT HANDLER FOR SQLEXCEPTION
    BEGIN
    ROLLBACK;
    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
     @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
    SET @full_error = CONCAT("ERROR ", @errno, " (", @sqlstate, "): ", @text);
    SELECT @full_error;
    ROLLBACK;
END;



START TRANSACTION;


SELECT COUNT(*) FROM storemovement WHERE `operationnum` = optnum INTO n;
SELECT DISTINCT operationnum FROM storemovement WHERE operationnum != 0  ORDER BY operationnum DESC limit 1 INTO lastopt;
set lastopt = lastopt+1;

	IF n > 0 THEN


      INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions,comment,operationnum ,deloperationnum,sizeid,colorid,driverid,drivertimeout,driverdate,delivererid,deliverdate)
                VALUES (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,comment ,
                lastopt,
                deloperationnum,sizeid,colorid,driverid,drivertimeout,driverdate,delivererid,deliverdate);
            SELECT LAST_INSERT_ID(),lastopt INTO inserted_id,optnum_used;
ELSE

    INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions,comment,operationnum ,deloperationnum,sizeid,colorid,driverid,drivertimeout,driverdate,delivererid,deliverdate)
                VALUES (storeidfrom, storeidto, productid,transferproductamount, transferproductdate, userid, conditions ,comment
                ,optnum
                ,deloperationnum,sizeid,colorid,driverid,drivertimeout,driverdate,delivererid,deliverdate);
            SELECT LAST_INSERT_ID(),optnum INTO inserted_id,optnum_used;
	END IF;

COMMIT WORK; -- it is mandatory dont wait comit in php.as if sp didnot found comit before reaching the end it will rollback giving no errors at all

End;
;;

;
BEGIN;
CALL insertUniqueOptNum(1642,6,5,1414,10,'2023-07-27',1,0, '' ,0,0,0,0,0,'2023-07-27 20:18:20',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '-1', userid = '1', storedetaildate = '2023-07-27' WHERE storedetailid = '5221';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-06-22', 6, 1414, 0, 0
                    , 315.00, 8, 0, 0, 1, '2023-07-27 20:18:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity-8, sellQuantity = sellQuantity-0,
                        del = 0,userid = 1,sysDate = '2023-07-27 20:18:20' ;
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-07-27', 6, 1414, 0, 0
                    , 315.00, -2, 0, 0, 1, '2023-07-27 20:18:20')
                ON DUPLICATE KEY UPDATE buyprice = 315.00,
                        buyQuantity =buyQuantity+-2, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 20:18:20' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "8*2023-06-22*315.00,2*2023-07-27*315.00," WHERE transferproductid = 7342;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1414', '6', '10', '1', '7342', 'تحويل منتجات من المخزن', 'storemovementController.php', '9.00', '-1', '1', '2023-07-27','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1414', '5', '10', '1', '2023-07-27');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-06-22', 5, 1414, 0, 0
                    , 315.00, 8, 0, 0, 1, '2023-07-27 20:18:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+8, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 20:18:20' ;
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-07-27', 5, 1414, 0, 0
                    , 315.00, 2, 0, 0, 1, '2023-07-27 20:18:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+2, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 20:18:20' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1414', '5', '10', '0', '7342', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '10', '1', '2023-07-27','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('6', '5', '1413', '8', '2023-07-27', '1', '0','1642',null,null,'2023-07-27 20:18:20',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '1', userid = '1', storedetaildate = '2023-07-27' WHERE storedetailid = '5220';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-06-22', 6, 1413, 0, 0
                    , 290.00, 8, 0, 0, 1, '2023-07-27 20:18:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity-8, sellQuantity = sellQuantity-0,
                        del = 0,userid = 1,sysDate = '2023-07-27 20:18:20' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "8*2023-06-22*290.00," WHERE transferproductid = 7343;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1413', '6', '8', '1', '7343', 'تحويل منتجات من المخزن', 'storemovementController.php', '9.00', '1', '1', '2023-07-27','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1413', '5', '8', '1', '2023-07-27');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-06-22', 5, 1413, 0, 0
                    , 290.00, 8, 0, 0, 1, '2023-07-27 20:18:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+8, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 20:18:20' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1413', '5', '8', '0', '7343', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '8', '1', '2023-07-27','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('6', '5', '1422', '11', '2023-07-27', '1', '0','1642',null,null,'2023-07-27 20:18:20',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '4', userid = '1', storedetaildate = '2023-07-27' WHERE storedetailid = '5248';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-07-09', 6, 1422, 0, 0
                    , 270.00, 11, 0, 0, 1, '2023-07-27 20:18:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity-11, sellQuantity = sellQuantity-0,
                        del = 0,userid = 1,sysDate = '2023-07-27 20:18:20' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "11*2023-07-09*270.00," WHERE transferproductid = 7344;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1422', '6', '11', '1', '7344', 'تحويل منتجات من المخزن', 'storemovementController.php', '15.00', '4', '1', '2023-07-27','0','0');
UPDATE storedetail SET  productquantity = '16', userid = '1', storedetaildate = '2023-07-27' WHERE storedetailid = '5247';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-07-09', 5, 1422, 0, 0
                    , 270.00, 11, 0, 0, 1, '2023-07-27 20:18:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+11, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 20:18:20' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1422', '5', '11', '0', '7344', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '5.00', '16', '1', '2023-07-27','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('6', '5', '1386', '5', '2023-07-27', '1', '0','1642',null,null,'2023-07-27 20:18:20',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '-1', userid = '1', storedetaildate = '2023-07-27' WHERE storedetailid = '5123';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-06-06', 6, 1386, 0, 0
                    , 290.00, 1, 0, 0, 1, '2023-07-27 20:18:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity-1, sellQuantity = sellQuantity-0,
                        del = 0,userid = 1,sysDate = '2023-07-27 20:18:20' ;
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-07-09', 6, 1386, 0, 0
                    , 290.00, 1, 0, 0, 1, '2023-07-27 20:18:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity-1, sellQuantity = sellQuantity-0,
                        del = 0,userid = 1,sysDate = '2023-07-27 20:18:20' ;
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-07-27', 6, 1386, 0, 0
                    , 290.00, -3, 0, 0, 1, '2023-07-27 20:18:20')
                ON DUPLICATE KEY UPDATE buyprice = 290.00,
                        buyQuantity =buyQuantity+-3, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 20:18:20' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "1*2023-06-06*290.00,1*2023-07-09*290.00,3*2023-07-27*290.00," WHERE transferproductid = 7345;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1386', '6', '5', '1', '7345', 'تحويل منتجات من المخزن', 'storemovementController.php', '4.00', '-1', '1', '2023-07-27','0','0');
UPDATE storedetail SET  productquantity = '6', userid = '1', storedetaildate = '2023-07-27' WHERE storedetailid = '5121';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-06-06', 5, 1386, 0, 0
                    , 290.00, 1, 0, 0, 1, '2023-07-27 20:18:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 20:18:20' ;
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-07-09', 5, 1386, 0, 0
                    , 290.00, 1, 0, 0, 1, '2023-07-27 20:18:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+1, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 20:18:20' ;
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-07-27', 5, 1386, 0, 0
                    , 290.00, 3, 0, 0, 1, '2023-07-27 20:18:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+3, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 20:18:20' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1386', '5', '5', '0', '7345', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '1.00', '6', '1', '2023-07-27','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('6', '5', '1383', '6', '2023-07-27', '1', '0','1642',null,null,'2023-07-27 20:18:20',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2023-07-27' WHERE storedetailid = '5124';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-06-06', 6, 1383, 0, 0
                    , 340.00, 6, 0, 0, 1, '2023-07-27 20:18:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity-6, sellQuantity = sellQuantity-0,
                        del = 0,userid = 1,sysDate = '2023-07-27 20:18:20' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "6*2023-06-06*340.00," WHERE transferproductid = 7346;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1383', '6', '6', '1', '7346', 'تحويل منتجات من المخزن', 'storemovementController.php', '6.00', '0', '1', '2023-07-27','0','0');
UPDATE storedetail SET  productquantity = '6', userid = '1', storedetaildate = '2023-07-27' WHERE storedetailid = '5118';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2023-06-06', 5, 1383, 0, 0
                    , 340.00, 6, 0, 0, 1, '2023-07-27 20:18:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+6, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2023-07-27 20:18:20' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1383', '5', '6', '0', '7346', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0.00', '6', '1', '2023-07-27','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 16:48:21";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 20:18:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2023-07-27 20:18:21', '1', 'editshow', '156.210.55.83', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 16:48:42";
UPDATE user SET loginip = "156.210.55.83", lastactivetime = "2023-07-27 20:18:42", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 20:18:42', '1', 'addsellBill', '156.210.55.83', '', 'DESKTOP');
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 17:57:13";
UPDATE user SET loginip = "197.63.215.180", lastactivetime = "2023-07-27 21:27:13", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2023-07-27 21:27:14', '8', '', '197.63.215.180', '', 'DESKTOP');
UPDATE product
                JOIN (
                       select productingredients.productId
                              ,sum(productnumber * quantity * productBuyPrice) as productBuyPrice
                              ,sum(productnumber * quantity * lastbuyprice) as lastbuyprice
                              ,sum(productnumber * quantity * lastbuyprice_withDiscount) as lastbuyprice_withDiscount
                              ,sum(productnumber * quantity * meanbuyprice) as meanbuyprice
                              ,sum(productnumber * quantity * meanbuyprice_withDiscount) as meanbuyprice_withDiscount
                              ,sum(productnumber * quantity * overAllAveragePrice) as overAllAveragePrice
                      from product
                      join productingredients on product.productId = productingredients.ingridientId
                      join productunit on productunit.productunitid = productingredients.unitId
                      group by productingredients.productId
                    ) as ingridientPrice ON ingridientPrice.productId =  product.productId
                SET product.productBuyPrice = ingridientPrice.productBuyPrice,
                        product.lastbuyprice = ingridientPrice.lastbuyprice,
                    product.lastbuyprice_withDiscount = ingridientPrice.lastbuyprice_withDiscount,
                    product.meanbuyprice = ingridientPrice.meanbuyprice,
                    product.meanbuyprice_withDiscount = ingridientPrice.meanbuyprice_withDiscount,
                    product.overAllAveragePrice = ingridientPrice.overAllAveragePrice;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 17:57:14";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 17:57:16";
UPDATE user SET loginip = "197.63.215.180", lastactivetime = "2023-07-27 21:27:16", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 21:27:16', '8', 'addsellBill', '197.63.215.180', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 18:00:25";
UPDATE user SET loginip = "197.63.215.180", lastactivetime = "2023-07-27 21:30:25", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 21:30:25', '8', 'addAndRetuen', '197.63.215.180', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 064c2b7050f2d8
-- ----------------------------------------------------------------------------------------------------

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-07-27 21:27:17', '064c2b7050f2d8', '1', '0.00', '0', '0', '1', '1780', '1780', '1780', '0', '6', '2023-07-27 21:30:25', '', '8', '0', 'نقدي', '6', '0', '3', '0', 'نقدي', '6' ,'0','','','','','-1','0','0','0','0','0','1780','0','','0','0','1780','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '8' 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','اضافة فاتورة مبيعات','13841', '0', '2023-07-27 21:30:25', '8', 'sellbillController.php', 'اضافة فاتورة مبيعات', '1780', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 15875;
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 ('260','01435', '13841', '1', '1435', '1', '270', '270', '0', '', '0', '2023-07-27 21:30:25', '1435', '0.00', '0', '6','0','','','0','0','0','0','0','0','0','0','','15875-1,');
UPDATE sellbilldetail SET  lastbuyprice = 260.00 , meanbuyprice = 260.00, lastbuyprice_withDiscount = 260.00, meanbuyprice_withDiscount = 260.00
                where sellbilldetailid = 41043;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1435, '2023-07-27', 270, 260, 260
                    , 260, 260, 260, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+270, sellCostBuyPrice =sellCostBuyPrice+260
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+260, sellCostMeanBuyPrice = sellCostMeanBuyPrice+260
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+260, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+260
                            , 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 (6, '2023-07-27', 270, 260, 260
                    , 260, 260, 260, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+270, sellCostBuyPrice =sellCostBuyPrice+260
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+260, sellCostMeanBuyPrice = sellCostMeanBuyPrice+260
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+260, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+260
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '19', userid = '8', storedetaildate = '2023-07-27 21:30:25' WHERE storedetailid = '5295';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1435', '6', '1', '1', '13841', 'اضافة فاتورة مبيعات', 'sellbillController.php', '20.00', '19', '8', '2023-07-27 21:30:25','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 15879;
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 ('340','01437', '13841', '1', '1437', '1', '350', '350', '0', '', '0', '2023-07-27 21:30:25', '1437', '0.00', '0', '6','0','','','0','0','0','0','0','0','0','0','','15879-1,');
UPDATE sellbilldetail SET  lastbuyprice = 340.00 , meanbuyprice = 340.00, lastbuyprice_withDiscount = 340.00, meanbuyprice_withDiscount = 340.00
                where sellbilldetailid = 41044;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1437, '2023-07-27', 350, 340, 340
                    , 340, 340, 340, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+350, sellCostBuyPrice =sellCostBuyPrice+340
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+340, sellCostMeanBuyPrice = sellCostMeanBuyPrice+340
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+340, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+340
                            , 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 (6, '2023-07-27', 350, 340, 340
                    , 340, 340, 340, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+350, sellCostBuyPrice =sellCostBuyPrice+340
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+340, sellCostMeanBuyPrice = sellCostMeanBuyPrice+340
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+340, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+340
                            , 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 = '31', userid = '8', storedetaildate = '2023-07-27 21:30:25' WHERE storedetailid = '5297';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1437', '6', '1', '1', '13841', 'اضافة فاتورة مبيعات', 'sellbillController.php', '32.00', '31', '8', '2023-07-27 21:30:25','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 15877;
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 ('260','01436', '13841', '1', '1436', '1', '270', '270', '0', '', '0', '2023-07-27 21:30:25', '1436', '0.00', '0', '6','0','','','0','0','0','0','0','0','0','0','','15877-1,');
UPDATE sellbilldetail SET  lastbuyprice = 260.00 , meanbuyprice = 260.00, lastbuyprice_withDiscount = 260.00, meanbuyprice_withDiscount = 260.00
                where sellbilldetailid = 41045;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1436, '2023-07-27', 270, 260, 260
                    , 260, 260, 260, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+270, sellCostBuyPrice =sellCostBuyPrice+260
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+260, sellCostMeanBuyPrice = sellCostMeanBuyPrice+260
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+260, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+260
                            , 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 (6, '2023-07-27', 270, 260, 260
                    , 260, 260, 260, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+270, sellCostBuyPrice =sellCostBuyPrice+260
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+260, sellCostMeanBuyPrice = sellCostMeanBuyPrice+260
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+260, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+260
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '15', userid = '8', storedetaildate = '2023-07-27 21:30:25' WHERE storedetailid = '5296';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1436', '6', '1', '1', '13841', 'اضافة فاتورة مبيعات', 'sellbillController.php', '16.00', '15', '8', '2023-07-27 21:30:25','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 15879;
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 ('340','01437', '13841', '1', '1437', '1', '350', '350', '0', '', '0', '2023-07-27 21:30:25', '1437', '0.00', '0', '6','0','','','0','0','0','0','0','0','0','0','','15879-1,');
UPDATE sellbilldetail SET  lastbuyprice = 340.00 , meanbuyprice = 340.00, lastbuyprice_withDiscount = 340.00, meanbuyprice_withDiscount = 340.00
                where sellbilldetailid = 41046;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1437, '2023-07-27', 350, 340, 340
                    , 340, 340, 340, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+350, sellCostBuyPrice =sellCostBuyPrice+340
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+340, sellCostMeanBuyPrice = sellCostMeanBuyPrice+340
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+340, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+340
                            , 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 (6, '2023-07-27', 350, 340, 340
                    , 340, 340, 340, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+350, sellCostBuyPrice =sellCostBuyPrice+340
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+340, sellCostMeanBuyPrice = sellCostMeanBuyPrice+340
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+340, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+340
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '30', userid = '8', storedetaildate = '2023-07-27 21:30:25' WHERE storedetailid = '5297';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1437', '6', '1', '1', '13841', 'اضافة فاتورة مبيعات', 'sellbillController.php', '31.00', '30', '8', '2023-07-27 21:30:25','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+2 where id = 15877;
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 ('260','01436', '13841', '1', '1436', '2', '270', '540', '0', '', '0', '2023-07-27 21:30:25', '1436', '0.00', '0', '6','0','','','0','0','0','0','0','0','0','0','','15877-2,');
UPDATE sellbilldetail SET  lastbuyprice = 260.00 , meanbuyprice = 260.00, lastbuyprice_withDiscount = 260.00, meanbuyprice_withDiscount = 260.00
                where sellbilldetailid = 41047;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1436, '2023-07-27', 540, 520, 520
                    , 520, 520, 520, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 2, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+540, sellCostBuyPrice =sellCostBuyPrice+520
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+520, sellCostMeanBuyPrice = sellCostMeanBuyPrice+520
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+520, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+520
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+2
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (6, '2023-07-27', 540, 520, 520
                    , 520, 520, 520, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+540, sellCostBuyPrice =sellCostBuyPrice+520
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+520, sellCostMeanBuyPrice = sellCostMeanBuyPrice+520
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+520, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+520
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '13', userid = '8', storedetaildate = '2023-07-27 21:30:25' WHERE storedetailid = '5296';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1436', '6', '2', '1', '13841', 'اضافة فاتورة مبيعات', 'sellbillController.php', '15.00', '13', '8', '2023-07-27 21:30:25','0','0');
UPDATE save SET  savecurrentvalue = '21762',  userid = '8' WHERE saveid = '6';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('19982.00','1780', '0', '6', 'اضافة فاتورة مبيعات', '13841', '21762', '2023-07-27 21:30:25', '8',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2023-07-27', 1780, 1720, 1720
                    , 1720, 1720, 1720, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1780, sellCostBuyPrice =sellCostBuyPrice+1720
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1720, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1720
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1720, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1720
                            , 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-07-27', 1780, 1720, 1720
                    , 1720, 1720, 1720, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1780, sellCostBuyPrice =sellCostBuyPrice+1720
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1720, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1720
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1720, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1720
                            , 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, 1780, 1720, 1720
                    , 1720, 1720, 1720, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+1780, netSellCostBuyPrice = netSellCostBuyPrice+1720
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+1720
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+1720
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+1720
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+1720
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 064c2b7050f2d8 and sellbillId = 13841 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 18:00:25";
UPDATE user SET loginip = "197.63.215.180", lastactivetime = "2023-07-27 21:30:26", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 21:30:26', '8', 'addsellBill', '197.63.215.180', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 18:00:52";
UPDATE user SET loginip = "197.63.215.180", lastactivetime = "2023-07-27 21:30:52", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 21:30:52', '8', 'addAndRetuen', '197.63.215.180', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 064c2b7c232b02
-- ----------------------------------------------------------------------------------------------------

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-07-27 21:30:26', '064c2b7c232b02', '1', '0.00', '0', '0', '1', '300', '300', '300', '0', '6', '2023-07-27 21:30:52', '', '8', '0', 'نقدي', '6', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','300','0','','0','0','300','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '8' 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','اضافة فاتورة مبيعات','13842', '0', '2023-07-27 21:30:52', '8', 'sellbillController.php', 'اضافة فاتورة مبيعات', '300', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 15367;
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 ('290','01388', '13842', '1', '1388', '1', '300', '300', '0', '', '0', '2023-07-27 21:30:52', '1388', '0.00', '0', '6','0','','','0','0','0','0','0','0','0','0','','15367-1,');
UPDATE sellbilldetail SET  lastbuyprice = 290.00 , meanbuyprice = 290.00, lastbuyprice_withDiscount = 290.00, meanbuyprice_withDiscount = 290.00
                where sellbilldetailid = 41048;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1388, '2023-07-27', 300, 290, 290
                    , 290, 290, 290, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+300, sellCostBuyPrice =sellCostBuyPrice+290
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+290, sellCostMeanBuyPrice = sellCostMeanBuyPrice+290
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+290, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+290
                            , 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 (6, '2023-07-27', 300, 290, 290
                    , 290, 290, 290, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+300, sellCostBuyPrice =sellCostBuyPrice+290
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+290, sellCostMeanBuyPrice = sellCostMeanBuyPrice+290
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+290, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+290
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '28', userid = '8', storedetaildate = '2023-07-27 21:30:52' WHERE storedetailid = '5131';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1388', '6', '1', '1', '13842', 'اضافة فاتورة مبيعات', 'sellbillController.php', '29.00', '28', '8', '2023-07-27 21:30:52','0','0');
UPDATE save SET  savecurrentvalue = '22062',  userid = '8' WHERE saveid = '6';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('21762.00','300', '0', '6', 'اضافة فاتورة مبيعات', '13842', '22062', '2023-07-27 21:30:52', '8',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2023-07-27', 300, 290, 290
                    , 290, 290, 290, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+300, sellCostBuyPrice =sellCostBuyPrice+290
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+290, sellCostMeanBuyPrice = sellCostMeanBuyPrice+290
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+290, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+290
                            , 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-07-27', 300, 290, 290
                    , 290, 290, 290, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+300, sellCostBuyPrice =sellCostBuyPrice+290
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+290, sellCostMeanBuyPrice = sellCostMeanBuyPrice+290
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+290, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+290
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, 300, 290, 290
                    , 290, 290, 290, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+300, netSellCostBuyPrice = netSellCostBuyPrice+290
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+290
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+290
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+290
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+290
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 064c2b7c232b02 and sellbillId = 13842 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 18:00:53";
UPDATE user SET loginip = "197.63.215.180", lastactivetime = "2023-07-27 21:30:53", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 21:30:53', '8', 'addsellBill', '197.63.215.180', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 18:32:41";
UPDATE user SET loginip = "154.183.61.8", lastactivetime = "2023-07-27 22:02:41", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 22:02:41', '8', 'addsellBill', '154.183.61.8', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 18:35:39";
UPDATE user SET loginip = "197.63.196.175", lastactivetime = "2023-07-27 22:05:39", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 22:05:39', '8', 'addAndRetuen', '197.63.196.175', '', '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 064c2bf51f36da
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(17,@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-07-27 22:02:41', '064c2bf51f36da', '17', '118761.00', '118871', '0', '1', '1610', '1610', '1500', '110', '6', '2023-07-27 22:05:39', '', '8', '0', 'محمد عادل', '6', '1', '3', '0', 'نقدي', '5' ,'0','','','','','-1','0','0','0','0','0','1610','0','','0','0','1500','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '118871', userid = '8' WHERE clientid = '17';
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 ('17','118761.00','110','0','اضافة فاتورة مبيعات','13843', '118871', '2023-07-27 22:05:39', '8', 'sellbillController.php', 'اضافة فاتورة مبيعات', '1610', '0', null, '0', null, null,'', '0','1','1','110','1');
UPDATE client SET  inUse = 0 where clientid = 17;
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+3 where id = 15879;
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 ('340','01437', '13843', '1', '1437', '3', '350', '1050', '0', '', '0', '2023-07-27 22:05:39', '1437', '0.00', '0', '6','0','','','0','0','0','0','0','0','0','0','','15879-3,');
UPDATE sellbilldetail SET  lastbuyprice = 340.00 , meanbuyprice = 340.00, lastbuyprice_withDiscount = 340.00, meanbuyprice_withDiscount = 340.00
                where sellbilldetailid = 41049;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1437, '2023-07-27', 1050, 1020, 1020
                    , 1020, 1020, 1020, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 3, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1050, sellCostBuyPrice =sellCostBuyPrice+1020
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1020, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1020
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1020, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1020
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+3
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (6, '2023-07-27', 1050, 1020, 1020
                    , 1020, 1020, 1020, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1050, sellCostBuyPrice =sellCostBuyPrice+1020
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1020, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1020
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1020, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1020
                            , 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 = '8', storedetaildate = '2023-07-27 22:05:39' WHERE storedetailid = '5297';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1437', '6', '3', '1', '13843', 'اضافة فاتورة مبيعات', 'sellbillController.php', '30.00', '27', '8', '2023-07-27 22:05:39','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 15847;
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','01432', '13843', '1', '1432', '1', '290', '290', '0', '', '0', '2023-07-27 22:05:39', '1432', '0.00', '0', '6','0','','','0','0','0','0','0','0','0','0','','15847-1,');
UPDATE sellbilldetail SET  lastbuyprice = 280.00 , meanbuyprice = 280.00, lastbuyprice_withDiscount = 280.00, meanbuyprice_withDiscount = 280.00
                where sellbilldetailid = 41050;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1432, '2023-07-27', 290, 280, 280
                    , 280, 280, 280, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+290, sellCostBuyPrice =sellCostBuyPrice+280
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+280, sellCostMeanBuyPrice = sellCostMeanBuyPrice+280
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+280, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+280
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (6, '2023-07-27', 290, 280, 280
                    , 280, 280, 280, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+290, sellCostBuyPrice =sellCostBuyPrice+280
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+280, sellCostMeanBuyPrice = sellCostMeanBuyPrice+280
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+280, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+280
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '37', userid = '8', storedetaildate = '2023-07-27 22:05:39' WHERE storedetailid = '5281';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1432', '6', '1', '1', '13843', 'اضافة فاتورة مبيعات', 'sellbillController.php', '38.00', '37', '8', '2023-07-27 22:05:39','0','0');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 15875;
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 ('260','01435', '13843', '1', '1435', '1', '270', '270', '0', '', '0', '2023-07-27 22:05:39', '1435', '0.00', '0', '6','0','','','0','0','0','0','0','0','0','0','','15875-1,');
UPDATE sellbilldetail SET  lastbuyprice = 260.00 , meanbuyprice = 260.00, lastbuyprice_withDiscount = 260.00, meanbuyprice_withDiscount = 260.00
                where sellbilldetailid = 41051;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1435, '2023-07-27', 270, 260, 260
                    , 260, 260, 260, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+270, sellCostBuyPrice =sellCostBuyPrice+260
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+260, sellCostMeanBuyPrice = sellCostMeanBuyPrice+260
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+260, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+260
                            , 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 (6, '2023-07-27', 270, 260, 260
                    , 260, 260, 260, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+270, sellCostBuyPrice =sellCostBuyPrice+260
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+260, sellCostMeanBuyPrice = sellCostMeanBuyPrice+260
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+260, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+260
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '18', userid = '8', storedetaildate = '2023-07-27 22:05:39' WHERE storedetailid = '5295';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1435', '6', '1', '1', '13843', 'اضافة فاتورة مبيعات', 'sellbillController.php', '19.00', '18', '8', '2023-07-27 22:05:39','0','0');
UPDATE save SET  savecurrentvalue = '23562',  userid = '8' WHERE saveid = '6';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('22062.00','1500', '0', '6', 'اضافة فاتورة مبيعات', '13843', '23562', '2023-07-27 22:05:39', '8',  'sellbillController.php','17','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2023-07-27', 1610, 1560, 1560
                    , 1560, 1560, 1560, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1610, sellCostBuyPrice =sellCostBuyPrice+1560
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1560, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1560
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1560, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1560
                            , 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 (17, '2023-07-27', 1610, 1560, 1560
                    , 1560, 1560, 1560, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+1610, sellCostBuyPrice =sellCostBuyPrice+1560
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+1560, sellCostMeanBuyPrice = sellCostMeanBuyPrice+1560
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+1560, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+1560
                            , 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, 1610, 1560, 1560
                    , 1560, 1560, 1560, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+1610, netSellCostBuyPrice = netSellCostBuyPrice+1560
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+1560
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+1560
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+1560
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+1560
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 064c2bf51f36da and sellbillId = 13843 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 18:35:40";
UPDATE user SET loginip = "197.63.196.175", lastactivetime = "2023-07-27 22:05:40", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2023-07-27 22:05:40', '8', 'addsellBill', '197.63.196.175', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2023-07-27 18:35:44";
UPDATE user SET loginip = "197.63.196.175", lastactivetime = "2023-07-27 22:05:44", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2023-07-27 22:05:45', '8', '', '197.63.196.175', '', 'DESKTOP');
