UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-07 21:16:14";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 00:46:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2024-08-08 00:46:14', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-07 21:17:04";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 00:47:04", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientPayedDeptController.php', '2024-08-08 00:47:04', '1', 'add', '156.210.66.235', '', '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 =26675
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(400,@clientdebt,@clientname);
UPDATE client SET  clientdebt = '91380' , clientdate = '2024-08-08 00:47:05', userid = '1' WHERE clientid = '400';
UPDATE client SET  inUse = 0 where clientid = 400;
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 ('400','96380.00','5000','1','ايصال تحصيل (( قبض من عميل ))','26675', '91380', '2024-08-08 00:46:14', '1', 'clientPayedDeptController.php', '  ليد الشيخ عبد اللطيف
 ', '5000', '0', null, '0', null, null,'', '-1','1','1','1','1');
UPDATE save SET  savecurrentvalue = '644800',  userid = '1' WHERE saveid = '1';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('639800.00','5000', '0', '1', 'ايصال تحصيل (( قبض من عميل ))', '26675', '644800', '2024-08-08 00:47:05', '1',  'clientPayedDeptController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '5000', '5000', '2024-08-08', '1', '0', '0', '2024-08-08 00:47:05','اضافة ايصال سداد للعميل سنتر سامح جمعه','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('10813', '54', '5000', '','0');
UPDATE accountstree SET name = 'الخزنة الرئيسية', customName = 'الخزنة الرئيسية', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2018-04-21', itemtype2 = '1', theValue = '452519', theOrder = '0', layingOrder = '1221',reportid = '2' WHERE id = '54';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('10813', '471', '5000', '','0');
UPDATE accountstree SET name = 'سنتر سامح جمعه', customName = 'سنتر سامح جمعه', parent = '23', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2024-03-07', itemtype2 = '1', theValue = '-26355', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '471';
UPDATE clientdebtchange SET clientid = '400', clientdebtchangebefore = '96380.00', clientdebtchangeamount = '5000.00', clientdebtchangetype = '1', processname = 'ايصال تحصيل (( قبض من عميل ))', clientdebtchangemodelid = '26675', clientdebtchangeafter = '91380.00', clientdebtchangedate = '2024-08-08 00:46:14', userid = '1', tablename = 'clientPayedDeptController.php', comment = '  ليد الشيخ عبد اللطيف
 ', totalOperationCost = '5000.00',discount='', reciptid=null, dailyentryid = '10813',seller = '0',currencyId='1',conversionFactor='1',payedInCurrency='1',saveConversionFactor='1' WHERE clientdebtchangeid = '26675';
COMMIT;

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

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

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 07:26:21";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 10:56:22", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2024-08-08 10:56:22', '4', '', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 07:26:24";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 10:56:25", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 10:56:25', '4', 'addsellBill', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 09:17:32";
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 < "2024-08-08 09:17:44";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 12:47:44", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2024-08-08 12:47:44', '7', '', '197.192.201.150', '', '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 < "2024-08-08 09:17:45";
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 < "2024-08-08 09:17:50";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 12:47:50", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 12:47:50', '7', 'addsellBill', '197.192.201.150', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 09:17:57";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 12:47:57", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 12:47:57', '7', '', '197.192.201.150', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 09:18:08";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 12:48:08", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 12:48:08', '7', 'add', '197.192.201.150', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('-1', 'جهاد', '', '30', '2024-08-08', '7', '0','-1','5','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '12695',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('12725.00','30', '1', '5', 'إضافة مصروف', '5292', '12695', '2024-08-08 12:48:09', '7',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '30', '30', '2024-08-08', '7', '0', '0', '2024-08-08 12:48:09','اضافة اسم مصروف( جهاد )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('10814', '160', '30', '','0');
UPDATE accountstree SET name = '', customName = '', parent = '10', itemtype = '1', itemfrom = '0', notes = '', del = '1', userid = '1', mydate = '2021-12-01', itemtype2 = '1', theValue = '-4608040', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '160';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('10814', '139', '30', '','0');
UPDATE accountstree SET name = 'خزينة محل عبدالله', customName = 'خزينة محل عبدالله', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2022-07-06', itemtype2 = '1', theValue = '-3338743', theOrder = '0', layingOrder = '',reportid = '0' WHERE id = '139';
UPDATE expenses SET expensestypeid = '-1', expensesname = 'جهاد', expensesdetails = '', expensesValue = '30.00', expensesdate = '2024-08-08', userid = '7', conditions = '0',saveid = '5' , dailyentryid = '10814', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '5292';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 09:18:09";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 12:48:09", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 12:48:10', '7', 'sucess', '197.192.201.150', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 09:18:12";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 12:48:12", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 12:48:12', '7', 'show', '197.192.201.150', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 09:25:27";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 12:55:27", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 12:55:27', '7', 'addsellBill', '197.192.201.150', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 09:28:50";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 12:58:50", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2024-08-08 12:58:50', '4', '', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 09:28:52";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 12:58:52", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 12:58:53', '4', '', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 09:29:16";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 12:59:16", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 12:59:16', '4', 'add', '197.35.195.208', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('-1', 'شحن بضاعه', '', '25', '2024-08-08', '4', '0','-1','7','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '6655',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('6680.00','25', '1', '7', 'إضافة مصروف', '5293', '6655', '2024-08-08 12:59:16', '4',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '25', '25', '2024-08-08', '4', '0', '0', '2024-08-08 12:59:16','اضافة اسم مصروف( شحن بضاعه )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('10815', '160', '25', '','0');
UPDATE accountstree SET name = '', customName = '', parent = '10', itemtype = '1', itemfrom = '0', notes = '', del = '1', userid = '1', mydate = '2021-12-01', itemtype2 = '1', theValue = '-4608065', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '160';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('10815', '141', '25', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-2222922', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE expenses SET expensestypeid = '-1', expensesname = 'شحن بضاعه', expensesdetails = '', expensesValue = '25.00', expensesdate = '2024-08-08', userid = '4', conditions = '0',saveid = '7' , dailyentryid = '10815', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '5293';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 09:29:17";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 12:59:17", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 12:59:17', '4', 'sucess', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 09:29:18";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 12:59:19", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 12:59:19', '4', 'show', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 09:29:20";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 12:59:20", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2024-08-08 12:59:20', '4', '', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 09:29:27";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 12:59:27", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 12:59:27', '4', 'addsellBill', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE userid = 7;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 10:34:13";
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 < "2024-08-08 10:34:26";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 14:04:26", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2024-08-08 14:04:27', '7', '', '197.192.201.150', '', '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 < "2024-08-08 10:34:27";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 10:34:32";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 14:04:32", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 14:04:32', '7', '', '197.192.201.150', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 10:36:07";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 14:06:07", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 14:06:07', '7', 'addsellBill', '197.192.201.150', '', '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 < "2024-08-08 10:42:41";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:12:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2024-08-08 14:12:41', '1', '', '156.210.66.235', '', '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 < "2024-08-08 10:42:41";
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 < "2024-08-08 11:00:42";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:30:42", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2024-08-08 14:30:43', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:00:43";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:30:43", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2024-08-08 14:30:43', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:02:04";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:32:04", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2024-08-08 14:32:04', '1', 'add', '156.210.66.235', '', '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 ('1013فسكوز','','1','400','400', '480','410', '2024-08-08', '0', '1', '0', '', '0', '0', '0', '0', '0', '400','400','400','400','400','0','0','2.5','20','.','0','0','0','0','0','','','0','0','0');
UPDATE product SET productName = '1013فسكوز', productDescription = '', productCatId = '1', productBuyPrice = '400', productSellAllPrice = '400', productSellUnitPrice = '480', productSellHalfPrice = '410', productDate = '2024-08-08', conditions = '0', userId = '1', limitamount = '0', parcode = '01818',type ='0', expireDate = '0' , dailyentryId = '0',isService = '0',isOptic = '0',lastbuyprice = '400',lastbuyprice_withDiscount = '400',meanbuyprice = '400',meanbuyprice_withDiscount = '400' , productbuypricereal = '400' , buypricereal_precentage = '0' , buytotal_precentage = '0' , buyhalf_precentage = '2.5' , buypart_precentage = '20',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1818';
INSERT INTO productunit (unitid, productid, productnumber, productunitdate, userid, conditions,proUnitParcode,proUnitSellAllPrice,proUnitSellHalfPrice,proUnitSellUnitPrice,proUnitBuyPrice) VALUES ('1', '1818', '1', '2024-08-08', '1', '0','0181801','400','410','480','400');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1818', '1', '271', '1', '2024-08-08');
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1818', '1', '271', '0', '1818', 'إضافة منتج', 'productController.php', '0', '271', '1', '2024-08-08','0','0');
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1818, 1,'2024-08-08 14:32:04',1)
                ON DUPLICATE KEY UPDATE productid = 1818, edited = 1, sysdate = '2024-08-08 14:32:04', userid = 1;
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '108400', '108400', '2024-08-08', '1', '0', '0', '2024-08-08 14:32:04','إضافة منتج 1013فسكوز الكمية 271','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('10816', '19', '108400', '','0');
UPDATE accountstree SET name = 'البضاعة (بضاعة أول المدة)', customName = 'البضاعة (بضاعة أول المدة)', parent = '6', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '0', mydate = '0000-00-00', itemtype2 = '1', theValue = '21001620.95', theOrder = '0', layingOrder = '121',reportid = '0' WHERE id = '19';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('10816', '7', '108400', '','0');
UPDATE accountstree SET name = 'رأس المال', customName = 'رأس المال', parent = '25', itemtype = '1', itemfrom = '0', notes = '', del = '0', userid = '2', mydate = '2016-11-23', itemtype2 = '1', theValue = '21759971.75', theOrder = '0', layingOrder = '211',reportid = '0' WHERE id = '7';
UPDATE product SET productName = '1013فسكوز', productDescription = '', productCatId = '1', productBuyPrice = '400.00', productSellAllPrice = '400.00', productSellUnitPrice = '480.00', productSellHalfPrice = '410.00', productDate = '2024-08-08', conditions = '0', userId = '1', limitamount = '0', parcode = '01818',type ='0', expireDate = '0' , dailyentryId = '10816',isService = '0',isOptic = '0',lastbuyprice = '400',lastbuyprice_withDiscount = '400',meanbuyprice = '400',meanbuyprice_withDiscount = '400' , productbuypricereal = '400' , buypricereal_precentage = '0' , buytotal_precentage = '0' , buyhalf_precentage = '2.5' , buypart_precentage = '20',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType =null , online = '' , updatebyuser = ''  WHERE productId = '1818';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:02:06";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:32:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2024-08-08 14:32:06', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:02:13";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:32:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 14:32:13', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:02:51";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:32:51", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 14:32:51', '1', 'add', '156.210.66.235', '', '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(2195,1,5,1818,78,'2024-08-08',1,0, '' ,0,0,0,0,0,'2024-08-08 14:32:52',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '193', userid = '1', storedetaildate = '2024-08-08' WHERE storedetailid = '6514';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2024-08-08', 1, 1818, 0, 0
                    , 400.00, -78, 0, 0, 1, '2024-08-08 14:32:52')
                ON DUPLICATE KEY UPDATE buyprice = 400.00,
                        buyQuantity =buyQuantity+-78, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2024-08-08 14:32:52' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "78*2024-08-08*400.00," WHERE transferproductid = 9083;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1818', '1', '78', '1', '9083', 'تحويل منتجات من المخزن', 'storemovementController.php', '271.00', '193', '1', '2024-08-08','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1818', '5', '78', '1', '2024-08-08');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2024-08-08', 5, 1818, 0, 0
                    , 400.00, 78, 0, 0, 1, '2024-08-08 14:32:52')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+78, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2024-08-08 14:32:52' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1818', '5', '78', '0', '9083', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '78', '1', '2024-08-08','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:02:53";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:32:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 14:32:54', '1', 'editshow', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:03:59";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:33:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 14:34:00', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:04:45";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:34:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 14:34:45', '1', 'add', '156.210.66.235', '', '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(2196,5,6,1789,4,'2024-08-08',1,0, '' ,0,0,0,0,0,'2024-08-08 14:34:45',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '0', userid = '1', storedetaildate = '2024-08-08' WHERE storedetailid = '6427';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2024-08-08', 5, 1789, 0, 0
                    , 330.00, -4, 0, 0, 1, '2024-08-08 14:34:46')
                ON DUPLICATE KEY UPDATE buyprice = 330.00,
                        buyQuantity =buyQuantity+-4, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2024-08-08 14:34:46' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "4*2024-08-08*330.00," WHERE transferproductid = 9084;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1789', '5', '4', '1', '9084', 'تحويل منتجات من المخزن', 'storemovementController.php', '4.00', '0', '1', '2024-08-08','0','0');
UPDATE storedetail SET  productquantity = '6', userid = '1', storedetaildate = '2024-08-08' WHERE storedetailid = '6478';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2024-08-08', 6, 1789, 0, 0
                    , 330.00, 4, 0, 0, 1, '2024-08-08 14:34:46')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+4, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2024-08-08 14:34:46' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1789', '6', '4', '0', '9084', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '2.00', '6', '1', '2024-08-08','0','0');
INSERT INTO storemovement (storeidfrom, storeidto, productid, transferproductamount, transferproductdate, userid, conditions ,operationnum,driverid,drivertimeout,driverdate,delivererid,deliverdate,storetype,priceType,price,sizeid,colorid) VALUES ('5', '6', '1779', '8', '2024-08-08', '1', '0','2196',null,null,'2024-08-08 14:34:46',null,'','0','hide','0','0','0');
UPDATE storedetail SET  productquantity = '1', userid = '1', storedetaildate = '2024-08-08' WHERE storedetailid = '6428';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2024-06-11', 5, 1779, 0, 0
                    , 350.00, 6, 0, 0, 1, '2024-08-08 14:34:46')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity-6, sellQuantity = sellQuantity-0,
                        del = 0,userid = 1,sysDate = '2024-08-08 14:34:46' ;
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2024-08-08', 5, 1779, 0, 0
                    , 350.00, -2, 0, 0, 1, '2024-08-08 14:34:46')
                ON DUPLICATE KEY UPDATE buyprice = 350.00,
                        buyQuantity =buyQuantity+-2, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2024-08-08 14:34:46' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "6*2024-06-11*350.00,2*2024-08-08*350.00," WHERE transferproductid = 9085;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1779', '5', '8', '1', '9085', 'تحويل منتجات من المخزن', 'storemovementController.php', '9.00', '1', '1', '2024-08-08','0','0');
UPDATE storedetail SET  productquantity = '9', userid = '1', storedetaildate = '2024-08-08' WHERE storedetailid = '6479';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2024-06-11', 6, 1779, 0, 0
                    , 350.00, 6, 0, 0, 1, '2024-08-08 14:34:46')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+6, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2024-08-08 14:34:46' ;
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2024-08-08', 6, 1779, 0, 0
                    , 350.00, 2, 0, 0, 1, '2024-08-08 14:34:46')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+2, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2024-08-08 14:34:46' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1779', '6', '8', '0', '9085', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '1.00', '9', '1', '2024-08-08','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:04:46";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:34:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 14:34:47', '1', 'editshow', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:05:29";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:35:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 14:35:29', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:06:12";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:36:12", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 14:36:12', '1', 'add', '156.210.66.235', '', '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(2197,1,6,1818,78,'2024-08-08',1,0, '' ,0,0,0,0,0,'2024-08-08 14:36:12',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '115', userid = '1', storedetaildate = '2024-08-08' WHERE storedetailid = '6514';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2024-08-08', 1, 1818, 0, 0
                    , 400.00, -78, 0, 0, 1, '2024-08-08 14:36:13')
                ON DUPLICATE KEY UPDATE buyprice = 400.00,
                        buyQuantity =buyQuantity+-78, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2024-08-08 14:36:13' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "78*2024-08-08*400.00," WHERE transferproductid = 9086;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1818', '1', '78', '1', '9086', 'تحويل منتجات من المخزن', 'storemovementController.php', '193.00', '115', '1', '2024-08-08','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1818', '6', '78', '1', '2024-08-08');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2024-08-08', 6, 1818, 0, 0
                    , 400.00, 78, 0, 0, 1, '2024-08-08 14:36:13')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+78, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2024-08-08 14:36:13' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1818', '6', '78', '0', '9086', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '78', '1', '2024-08-08','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:06:13";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:36:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 14:36:13', '1', 'editshow', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:06:46";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:36:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 14:36:46', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:07:03";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:37:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 14:37:03', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:07:19";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:37:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 14:37:19', '1', 'add', '156.210.66.235', '', '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(2198,1,8,1818,89,'2024-08-08',1,0, '' ,0,0,0,0,0,'2024-08-08 14:37:19',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '26', userid = '1', storedetaildate = '2024-08-08' WHERE storedetailid = '6514';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2024-08-08', 1, 1818, 0, 0
                    , 400.00, -89, 0, 0, 1, '2024-08-08 14:37:20')
                ON DUPLICATE KEY UPDATE buyprice = 400.00,
                        buyQuantity =buyQuantity+-89, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2024-08-08 14:37:20' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "89*2024-08-08*400.00," WHERE transferproductid = 9087;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1818', '1', '89', '1', '9087', 'تحويل منتجات من المخزن', 'storemovementController.php', '115.00', '26', '1', '2024-08-08','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1818', '8', '89', '1', '2024-08-08');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2024-08-08', 8, 1818, 0, 0
                    , 400.00, 89, 0, 0, 1, '2024-08-08 14:37:20')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+89, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2024-08-08 14:37:20' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1818', '8', '89', '0', '9087', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '89', '1', '2024-08-08','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:07:20";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:37:20", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 14:37:20', '1', 'editshow', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:11:36";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:41:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 14:41:36', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:13:13";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:43:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2024-08-08 14:43:14', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:15:01";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:45:01", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2024-08-08 14:45:01', '1', 'add', '156.210.66.235', '', 'DESKTOP');
UPDATE storedetail SET  productquantity = '126', userid = '1', storedetaildate = '2024-08-08' WHERE storedetailid = '6514';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1818', '1', '100', '0', '-1', 'تم إعادة جرد المنتج بالقيمة الحالية بالزيادة', 'inventoryController.php', '26.00', '126', '1', '2024-08-08','0','0');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:15:04";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:45:04", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('inventoryController.php', '2024-08-08 14:45:04', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:15:05";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:45:05", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 14:45:05', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:15:30";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:45:31", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 14:45:31', '1', 'add', '156.210.66.235', '', '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(2199,1,7,1818,90,'2024-08-08',1,0, '' ,0,0,0,0,0,'2024-08-08 14:45:31',0,'',@id,@optnum);
UPDATE storedetail SET  productquantity = '36', userid = '1', storedetaildate = '2024-08-08' WHERE storedetailid = '6514';
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2024-08-08', 1, 1818, 0, 0
                    , 400.00, -90, 0, 0, 1, '2024-08-08 14:45:31')
                ON DUPLICATE KEY UPDATE buyprice = 400.00,
                        buyQuantity =buyQuantity+-90, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2024-08-08 14:45:31' ;
UPDATE storemovement SET  buyPricesHistoryBookData = "90*2024-08-08*400.00," WHERE transferproductid = 9088;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1818', '1', '90', '1', '9088', 'تحويل منتجات من المخزن', 'storemovementController.php', '126.00', '36', '1', '2024-08-08','0','0');
INSERT INTO storedetail (productid, storeid, productquantity, userid, storedetaildate) VALUES ('1818', '7', '90', '1', '2024-08-08');
INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('2024-08-08', 7, 1818, 0, 0
                    , 400.00, 90, 0, 0, 1, '2024-08-08 14:45:31')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+90, sellQuantity = sellQuantity+0,
                        del = 0,userid = 1,sysDate = '2024-08-08 14:45:31' ;
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1818', '7', '90', '0', '9088', 'تحويل منتجات إلى المخزن', 'storemovementController.php', '0', '90', '1', '2024-08-08','0','0');
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:15:32";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:45:32", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 14:45:32', '1', 'editshow', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:16:18";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 14:46:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 14:46:19', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:44:40";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:14:40", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('storemovementController.php', '2024-08-08 15:14:41', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:44:48";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:14:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 15:14:49', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:51:48";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:21:48", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 15:21:48', '1', 'addAndRetuen', '156.210.66.235', '', '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 066b4b6b99d12e
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(400,@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 ('2024-08-08 15:14:49', '066b4b6b99d12e', '400', '91380.00', '131220', '0', '1', '39840', '39840', '0', '39840', '1', '2024-08-08 15:21:49', '', '1', '0', 'سنتر سامح جمعه', '1', '1', '3', '0', 'سنتر سامح جمعه', '48' ,'0','','','','','-1','0','0','0','0','0','39840','0','','0','0','0','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '131220', userid = '1' WHERE clientid = '400';
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 ('400','91380.00','39840','0','اضافة فاتورة مبيعات','18008', '131220', '2024-08-08 15:21:49', '1', 'sellbillController.php', 'اضافة فاتورة مبيعات', '39840', '0', null, '0', null, null,'', '0','1','1','39840','1');
UPDATE client SET  inUse = 0 where clientid = 400;
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 ('830','01812', '18008', '1', '1812', '12', '830.00', '9960', '0', '', '0', '2024-08-08 15:21:49', '1812', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53276;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1812, '2024-08-08', 9960, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 12, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+9960, sellCostBuyPrice =sellCostBuyPrice+9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice+9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+9960
                            , 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+12
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 9960, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+9960, sellCostBuyPrice =sellCostBuyPrice+9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice+9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+9960
                            , 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 = '-36', userid = '1', storedetaildate = '2024-08-08 15:21:49' WHERE storedetailid = '6499';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1812', '1', '12', '1', '18008', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-24.00', '-36', '1', '2024-08-08 15:21:49','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 ('830','01814', '18008', '1', '1814', '12', '830', '9960', '0', '', '0', '2024-08-08 15:21:49', '1814', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53277;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1814, '2024-08-08', 9960, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 12, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+9960, sellCostBuyPrice =sellCostBuyPrice+9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice+9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+9960
                            , 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+12
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 9960, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+9960, sellCostBuyPrice =sellCostBuyPrice+9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice+9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+9960
                            , 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 = '1', storedetaildate = '2024-08-08 15:21:49' WHERE storedetailid = '6502';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1814', '1', '12', '1', '18008', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-12.00', '-24', '1', '2024-08-08 15:21:49','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 ('830','01813', '18008', '1', '1813', '12', '830', '9960', '0', '', '0', '2024-08-08 15:21:49', '1813', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53278;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1813, '2024-08-08', 9960, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 12, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+9960, sellCostBuyPrice =sellCostBuyPrice+9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice+9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+9960
                            , 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+12
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 9960, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+9960, sellCostBuyPrice =sellCostBuyPrice+9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice+9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+9960
                            , 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 = '-36', userid = '1', storedetaildate = '2024-08-08 15:21:49' WHERE storedetailid = '6500';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1813', '1', '12', '1', '18008', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-24.00', '-36', '1', '2024-08-08 15:21:49','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 ('830','01815', '18008', '1', '1815', '12', '830', '9960', '0', '', '0', '2024-08-08 15:21:49', '1815', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53279;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1815, '2024-08-08', 9960, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 12, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+9960, sellCostBuyPrice =sellCostBuyPrice+9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice+9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+9960
                            , 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+12
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 9960, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+9960, sellCostBuyPrice =sellCostBuyPrice+9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice+9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+9960
                            , 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 = '1', storedetaildate = '2024-08-08 15:21:49' WHERE storedetailid = '6503';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1815', '1', '12', '1', '18008', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-12.00', '-24', '1', '2024-08-08 15:21:49','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2024-08-08', 39840, 39840, 39840
                    , 39840, 39840, 39840, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+39840, sellCostBuyPrice =sellCostBuyPrice+39840
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+39840, sellCostMeanBuyPrice = sellCostMeanBuyPrice+39840
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+39840, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+39840
                            , 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 (400, '2024-08-08', 39840, 39840, 39840
                    , 39840, 39840, 39840, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+39840, sellCostBuyPrice =sellCostBuyPrice+39840
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+39840, sellCostMeanBuyPrice = sellCostMeanBuyPrice+39840
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+39840, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+39840
                            , 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, 39840, 39840, 39840
                    , 39840, 39840, 39840, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+39840, netSellCostBuyPrice = netSellCostBuyPrice+39840
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+39840
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+39840
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+39840
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+39840
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 066b4b6b99d12e and sellbillId = 18008 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:51:51";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:21:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 15:21:52', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 11:59:28";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:29:28", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 15:29:28', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:09:05";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:39:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2024-08-08 15:39:06', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:09:16";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:39:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2024-08-08 15:39:16', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE product SET productName = '1013فسكوز', productDescription = '', productCatId = '1', productBuyPrice = '380', productSellAllPrice = '400.00', productSellUnitPrice = '480.00', productSellHalfPrice = '410.00', productDate = '2024-08-08', conditions = '0', userId = '1', limitamount = '0', parcode = '01818',type ='0', expireDate = '0' , dailyentryId = '10816',isService = '0',isOptic = '0',lastbuyprice = '400.00',lastbuyprice_withDiscount = '400',meanbuyprice = '390',meanbuyprice_withDiscount = '390' , productbuypricereal = '400.00' , buypricereal_precentage = '0.00' , buytotal_precentage = '0.00' , buyhalf_precentage = '2.50' , buypart_precentage = '20.00',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1818';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1818, 1,'2024-08-08 15:39:25',1)
                ON DUPLICATE KEY UPDATE productid = 1818, edited = 1, sysdate = '2024-08-08 15:39:25', userid = 1;
UPDATE product SET productName = '1013فسكوز', productDescription = '', productCatId = '1', productBuyPrice = '380.00', productSellAllPrice = '380', productSellUnitPrice = '380', productSellHalfPrice = '380', productDate = '2024-08-08', conditions = '0', userId = '1', limitamount = '0', parcode = '01818',type ='0', expireDate = '0' , dailyentryId = '10816',isService = '0',isOptic = '0',lastbuyprice = '400.00',lastbuyprice_withDiscount = '400',meanbuyprice = '390.00',meanbuyprice_withDiscount = '390' , productbuypricereal = '400.00' , buypricereal_precentage = '0.00' , buytotal_precentage = '0.00' , buyhalf_precentage = '2.50' , buypart_precentage = '20.00',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1818';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1818, 1,'2024-08-08 15:39:29',1)
                ON DUPLICATE KEY UPDATE productid = 1818, edited = 1, sysdate = '2024-08-08 15:39:29', userid = 1;
UPDATE product SET productName = '1013فسكوز', productDescription = '', productCatId = '1', productBuyPrice = '380.00', productSellAllPrice = '380.00', productSellUnitPrice = '380.00', productSellHalfPrice = '390', productDate = '2024-08-08', conditions = '0', userId = '1', limitamount = '0', parcode = '01818',type ='0', expireDate = '0' , dailyentryId = '10816',isService = '0',isOptic = '0',lastbuyprice = '400.00',lastbuyprice_withDiscount = '400',meanbuyprice = '390.00',meanbuyprice_withDiscount = '390' , productbuypricereal = '400.00' , buypricereal_precentage = '0.00' , buytotal_precentage = '0.00' , buyhalf_precentage = '2.50' , buypart_precentage = '20.00',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1818';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1818, 1,'2024-08-08 15:39:33',1)
                ON DUPLICATE KEY UPDATE productid = 1818, edited = 1, sysdate = '2024-08-08 15:39:33', userid = 1;
UPDATE product SET productName = '1013فسكوز', productDescription = '', productCatId = '1', productBuyPrice = '380.00', productSellAllPrice = '380.00', productSellUnitPrice = '460', productSellHalfPrice = '390.00', productDate = '2024-08-08', conditions = '0', userId = '1', limitamount = '0', parcode = '01818',type ='0', expireDate = '0' , dailyentryId = '10816',isService = '0',isOptic = '0',lastbuyprice = '400.00',lastbuyprice_withDiscount = '400',meanbuyprice = '390.00',meanbuyprice_withDiscount = '390' , productbuypricereal = '400.00' , buypricereal_precentage = '0.00' , buytotal_precentage = '0.00' , buyhalf_precentage = '2.50' , buypart_precentage = '20.00',logo = '.',inMenu='0', obygyDetectionId = '0',hasSizeAndColor = '0',logo1 = '',logo2 = '',logo3 = '',logo4 = '',logo5 = '',logo6 = '',logo7 = '',reviewType ='0' , online = '' , updatebyuser = '0'  WHERE productId = '1818';
INSERT INTO onlinetempproduct (productid, edited, sysdate, userid)
                VALUES (1818, 1,'2024-08-08 15:39:45',1)
                ON DUPLICATE KEY UPDATE productid = 1818, edited = 1, sysdate = '2024-08-08 15:39:45', userid = 1;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:10:15";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:40:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 15:40:15', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:12:01";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:42:01", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 15:42:01', '1', 'all', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:12:10";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:42:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 15:42:10', '1', 'all', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:13:51";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:43:51", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 15:43:51', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:13:51";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:43:51", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 15:43:52', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:16:25";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:46:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 15:46:25', '1', 'add', '156.210.66.235', '', 'DESKTOP');
INSERT INTO client (clientname, clientaddress, clientphone, clientmobile, clientdebt, clientdetails, conditions, clientdate, userid,clientareaid,clientcode,dailyentryid ,rondomtxt,clientStoreIds,obygyPatientId,debtLimit,typeclientid,priceTypeId,card_number,file_faida,specialDiscount,specialDiscountVal,file,addDate,mandobCollectRatio,webApiId,clientRFID,linkedSupplierId,postponeDays,studentid) VALUES ('سنتر ابو عبداللة(المحلة)' , '', '', '01010079399', '0', '', '0', '2024-08-08 15:46:25', '1', '0','','0','','-10','0','10000',',-20,','-1','0','','0','0','.','2024-08-08','0','0','','0','0','0');
INSERT INTO tamweenclientdetail (clientid, noOfPersonsTamween, noOfPersonsDa3m, cardNum, cardPassword) VALUES ('424', '0', '0', '', '');
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('424','0','0','0','إضافة عميل جديد','424', '0', '2024-08-08 15:46:25', '0', 'clientController.php', '', '0', '0', null, '0', null, null,'', '0','1','1','0','1');
INSERT INTO accountstree (name, customName, parent, itemtype, itemfrom, notes, del, userid, mydate, itemtype2, theValue, theOrder, layingOrder,reportid) VALUES ('سنتر ابو عبداللة(المحلة)', 'سنتر ابو عبداللة(المحلة)', '23', '3', '0', '', '0', '1', '2024-08-08', '1', '0', '0', '','2');
UPDATE client SET clientname = 'سنتر ابو عبداللة(المحلة)', clientaddress = '', clientphone = '', clientmobile = '01010079399', clientdebt = '0.00', clientdetails = '', conditions = '0', clientdate = '2024-08-08', userid = '1'  , clientareaid = '0'  ,clientcode = '',dailyentryid = '0' , rondomtxt = '',clientStoreIds = '-10', obygyPatientId = '0' , debtLimit='10000' , typeclientid=',-20,',priceTypeId='-1',lastEditUser = '0',card_number = '0',file_faida = '',specialDiscount = '0',specialDiscountVal = '0',file = '.',mandobCollectRatio='0',clientRFID = '',linkedSupplierId = '0',postponeDays='0', studentid='0' WHERE clientid = '424';
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:16:26";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:46:26", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 15:46:26', '1', 'sucess', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:16:28";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:46:28", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 15:46:28', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:16:45";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:46:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 15:46:45', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:20:46";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:50:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 15:50:46', '1', 'addAndRetuen', '156.210.66.235', '', '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 066b4be35b6c01
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(424,@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 ('2024-08-08 15:46:45', '066b4be35b6c01', '424', '0.00', '33680', '0', '1', '33680', '33680', '0', '33680', '1', '2024-08-08 15:50:46', '', '1', '0', 'سنتر ابو عبداللة(المحلة)', '1', '1', '3', '0', 'سنتر ابو عبداللة(المحلة)', '56' ,'0','','','','','-1','0','0','0','0','0','33680','0','','0','0','0','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '33680', userid = '1' WHERE clientid = '424';
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 ('424','0.00','33680','0','اضافة فاتورة مبيعات','18009', '33680', '2024-08-08 15:50:46', '1', 'sellbillController.php', 'اضافة فاتورة مبيعات', '33680', '0', null, '0', null, null,'', '0','1','1','33680','1');
UPDATE client SET  inUse = 0 where clientid = 424;
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 ('830','01812', '18009', '1', '1812', '6', '830.00', '4980', '0', '', '0', '2024-08-08 15:50:46', '1812', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53280;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1812, '2024-08-08', 4980, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 6, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+4980, sellCostBuyPrice =sellCostBuyPrice+4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4980
                            , 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 (1, '2024-08-08', 4980, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+4980, sellCostBuyPrice =sellCostBuyPrice+4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4980
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '-42', userid = '1', storedetaildate = '2024-08-08 15:50:46' WHERE storedetailid = '6499';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1812', '1', '6', '1', '18009', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-36.00', '-42', '1', '2024-08-08 15:50:46','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 ('830','01814', '18009', '1', '1814', '6', '830', '4980', '0', '', '0', '2024-08-08 15:50:46', '1814', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53281;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1814, '2024-08-08', 4980, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 6, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+4980, sellCostBuyPrice =sellCostBuyPrice+4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4980
                            , 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 (1, '2024-08-08', 4980, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+4980, sellCostBuyPrice =sellCostBuyPrice+4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4980
                            , 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 = '1', storedetaildate = '2024-08-08 15:50:46' WHERE storedetailid = '6502';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1814', '1', '6', '1', '18009', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-24.00', '-30', '1', '2024-08-08 15:50:46','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 ('830','01813', '18009', '1', '1813', '6', '830', '4980', '0', '', '0', '2024-08-08 15:50:46', '1813', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53282;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1813, '2024-08-08', 4980, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 6, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+4980, sellCostBuyPrice =sellCostBuyPrice+4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4980
                            , 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 (1, '2024-08-08', 4980, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+4980, sellCostBuyPrice =sellCostBuyPrice+4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4980
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '-42', userid = '1', storedetaildate = '2024-08-08 15:50:46' WHERE storedetailid = '6500';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1813', '1', '6', '1', '18009', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-36.00', '-42', '1', '2024-08-08 15:50:46','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 ('830','01815', '18009', '1', '1815', '6', '830', '4980', '0', '', '0', '2024-08-08 15:50:46', '1815', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53283;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1815, '2024-08-08', 4980, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 6, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+4980, sellCostBuyPrice =sellCostBuyPrice+4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4980
                            , 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 (1, '2024-08-08', 4980, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+4980, sellCostBuyPrice =sellCostBuyPrice+4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4980
                            , 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 = '1', storedetaildate = '2024-08-08 15:50:46' WHERE storedetailid = '6503';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1815', '1', '6', '1', '18009', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-24.00', '-30', '1', '2024-08-08 15:50:46','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 ('430','01809', '18009', '1', '1809', '16', '430', '6880', '0', '', '0', '2024-08-08 15:50:46', '1809', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 430.00 , meanbuyprice = 430.00, lastbuyprice_withDiscount = 430.00, meanbuyprice_withDiscount = 430.00
                where sellbilldetailid = 53284;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1809, '2024-08-08', 6880, 6880, 6880
                    , 6880, 6880, 6880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 16, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+6880, sellCostBuyPrice =sellCostBuyPrice+6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice+6880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+6880
                            , 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+16
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 6880, 6880, 6880
                    , 6880, 6880, 6880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+6880, sellCostBuyPrice =sellCostBuyPrice+6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice+6880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+6880
                            , 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 = '25', userid = '1', storedetaildate = '2024-08-08 15:50:46' WHERE storedetailid = '6484';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1809', '1', '16', '1', '18009', 'اضافة فاتورة مبيعات', 'sellbillController.php', '41.00', '25', '1', '2024-08-08 15:50:46','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 ('430','01816', '18009', '1', '1816', '16', '430', '6880', '0', '', '0', '2024-08-08 15:50:46', '1816', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 430.00 , meanbuyprice = 215.00, lastbuyprice_withDiscount = 430.00, meanbuyprice_withDiscount = 215.00
                where sellbilldetailid = 53285;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1816, '2024-08-08', 6880, 6880, 6880
                    , 3440, 6880, 3440, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 16, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+6880, sellCostBuyPrice =sellCostBuyPrice+6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice+3440
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+3440
                            , 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+16
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 6880, 6880, 6880
                    , 3440, 6880, 3440, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+6880, sellCostBuyPrice =sellCostBuyPrice+6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice+3440
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+3440
                            , 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 = '227', userid = '1', storedetaildate = '2024-08-08 15:50:46' WHERE storedetailid = '6508';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1816', '1', '16', '1', '18009', 'اضافة فاتورة مبيعات', 'sellbillController.php', '243.00', '227', '1', '2024-08-08 15:50:46','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2024-08-08', 33680, 33680, 33680
                    , 30240, 33680, 30240, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+33680, sellCostBuyPrice =sellCostBuyPrice+33680
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+33680, sellCostMeanBuyPrice = sellCostMeanBuyPrice+30240
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+33680, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+30240
                            , 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 (424, '2024-08-08', 33680, 33680, 33680
                    , 30240, 33680, 30240, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+33680, sellCostBuyPrice =sellCostBuyPrice+33680
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+33680, sellCostMeanBuyPrice = sellCostMeanBuyPrice+30240
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+33680, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+30240
                            , 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, 33680, 33680, 33680
                    , 30240, 33680, 30240, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+33680, netSellCostBuyPrice = netSellCostBuyPrice+33680
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+33680
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+30240
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+33680
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+30240
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 066b4be35b6c01 and sellbillId = 18009 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:20:47";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:50:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 15:50:47', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:26:07";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:56:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 15:56:07', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:29:33";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:59:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 15:59:33', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:29:46";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:59:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 15:59:46', '1', 'delete', '156.210.66.235', '', 'DESKTOP');
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;

-- ----------------------------------------------------------------------------------------------------
-- bill delete start - sellbill with id = 18008
-- ----------------------------------------------------------------------------------------------------

BEGIN;
UPDATE costcenterdetail SET del = 1 WHERE type in( 0) and  modelid = 18008;
UPDATE sellbill SET  sellbillsysdate = '2024-08-08 15:59:47', userid = '1',delbyuserid = '1', conditions = '1'  ,billReservation= 0,billReservationDate='0000-00-00'  WHERE sellbillid = '18008';
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53276;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1812, '2024-08-08', 9960, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0,12,0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-9960, sellCostBuyPrice =sellCostBuyPrice-9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice-9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-9960
                            , 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-12
                        , netQuantityRet = netQuantityRet-0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 9960, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-9960, sellCostBuyPrice =sellCostBuyPrice-9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice-9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-9960
                            , 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 = '1', storedetaildate = '2024-08-08 15:59:47' WHERE storedetailid = '6499';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1812', '1', '12', '0', '18008', 'حذف فاتورة مبيعات', 'sellbillController.php', '-42.00', '-30', '1', '2024-08-08 15:59:47','0','0');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53277;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1814, '2024-08-08', 9960, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0,12,0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-9960, sellCostBuyPrice =sellCostBuyPrice-9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice-9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-9960
                            , 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-12
                        , netQuantityRet = netQuantityRet-0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 9960, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-9960, sellCostBuyPrice =sellCostBuyPrice-9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice-9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-9960
                            , 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 = '1', storedetaildate = '2024-08-08 15:59:47' WHERE storedetailid = '6502';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1814', '1', '12', '0', '18008', 'حذف فاتورة مبيعات', 'sellbillController.php', '-30.00', '-18', '1', '2024-08-08 15:59:47','0','0');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53278;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1813, '2024-08-08', 9960, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0,12,0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-9960, sellCostBuyPrice =sellCostBuyPrice-9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice-9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-9960
                            , 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-12
                        , netQuantityRet = netQuantityRet-0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 9960, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-9960, sellCostBuyPrice =sellCostBuyPrice-9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice-9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-9960
                            , 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 = '1', storedetaildate = '2024-08-08 15:59:47' WHERE storedetailid = '6500';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1813', '1', '12', '0', '18008', 'حذف فاتورة مبيعات', 'sellbillController.php', '-42.00', '-30', '1', '2024-08-08 15:59:47','0','0');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53279;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1815, '2024-08-08', 9960, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0,12,0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-9960, sellCostBuyPrice =sellCostBuyPrice-9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice-9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-9960
                            , 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-12
                        , netQuantityRet = netQuantityRet-0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 9960, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-9960, sellCostBuyPrice =sellCostBuyPrice-9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice-9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-9960
                            , 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 = '1', storedetaildate = '2024-08-08 15:59:47' WHERE storedetailid = '6503';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1815', '1', '12', '0', '18008', 'حذف فاتورة مبيعات', 'sellbillController.php', '-30.00', '-18', '1', '2024-08-08 15:59:47','0','0');
CALL clientInUse(400,@clientdebt,@clientname);
UPDATE client SET  clientdebt = '91380', userid = '1' WHERE clientid = '400';
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 ('400','131220.00','39840.00','1','حذف فاتورة مبيعات','18008', '91380', '2024-08-08 15:59:47', '1', 'sellbillController.php', 'حذف فاتورة مبيعات', '39840', '0', null, '0', null, null,'', '0','1','1','39840','1');
UPDATE client SET  inUse = 0 where clientid = 400;
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2024-08-08', 39840, 39840, 39840
                    , 39840, 39840, 39840, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-39840, sellCostBuyPrice =sellCostBuyPrice-39840
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-39840, sellCostMeanBuyPrice = sellCostMeanBuyPrice-39840
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-39840, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-39840
                            , 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 (400, '2024-08-08', 39840, 39840, 39840
                    , 39840, 39840, 39840, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-39840, sellCostBuyPrice =sellCostBuyPrice-39840
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-39840, sellCostMeanBuyPrice = sellCostMeanBuyPrice-39840
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-39840, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-39840
                            , 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, 39840, 39840, 39840
                    , 39840, 39840, 39840, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal-39840, netSellCostBuyPrice = netSellCostBuyPrice-39840
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice-39840
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice-39840
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount-39840
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount-39840
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice-0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill delete end - sellbill with id = 18008
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:29:47";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:59:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 15:59:47', '1', 'sucess', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:29:49";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:59:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 15:59:49', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:29:52";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:59:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 15:59:52', '1', 'all', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:29:56";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 15:59:56", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 15:59:56', '1', 'all', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:30:11";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:00:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 16:00:11', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:31:19";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:01:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 16:01:19', '1', 'add', '156.210.66.235', '', 'DESKTOP');
INSERT INTO client (clientname, clientaddress, clientphone, clientmobile, clientdebt, clientdetails, conditions, clientdate, userid,clientareaid,clientcode,dailyentryid ,rondomtxt,clientStoreIds,obygyPatientId,debtLimit,typeclientid,priceTypeId,card_number,file_faida,specialDiscount,specialDiscountVal,file,addDate,mandobCollectRatio,webApiId,clientRFID,linkedSupplierId,postponeDays,studentid) VALUES ('سامح جمعة قمرايا فاشون' , '', '', '01092800511', '0', '', '0', '2024-08-08 16:01:20', '1', '0','','0','','-10','0','10000',',-20,','-1','0','','0','0','.','2024-08-08','0','0','','0','0','0');
INSERT INTO tamweenclientdetail (clientid, noOfPersonsTamween, noOfPersonsDa3m, cardNum, cardPassword) VALUES ('425', '0', '0', '', '');
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('425','0','0','0','إضافة عميل جديد','425', '0', '2024-08-08 16:01:20', '0', 'clientController.php', '', '0', '0', null, '0', null, null,'', '0','1','1','0','1');
INSERT INTO accountstree (name, customName, parent, itemtype, itemfrom, notes, del, userid, mydate, itemtype2, theValue, theOrder, layingOrder,reportid) VALUES ('سامح جمعة قمرايا فاشون', 'سامح جمعة قمرايا فاشون', '23', '3', '0', '', '0', '1', '2024-08-08', '1', '0', '0', '','2');
UPDATE client SET clientname = 'سامح جمعة قمرايا فاشون', clientaddress = '', clientphone = '', clientmobile = '01092800511', clientdebt = '0.00', clientdetails = '', conditions = '0', clientdate = '2024-08-08', userid = '1'  , clientareaid = '0'  ,clientcode = '',dailyentryid = '0' , rondomtxt = '',clientStoreIds = '-10', obygyPatientId = '0' , debtLimit='10000' , typeclientid=',-20,',priceTypeId='-1',lastEditUser = '0',card_number = '0',file_faida = '',specialDiscount = '0',specialDiscountVal = '0',file = '.',mandobCollectRatio='0',clientRFID = '',linkedSupplierId = '0',postponeDays='0', studentid='0' WHERE clientid = '425';
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:31:21";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:01:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 16:01:21', '1', 'sucess', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:31:22";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:01:23", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 16:01:23', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:31:25";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:01:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 16:01:25', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:32:44";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:02:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 16:02:44', '1', 'addAndRetuen', '156.210.66.235', '', '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 066b4c1a5914eb
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(425,@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 ('2024-08-08 16:01:25', '066b4c1a5914eb', '425', '0.00', '38400', '1440', '1', '39840', '38400', '0', '38400', '1', '2024-08-08 16:02:44', '', '1', '0', 'سامح جمعة قمرايا فاشون', '1', '1', '3', '0', 'سامح جمعة قمرايا فاشون', '48' ,'0','','','','','-1','0','0','0','0','0','38400','0','','0','0','0','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '38400', userid = '1' WHERE clientid = '425';
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 ('425','0.00','38400','0','اضافة فاتورة مبيعات','18010', '38400', '2024-08-08 16:02:44', '1', 'sellbillController.php', 'اضافة فاتورة مبيعات', '38400', '0', null, '0', null, null,'', '0','1','1','38400','1');
UPDATE client SET  inUse = 0 where clientid = 425;
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 ('830','01812', '18010', '1', '1812', '12', '830', '9960', '0', '', '0', '2024-08-08 16:02:44', '1812', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53286;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1812, '2024-08-08', 9600, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 12, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+9600, sellCostBuyPrice =sellCostBuyPrice+9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice+9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+9960
                            , 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+12
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 9600, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+9600, sellCostBuyPrice =sellCostBuyPrice+9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice+9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+9960
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '-42', userid = '1', storedetaildate = '2024-08-08 16:02:44' WHERE storedetailid = '6499';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1812', '1', '12', '1', '18010', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-30.00', '-42', '1', '2024-08-08 16:02:44','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 ('830','01814', '18010', '1', '1814', '12', '830', '9960', '0', '', '0', '2024-08-08 16:02:44', '1814', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53287;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1814, '2024-08-08', 9600, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 12, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+9600, sellCostBuyPrice =sellCostBuyPrice+9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice+9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+9960
                            , 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+12
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 9600, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+9600, sellCostBuyPrice =sellCostBuyPrice+9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice+9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+9960
                            , 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 = '1', storedetaildate = '2024-08-08 16:02:44' WHERE storedetailid = '6502';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1814', '1', '12', '1', '18010', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-18.00', '-30', '1', '2024-08-08 16:02:44','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 ('830','01813', '18010', '1', '1813', '12', '830', '9960', '0', '', '0', '2024-08-08 16:02:44', '1813', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53288;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1813, '2024-08-08', 9600, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 12, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+9600, sellCostBuyPrice =sellCostBuyPrice+9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice+9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+9960
                            , 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+12
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 9600, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+9600, sellCostBuyPrice =sellCostBuyPrice+9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice+9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+9960
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '-42', userid = '1', storedetaildate = '2024-08-08 16:02:44' WHERE storedetailid = '6500';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1813', '1', '12', '1', '18010', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-30.00', '-42', '1', '2024-08-08 16:02:44','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 ('830','01815', '18010', '1', '1815', '12', '830', '9960', '0', '', '0', '2024-08-08 16:02:44', '1815', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53289;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1815, '2024-08-08', 9600, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 12, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+9600, sellCostBuyPrice =sellCostBuyPrice+9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice+9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+9960
                            , 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+12
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 9600, 9960, 9960
                    , 9960, 9960, 9960, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+9600, sellCostBuyPrice =sellCostBuyPrice+9960
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+9960, sellCostMeanBuyPrice = sellCostMeanBuyPrice+9960
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+9960, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+9960
                            , 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 = '1', storedetaildate = '2024-08-08 16:02:44' WHERE storedetailid = '6503';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1815', '1', '12', '1', '18010', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-18.00', '-30', '1', '2024-08-08 16:02:44','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2024-08-08', 38400, 39840, 39840
                    , 39840, 39840, 39840, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+38400, sellCostBuyPrice =sellCostBuyPrice+39840
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+39840, sellCostMeanBuyPrice = sellCostMeanBuyPrice+39840
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+39840, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+39840
                            , 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 (425, '2024-08-08', 38400, 39840, 39840
                    , 39840, 39840, 39840, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+38400, sellCostBuyPrice =sellCostBuyPrice+39840
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+39840, sellCostMeanBuyPrice = sellCostMeanBuyPrice+39840
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+39840, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+39840
                            , 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, 38400, 39840, 39840
                    , 39840, 39840, 39840, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+38400, netSellCostBuyPrice = netSellCostBuyPrice+39840
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+39840
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+39840
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+39840
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+39840
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 066b4c1a5914eb and sellbillId = 18010 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 12:32:46";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:02:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 16:02:46', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:05:04";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:35:04", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 16:35:04', '1', 'all', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:05:11";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:35:11", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 16:35:11', '1', 'all', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:05:28";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:35:28", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 16:35:28', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:05:47";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:35:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 16:35:48', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:05:53";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:35:53", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 16:35:53', '1', 'delete', '156.210.66.235', '', 'DESKTOP');
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;

-- ----------------------------------------------------------------------------------------------------
-- bill delete start - sellbill with id = 18009
-- ----------------------------------------------------------------------------------------------------

BEGIN;
UPDATE costcenterdetail SET del = 1 WHERE type in( 0) and  modelid = 18009;
UPDATE sellbill SET  sellbillsysdate = '2024-08-08 16:35:53', userid = '1',delbyuserid = '1', conditions = '1'  ,billReservation= 0,billReservationDate='0000-00-00'  WHERE sellbillid = '18009';
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53280;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1812, '2024-08-08', 4980, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0,6,0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-4980, sellCostBuyPrice =sellCostBuyPrice-4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice-4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-4980
                            , 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 (1, '2024-08-08', 4980, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-4980, sellCostBuyPrice =sellCostBuyPrice-4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice-4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-4980
                            , 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 = '-36', userid = '1', storedetaildate = '2024-08-08 16:35:53' WHERE storedetailid = '6499';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1812', '1', '6', '0', '18009', 'حذف فاتورة مبيعات', 'sellbillController.php', '-42.00', '-36', '1', '2024-08-08 16:35:53','0','0');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53281;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1814, '2024-08-08', 4980, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0,6,0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-4980, sellCostBuyPrice =sellCostBuyPrice-4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice-4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-4980
                            , 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 (1, '2024-08-08', 4980, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-4980, sellCostBuyPrice =sellCostBuyPrice-4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice-4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-4980
                            , 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 = '1', storedetaildate = '2024-08-08 16:35:53' WHERE storedetailid = '6502';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1814', '1', '6', '0', '18009', 'حذف فاتورة مبيعات', 'sellbillController.php', '-30.00', '-24', '1', '2024-08-08 16:35:53','0','0');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53282;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1813, '2024-08-08', 4980, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0,6,0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-4980, sellCostBuyPrice =sellCostBuyPrice-4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice-4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-4980
                            , 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 (1, '2024-08-08', 4980, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-4980, sellCostBuyPrice =sellCostBuyPrice-4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice-4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-4980
                            , 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 = '-36', userid = '1', storedetaildate = '2024-08-08 16:35:53' WHERE storedetailid = '6500';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1813', '1', '6', '0', '18009', 'حذف فاتورة مبيعات', 'sellbillController.php', '-42.00', '-36', '1', '2024-08-08 16:35:53','0','0');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53283;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1815, '2024-08-08', 4980, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0,6,0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-4980, sellCostBuyPrice =sellCostBuyPrice-4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice-4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-4980
                            , 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 (1, '2024-08-08', 4980, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-4980, sellCostBuyPrice =sellCostBuyPrice-4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice-4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-4980
                            , 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 = '1', storedetaildate = '2024-08-08 16:35:53' WHERE storedetailid = '6503';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1815', '1', '6', '0', '18009', 'حذف فاتورة مبيعات', 'sellbillController.php', '-30.00', '-24', '1', '2024-08-08 16:35:53','0','0');
UPDATE sellbilldetail SET  lastbuyprice = 430.00 , meanbuyprice = 430.00, lastbuyprice_withDiscount = 430.00, meanbuyprice_withDiscount = 430.00
                where sellbilldetailid = 53284;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1809, '2024-08-08', 6880, 6880, 6880
                    , 6880, 6880, 6880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0,16,0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-6880, sellCostBuyPrice =sellCostBuyPrice-6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice-6880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-6880
                            , 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-16
                        , netQuantityRet = netQuantityRet-0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 6880, 6880, 6880
                    , 6880, 6880, 6880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-6880, sellCostBuyPrice =sellCostBuyPrice-6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice-6880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-6880
                            , 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 = '41', userid = '1', storedetaildate = '2024-08-08 16:35:53' WHERE storedetailid = '6484';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1809', '1', '16', '0', '18009', 'حذف فاتورة مبيعات', 'sellbillController.php', '25.00', '41', '1', '2024-08-08 16:35:53','0','0');
UPDATE sellbilldetail SET  lastbuyprice = 430.00 , meanbuyprice = 215.00, lastbuyprice_withDiscount = 430.00, meanbuyprice_withDiscount = 215.00
                where sellbilldetailid = 53285;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1816, '2024-08-08', 6880, 6880, 6880
                    , 3440, 6880, 3440, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0,16,0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-6880, sellCostBuyPrice =sellCostBuyPrice-6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice-3440
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-3440
                            , 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-16
                        , netQuantityRet = netQuantityRet-0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 6880, 6880, 6880
                    , 3440, 6880, 3440, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-6880, sellCostBuyPrice =sellCostBuyPrice-6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice-3440
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-3440
                            , 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 = '243', userid = '1', storedetaildate = '2024-08-08 16:35:53' WHERE storedetailid = '6508';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1816', '1', '16', '0', '18009', 'حذف فاتورة مبيعات', 'sellbillController.php', '227.00', '243', '1', '2024-08-08 16:35:53','0','0');
CALL clientInUse(424,@clientdebt,@clientname);
UPDATE client SET  clientdebt = '0', userid = '1' WHERE clientid = '424';
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 ('424','33680.00','33680.00','1','حذف فاتورة مبيعات','18009', '0', '2024-08-08 16:35:53', '1', 'sellbillController.php', 'حذف فاتورة مبيعات', '33680', '0', null, '0', null, null,'', '0','1','1','33680','1');
UPDATE client SET  inUse = 0 where clientid = 424;
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2024-08-08', 33680, 33680, 33680
                    , 30240, 33680, 30240, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-33680, sellCostBuyPrice =sellCostBuyPrice-33680
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-33680, sellCostMeanBuyPrice = sellCostMeanBuyPrice-30240
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-33680, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-30240
                            , 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 (424, '2024-08-08', 33680, 33680, 33680
                    , 30240, 33680, 30240, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-33680, sellCostBuyPrice =sellCostBuyPrice-33680
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-33680, sellCostMeanBuyPrice = sellCostMeanBuyPrice-30240
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-33680, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-30240
                            , 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, 33680, 33680, 33680
                    , 30240, 33680, 30240, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal-33680, netSellCostBuyPrice = netSellCostBuyPrice-33680
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice-33680
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice-30240
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount-33680
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount-30240
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice-0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill delete end - sellbill with id = 18009
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:05:54";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:35:54", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 16:35:54', '1', 'sucess', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:05:56";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:35:56", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 16:35:56', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:05:57";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:35:58", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 16:35:58', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:07:19";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:37:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 16:37:19', '1', 'all', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:07:27";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:37:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 16:37:27', '1', 'all', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:07:32";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:37:32", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 16:37:32', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:09:17";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:39:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 16:39:17', '1', 'addAndRetuen', '156.210.66.235', '', '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 066b4ca1c8769c
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(424,@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 ('2024-08-08 16:37:32', '066b4ca1c8769c', '424', '0.00', '19200', '720', '1', '19920', '19200', '0', '19200', '1', '2024-08-08 16:39:17', '', '1', '0', 'سنتر ابو عبداللة(المحلة)', '1', '1', '3', '0', 'سنتر ابو عبداللة(المحلة)', '24' ,'0','','','','','-1','0','0','0','0','0','19200','0','','0','0','0','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '19200', userid = '1' WHERE clientid = '424';
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 ('424','0.00','19200','0','اضافة فاتورة مبيعات','18011', '19200', '2024-08-08 16:39:17', '1', 'sellbillController.php', 'اضافة فاتورة مبيعات', '19200', '0', null, '0', null, null,'', '0','1','1','19200','1');
UPDATE client SET  inUse = 0 where clientid = 424;
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 ('830','01812', '18011', '1', '1812', '6', '830', '4980', '0', '', '0', '2024-08-08 16:39:17', '1812', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53290;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1812, '2024-08-08', 4800, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 6, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+4800, sellCostBuyPrice =sellCostBuyPrice+4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4980
                            , 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 (1, '2024-08-08', 4800, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+4800, sellCostBuyPrice =sellCostBuyPrice+4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4980
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '-42', userid = '1', storedetaildate = '2024-08-08 16:39:17' WHERE storedetailid = '6499';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1812', '1', '6', '1', '18011', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-36.00', '-42', '1', '2024-08-08 16:39:17','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 ('830','01814', '18011', '1', '1814', '6', '830', '4980', '0', '', '0', '2024-08-08 16:39:17', '1814', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53291;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1814, '2024-08-08', 4800, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 6, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+4800, sellCostBuyPrice =sellCostBuyPrice+4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4980
                            , 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 (1, '2024-08-08', 4800, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+4800, sellCostBuyPrice =sellCostBuyPrice+4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4980
                            , 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 = '1', storedetaildate = '2024-08-08 16:39:17' WHERE storedetailid = '6502';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1814', '1', '6', '1', '18011', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-24.00', '-30', '1', '2024-08-08 16:39:17','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 ('830','01813', '18011', '1', '1813', '6', '830', '4980', '0', '', '0', '2024-08-08 16:39:17', '1813', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53292;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1813, '2024-08-08', 4800, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 6, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+4800, sellCostBuyPrice =sellCostBuyPrice+4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4980
                            , 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 (1, '2024-08-08', 4800, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+4800, sellCostBuyPrice =sellCostBuyPrice+4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4980
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '-42', userid = '1', storedetaildate = '2024-08-08 16:39:17' WHERE storedetailid = '6500';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1813', '1', '6', '1', '18011', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-36.00', '-42', '1', '2024-08-08 16:39:17','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 ('830','01815', '18011', '1', '1815', '6', '830', '4980', '0', '', '0', '2024-08-08 16:39:17', '1815', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 830.00 , meanbuyprice = 830.00, lastbuyprice_withDiscount = 830.00, meanbuyprice_withDiscount = 830.00
                where sellbilldetailid = 53293;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1815, '2024-08-08', 4800, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 6, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+4800, sellCostBuyPrice =sellCostBuyPrice+4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4980
                            , 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 (1, '2024-08-08', 4800, 4980, 4980
                    , 4980, 4980, 4980, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+4800, sellCostBuyPrice =sellCostBuyPrice+4980
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+4980, sellCostMeanBuyPrice = sellCostMeanBuyPrice+4980
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+4980, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+4980
                            , 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 = '1', storedetaildate = '2024-08-08 16:39:17' WHERE storedetailid = '6503';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1815', '1', '6', '1', '18011', 'اضافة فاتورة مبيعات', 'sellbillController.php', '-24.00', '-30', '1', '2024-08-08 16:39:17','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2024-08-08', 19200, 19920, 19920
                    , 19920, 19920, 19920, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+19200, sellCostBuyPrice =sellCostBuyPrice+19920
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+19920, sellCostMeanBuyPrice = sellCostMeanBuyPrice+19920
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+19920, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+19920
                            , 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 (424, '2024-08-08', 19200, 19920, 19920
                    , 19920, 19920, 19920, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+19200, sellCostBuyPrice =sellCostBuyPrice+19920
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+19920, sellCostMeanBuyPrice = sellCostMeanBuyPrice+19920
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+19920, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+19920
                            , 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, 19200, 19920, 19920
                    , 19920, 19920, 19920, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+19200, netSellCostBuyPrice = netSellCostBuyPrice+19920
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+19920
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+19920
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+19920
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+19920
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 066b4ca1c8769c and sellbillId = 18011 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:09:19";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:39:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 16:39:19', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:12:25";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:42:25", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 16:42:26', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:13:46";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:43:46", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 16:43:46', '1', 'add', '156.210.66.235', '', 'DESKTOP');
INSERT INTO client (clientname, clientaddress, clientphone, clientmobile, clientdebt, clientdetails, conditions, clientdate, userid,clientareaid,clientcode,dailyentryid ,rondomtxt,clientStoreIds,obygyPatientId,debtLimit,typeclientid,priceTypeId,card_number,file_faida,specialDiscount,specialDiscountVal,file,addDate,mandobCollectRatio,webApiId,clientRFID,linkedSupplierId,postponeDays,studentid) VALUES ('سنترابوعبداللة الوليد' , 'المحلة الكبرى', '01010079399', '', '0', '', '0', '2024-08-08 16:43:46', '1', '0','','0','','-10','0','10000',',-20,','-1','0','','0','0','.','2024-08-08','0','0','','0','0','0');
INSERT INTO tamweenclientdetail (clientid, noOfPersonsTamween, noOfPersonsDa3m, cardNum, cardPassword) VALUES ('426', '0', '0', '', '');
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('426','0','0','0','إضافة عميل جديد','426', '0', '2024-08-08 16:43:46', '0', 'clientController.php', '', '0', '0', null, '0', null, null,'', '0','1','1','0','1');
INSERT INTO accountstree (name, customName, parent, itemtype, itemfrom, notes, del, userid, mydate, itemtype2, theValue, theOrder, layingOrder,reportid) VALUES ('سنترابوعبداللة الوليد', 'سنترابوعبداللة الوليد', '23', '3', '0', '', '0', '1', '2024-08-08', '1', '0', '0', '','2');
UPDATE client SET clientname = 'سنترابوعبداللة الوليد', clientaddress = 'المحلة الكبرى', clientphone = '01010079399', clientmobile = '', clientdebt = '0.00', clientdetails = '', conditions = '0', clientdate = '2024-08-08', userid = '1'  , clientareaid = '0'  ,clientcode = '',dailyentryid = '0' , rondomtxt = '',clientStoreIds = '-10', obygyPatientId = '0' , debtLimit='10000' , typeclientid=',-20,',priceTypeId='-1',lastEditUser = '0',card_number = '0',file_faida = '',specialDiscount = '0',specialDiscountVal = '0',file = '.',mandobCollectRatio='0',clientRFID = '',linkedSupplierId = '0',postponeDays='0', studentid='0' WHERE clientid = '426';
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:13:47";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:43:47", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 16:43:47', '1', 'sucess', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:13:49";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:43:49", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 16:43:49', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:13:58";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:43:58", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 16:43:58', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:14:53";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:44:53", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 16:44:53', '1', 'addAndRetuen', '156.210.66.235', '', '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 066b4cb9ed28ac
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(426,@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 ('2024-08-08 16:43:58', '066b4cb9ed28ac', '426', '0.00', '13760', '0', '1', '13760', '13760', '0', '13760', '1', '2024-08-08 16:44:53', '', '1', '0', 'سنترابوعبداللة الوليد', '1', '1', '3', '0', 'سنترابوعبداللة الوليد', '32' ,'0','','','','','-1','0','0','0','0','0','13760','0','','0','0','0','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '13760', userid = '1' WHERE clientid = '426';
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 ('426','0.00','13760','0','اضافة فاتورة مبيعات','18012', '13760', '2024-08-08 16:44:53', '1', 'sellbillController.php', 'اضافة فاتورة مبيعات', '13760', '0', null, '0', null, null,'', '0','1','1','13760','1');
UPDATE client SET  inUse = 0 where clientid = 426;
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 ('430','01809', '18012', '1', '1809', '16', '430', '6880', '0', '', '0', '2024-08-08 16:44:53', '1809', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 430.00 , meanbuyprice = 430.00, lastbuyprice_withDiscount = 430.00, meanbuyprice_withDiscount = 430.00
                where sellbilldetailid = 53294;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1809, '2024-08-08', 6880, 6880, 6880
                    , 6880, 6880, 6880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 16, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+6880, sellCostBuyPrice =sellCostBuyPrice+6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice+6880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+6880
                            , 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+16
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 6880, 6880, 6880
                    , 6880, 6880, 6880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+6880, sellCostBuyPrice =sellCostBuyPrice+6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice+6880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+6880
                            , 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 = '25', userid = '1', storedetaildate = '2024-08-08 16:44:53' WHERE storedetailid = '6484';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1809', '1', '16', '1', '18012', 'اضافة فاتورة مبيعات', 'sellbillController.php', '41.00', '25', '1', '2024-08-08 16:44:53','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 ('430','01808', '18012', '1', '1808', '16', '430', '6880', '0', '', '0', '2024-08-08 16:44:53', '1808', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 430.00 , meanbuyprice = 430.00, lastbuyprice_withDiscount = 430.00, meanbuyprice_withDiscount = 430.00
                where sellbilldetailid = 53295;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1808, '2024-08-08', 6880, 6880, 6880
                    , 6880, 6880, 6880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 16, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+6880, sellCostBuyPrice =sellCostBuyPrice+6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice+6880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+6880
                            , 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+16
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 6880, 6880, 6880
                    , 6880, 6880, 6880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+6880, sellCostBuyPrice =sellCostBuyPrice+6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice+6880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+6880
                            , 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 = '83', userid = '1', storedetaildate = '2024-08-08 16:44:53' WHERE storedetailid = '6483';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1808', '1', '16', '1', '18012', 'اضافة فاتورة مبيعات', 'sellbillController.php', '99.00', '83', '1', '2024-08-08 16:44:53','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2024-08-08', 13760, 13760, 13760
                    , 13760, 13760, 13760, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+13760, sellCostBuyPrice =sellCostBuyPrice+13760
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+13760, sellCostMeanBuyPrice = sellCostMeanBuyPrice+13760
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+13760, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+13760
                            , 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 (426, '2024-08-08', 13760, 13760, 13760
                    , 13760, 13760, 13760, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+13760, sellCostBuyPrice =sellCostBuyPrice+13760
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+13760, sellCostMeanBuyPrice = sellCostMeanBuyPrice+13760
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+13760, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+13760
                            , 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, 13760, 13760, 13760
                    , 13760, 13760, 13760, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+13760, netSellCostBuyPrice = netSellCostBuyPrice+13760
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+13760
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+13760
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+13760
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+13760
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 066b4cb9ed28ac and sellbillId = 18012 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:14:53";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 16:44:53", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 16:44:54', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:17:12";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 16:47:12", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 16:47:12', '4', '', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:31:19";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 17:01:19", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 17:01:19', '4', 'add', '197.35.195.208', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('-1', 'بكره لزق', '', '40', '2024-08-08', '4', '0','-1','7','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '6615',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('6655.00','40', '1', '7', 'إضافة مصروف', '5294', '6615', '2024-08-08 17:01:19', '4',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '40', '40', '2024-08-08', '4', '0', '0', '2024-08-08 17:01:19','اضافة اسم مصروف( بكره لزق )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('10817', '160', '40', '','0');
UPDATE accountstree SET name = '', customName = '', parent = '10', itemtype = '1', itemfrom = '0', notes = '', del = '1', userid = '1', mydate = '2021-12-01', itemtype2 = '1', theValue = '-4608105', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '160';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('10817', '141', '40', '','0');
UPDATE accountstree SET name = 'خزينة محل العميد', customName = 'خزينة محل العميد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-2222962', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE expenses SET expensestypeid = '-1', expensesname = 'بكره لزق', expensesdetails = '', expensesValue = '40.00', expensesdate = '2024-08-08', userid = '4', conditions = '0',saveid = '7' , dailyentryid = '10817', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '5294';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:31:19";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 17:01:19", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 17:01:19', '4', 'sucess', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:31:21";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 17:01:21", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 17:01:21', '4', 'show', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:31:24";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 17:01:24", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2024-08-08 17:01:24', '4', '', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:40:36";
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 < "2024-08-08 13:41:00";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:11:00", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2024-08-08 17:11:00', '1', '', '156.210.66.235', '', '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 < "2024-08-08 13:41:00";
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 < "2024-08-08 13:41:34";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:11:34", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('comentclientController.php', '2024-08-08 17:11:34', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:42:02";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:12:02", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('currencyController.php', '2024-08-08 17:12:02', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:42:07";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:12:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('currencyController.php', '2024-08-08 17:12:07', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:42:21";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:12:21", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('currencyController.php', '2024-08-08 17:12:21', '1', 'edit', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:42:44";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:12:44", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('userController.php', '2024-08-08 17:12:44', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:42:58";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:12:58", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('userController.php', '2024-08-08 17:12:58', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:43:03";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:13:03", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('userController.php', '2024-08-08 17:13:03', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:43:14";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:13:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('userController.php', '2024-08-08 17:13:14', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:43:18";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:13:19", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('userController.php', '2024-08-08 17:13:19', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:43:41";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:13:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('userController.php', '2024-08-08 17:13:41', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:44:02";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:14:02", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 17:14:02', '1', 'all', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:44:59";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:14:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 17:14:59', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:45:15";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:15:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 17:15:15', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:46:36";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:16:36", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 17:16:36', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:46:57";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:16:57", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 17:16:57', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:48:05";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:18:05", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 17:18:06', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:49:29";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:19:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:19:29', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:50:06";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:20:06", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:20:07', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:50:42";

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 066b4a6a037610
-- ----------------------------------------------------------------------------------------------------

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 ('2024-08-08 14:06:08', '066b4a6a037610', '1', '0.00', '0', '0', '1', '485', '485', '485', '0', '5', '2024-08-08 17:20:42', '', null, '0', 'نقدي', '5', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','485','0','','0','0','485','0','0','0','0','0','0','0','0','');
ROLLBACK;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 066b4a6a037610 and sellbillId = 0 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:50:43";
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 < "2024-08-08 13:50:56";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 17:20:56", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2024-08-08 17:20:56', '7', '', '197.192.201.150', '', '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 < "2024-08-08 13:50:57";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:50:59";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 17:20:59", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:20:59', '7', 'addsellBill', '197.192.201.150', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:51:30";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 17:21:30", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:21:30', '7', 'addAndRetuen', '197.192.201.150', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 066b4d44be27da
-- ----------------------------------------------------------------------------------------------------

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 ('2024-08-08 17:20:59', '066b4d44be27da', '1', '0.00', '0', '30', '1', '500', '470', '470', '0', '5', '2024-08-08 17:21:31', '', '7', '0', 'نقدي', '5', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','470','0','','0','0','470','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '7' WHERE clientid = '1';
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('1','0.00','0','0','اضافة فاتورة مبيعات','18013', '0', '2024-08-08 17:21:31', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '470', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 16913;
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 ('420','01576', '18013', '1', '1576', '1', '500', '500', '0', '', '1', '2024-08-08 17:21:31', '1576', '0.00', '0', '5','0','','','0','0','0','0','0','0','1','0','','16913-1,');
UPDATE sellbilldetail SET  lastbuyprice = 420.00 , meanbuyprice = 420.00, lastbuyprice_withDiscount = 420.00, meanbuyprice_withDiscount = 420.00
                where sellbilldetailid = 53296;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1576, '2024-08-08', 470, 420, 420
                    , 420, 420, 420, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+470, sellCostBuyPrice =sellCostBuyPrice+420
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+420, sellCostMeanBuyPrice = sellCostMeanBuyPrice+420
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+420, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+420
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (5, '2024-08-08', 470, 420, 420
                    , 420, 420, 420, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+470, sellCostBuyPrice =sellCostBuyPrice+420
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+420, sellCostMeanBuyPrice = sellCostMeanBuyPrice+420
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+420, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+420
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '12', userid = '7', storedetaildate = '2024-08-08 17:21:31' WHERE storedetailid = '5693';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1576', '5', '1', '1', '18013', 'اضافة فاتورة مبيعات', 'sellbillController.php', '13.00', '12', '7', '2024-08-08 17:21:31','0','0');
UPDATE save SET  savecurrentvalue = '13165',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('12695.00','470', '0', '5', 'اضافة فاتورة مبيعات', '18013', '13165', '2024-08-08 17:21:31', '7',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2024-08-08', 470, 420, 420
                    , 420, 420, 420, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+470, sellCostBuyPrice =sellCostBuyPrice+420
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+420, sellCostMeanBuyPrice = sellCostMeanBuyPrice+420
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+420, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+420
                            , 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, '2024-08-08', 470, 420, 420
                    , 420, 420, 420, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+470, sellCostBuyPrice =sellCostBuyPrice+420
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+420, sellCostMeanBuyPrice = sellCostMeanBuyPrice+420
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+420, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+420
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
 INSERT INTO quickprofitgeneral (id, netSellVal, netSellCostBuyPrice, netSellCostLastBuyPrice, netSellCostMeanBuyPrice, netSellCostLastBuyPricewithDiscount, netSellCostMeanBuyPricewithDiscount, netSellCostOverAllAveragePrice)
                    VALUES (1, 470, 420, 420
                    , 420, 420, 420, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+470, netSellCostBuyPrice = netSellCostBuyPrice+420
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+420
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+420
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+420
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+420
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 066b4d44be27da and sellbillId = 18013 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:51:31";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 17:21:31", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:21:31', '7', 'addsellBill', '197.192.201.150', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:51:51";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 17:21:51", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:21:52', '7', 'addAndRetuen', '197.192.201.150', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 066b4d46c1f4b2
-- ----------------------------------------------------------------------------------------------------

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 ('2024-08-08 17:21:32', '066b4d46c1f4b2', '1', '0.00', '0', '0', '1', '485', '485', '485', '0', '5', '2024-08-08 17:21:52', '', '7', '0', 'نقدي', '5', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','485','0','','0','0','485','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '7' WHERE clientid = '1';
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('1','0.00','0','0','اضافة فاتورة مبيعات','18014', '0', '2024-08-08 17:21:52', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '485', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 19661;
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 ('475','01784', '18014', '1', '1784', '1', '485', '485', '0', '', '2', '2024-08-08 17:21:52', '1784', '0.00', '0', '5','0','','','0','0','0','0','0','0','2','0','','19661-1,');
UPDATE sellbilldetail SET  lastbuyprice = 475.00 , meanbuyprice = 475.00, lastbuyprice_withDiscount = 475.00, meanbuyprice_withDiscount = 475.00
                where sellbilldetailid = 53297;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1784, '2024-08-08', 485, 475, 475
                    , 475, 475, 475, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+485, sellCostBuyPrice =sellCostBuyPrice+475
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+475, sellCostMeanBuyPrice = sellCostMeanBuyPrice+475
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+475, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+475
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (5, '2024-08-08', 485, 475, 475
                    , 475, 475, 475, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+485, sellCostBuyPrice =sellCostBuyPrice+475
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+475, sellCostMeanBuyPrice = sellCostMeanBuyPrice+475
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+475, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+475
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '14', userid = '7', storedetaildate = '2024-08-08 17:21:52' WHERE storedetailid = '6489';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1784', '5', '1', '1', '18014', 'اضافة فاتورة مبيعات', 'sellbillController.php', '15.00', '14', '7', '2024-08-08 17:21:52','0','0');
UPDATE save SET  savecurrentvalue = '13650',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('13165.00','485', '0', '5', 'اضافة فاتورة مبيعات', '18014', '13650', '2024-08-08 17:21:52', '7',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2024-08-08', 485, 475, 475
                    , 475, 475, 475, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+485, sellCostBuyPrice =sellCostBuyPrice+475
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+475, sellCostMeanBuyPrice = sellCostMeanBuyPrice+475
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+475, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+475
                            , 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, '2024-08-08', 485, 475, 475
                    , 475, 475, 475, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+485, sellCostBuyPrice =sellCostBuyPrice+475
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+475, sellCostMeanBuyPrice = sellCostMeanBuyPrice+475
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+475, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+475
                            , 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, 485, 475, 475
                    , 475, 475, 475, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+485, netSellCostBuyPrice = netSellCostBuyPrice+475
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+475
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+475
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+475
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+475
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 066b4d46c1f4b2 and sellbillId = 18014 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:51:52";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 17:21:52", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:21:53', '7', 'addsellBill', '197.192.201.150', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:52:38";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 17:22:38", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:22:38', '7', 'addAndRetuen', '197.192.201.150', '', 'DESKTOP');

-- ----------------------------------------------------------------------------------------------------
-- bill add start - with serial 066b4d48127189
-- ----------------------------------------------------------------------------------------------------

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 ('2024-08-08 17:21:53', '066b4d48127189', '1', '0.00', '0', '0', '1', '440', '440', '440', '0', '5', '2024-08-08 17:22:38', '', '7', '0', 'نقدي', '5', '0', '3', '0', 'نقدي', '1' ,'0','','','','','-1','0','0','0','0','0','440','0','','0','0','440','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '0', userid = '7' WHERE clientid = '1';
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('1','0.00','0','0','اضافة فاتورة مبيعات','18015', '0', '2024-08-08 17:22:38', '7', 'sellbillController.php', 'اضافة فاتورة مبيعات', '440', '0', null, '0', null, null,'', '0','1','1','0','1');
UPDATE buypriceshistorybook set sellQuantity = sellQuantity+1 where id = 19723;
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 ('430','01808', '18015', '1', '1808', '1', '440.00', '440', '0', '', '2', '2024-08-08 17:22:38', '1808', '0.00', '0', '5','0','','','0','0','0','0','0','0','2','0','','19723-1,');
UPDATE sellbilldetail SET  lastbuyprice = 430.00 , meanbuyprice = 430.00, lastbuyprice_withDiscount = 430.00, meanbuyprice_withDiscount = 430.00
                where sellbilldetailid = 53298;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1808, '2024-08-08', 440, 430, 430
                    , 430, 430, 430, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 1, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+440, sellCostBuyPrice =sellCostBuyPrice+430
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+430, sellCostMeanBuyPrice = sellCostMeanBuyPrice+430
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+430, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+430
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0
                        , netQuantity = netQuantity+1
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (5, '2024-08-08', 440, 430, 430
                    , 430, 430, 430, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+440, sellCostBuyPrice =sellCostBuyPrice+430
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+430, sellCostMeanBuyPrice = sellCostMeanBuyPrice+430
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+430, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+430
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+0
                        , returnSellVal = returnSellVal+0, returnSellCostBuyPrice = returnSellCostBuyPrice+0, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+0
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+0, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+0
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+0
                        , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+0;
UPDATE storedetail SET  productquantity = '7', userid = '7', storedetaildate = '2024-08-08 17:22:39' WHERE storedetailid = '6506';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1808', '5', '1', '1', '18015', 'اضافة فاتورة مبيعات', 'sellbillController.php', '8.00', '7', '7', '2024-08-08 17:22:39','0','0');
UPDATE save SET  savecurrentvalue = '14090',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('13650.00','440', '0', '5', 'اضافة فاتورة مبيعات', '18015', '14090', '2024-08-08 17:22:39', '7',  'sellbillController.php','1','');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2024-08-08', 440, 430, 430
                    , 430, 430, 430, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+440, sellCostBuyPrice =sellCostBuyPrice+430
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+430, sellCostMeanBuyPrice = sellCostMeanBuyPrice+430
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+430, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+430
                            , 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, '2024-08-08', 440, 430, 430
                    , 430, 430, 430, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+440, sellCostBuyPrice =sellCostBuyPrice+430
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+430, sellCostMeanBuyPrice = sellCostMeanBuyPrice+430
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+430, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+430
                            , 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, 440, 430, 430
                    , 430, 430, 430, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+440, netSellCostBuyPrice = netSellCostBuyPrice+430
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+430
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+430
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+430
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+430
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 066b4d48127189 and sellbillId = 18015 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:52:39";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 17:22:39", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:22:39', '7', 'addsellBill', '197.192.201.150', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:52:44";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 17:22:44", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 17:22:44', '7', '', '197.192.201.150', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:54:00";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 17:24:00", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 17:24:00', '7', 'add', '197.192.201.150', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('1', '', 'فاتوره الكهربا', '210', '2024-08-08', '7', '0','-1','5','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '13880',  userid = '7' WHERE saveid = '5';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('14090.00','210', '1', '5', 'إضافة مصروف', '5295', '13880', '2024-08-08 17:24:00', '7',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '210', '210', '2024-08-08', '7', '0', '0', '2024-08-08 17:24:00','اضافة اسم مصروف(  )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('10818', '144', '210', '','0');
UPDATE accountstree SET name = 'شحن كهرباء', customName = 'شحن كهرباء', parent = '14', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-08', itemtype2 = '0', theValue = '16337', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '144';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('10818', '139', '210', '','0');
UPDATE accountstree SET name = 'خزينة محل عبدالله', customName = 'خزينة محل عبدالله', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2022-07-06', itemtype2 = '1', theValue = '-3338953', theOrder = '0', layingOrder = '',reportid = '0' WHERE id = '139';
UPDATE expenses SET expensestypeid = '1', expensesname = '', expensesdetails = 'فاتوره الكهربا', expensesValue = '210.00', expensesdate = '2024-08-08', userid = '7', conditions = '0',saveid = '5' , dailyentryid = '10818', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '5295';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:54:01";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 17:24:01", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 17:24:01', '7', 'sucess', '197.192.201.150', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:54:03";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 17:24:03", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 17:24:03', '7', 'show', '197.192.201.150', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 13:54:06";
UPDATE user SET loginip = "197.192.201.150", lastactivetime = "2024-08-08 17:24:06", deviceType = "DESKTOP" WHERE userid = 7;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:24:06', '7', 'addsellBill', '197.192.201.150', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:07:42";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:37:42", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2024-08-08 17:37:42', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:07:57";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:37:57", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2024-08-08 17:37:57', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:08:17";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:38:17", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2024-08-08 17:38:17', '1', '', '156.210.66.235', '', '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 < "2024-08-08 14:08:17";
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:08:52";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:38:52", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2024-08-08 17:38:52', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:09:33";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:39:33", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:39:33', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:09:51";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:39:51", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:39:51', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:11:22";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:41:22", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:41:22', '1', 'showDetail', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:11:31";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:41:31", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 17:41:31', '1', 'all', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:11:41";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:41:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 17:41:41', '1', 'all', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:11:50";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:41:50", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 17:41:50', '1', 'all', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:12:07";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:42:07", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productCatController.php', '2024-08-08 17:42:08', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:12:29";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:42:29", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('productController.php', '2024-08-08 17:42:29', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:12:41";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:42:41", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('typeClientController.php', '2024-08-08 17:42:41', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:13:10";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:43:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:43:10', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:13:31";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:43:31", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:43:31', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:14:13";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:44:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:44:13', '1', 'delete', '156.210.66.235', '', 'DESKTOP');
DROP PROCEDURE IF EXISTS clientInUse;;

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

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

END

;

-- ----------------------------------------------------------------------------------------------------
-- bill delete start - sellbill with id = 18012
-- ----------------------------------------------------------------------------------------------------

BEGIN;
UPDATE costcenterdetail SET del = 1 WHERE type in( 0) and  modelid = 18012;
UPDATE sellbill SET  sellbillsysdate = '2024-08-08 17:44:13', userid = '1',delbyuserid = '1', conditions = '1'  ,billReservation= 0,billReservationDate='0000-00-00'  WHERE sellbillid = '18012';
UPDATE sellbilldetail SET  lastbuyprice = 430.00 , meanbuyprice = 430.00, lastbuyprice_withDiscount = 430.00, meanbuyprice_withDiscount = 430.00
                where sellbilldetailid = 53294;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1809, '2024-08-08', 6880, 6880, 6880
                    , 6880, 6880, 6880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0,16,0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-6880, sellCostBuyPrice =sellCostBuyPrice-6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice-6880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-6880
                            , 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-16
                        , netQuantityRet = netQuantityRet-0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 6880, 6880, 6880
                    , 6880, 6880, 6880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-6880, sellCostBuyPrice =sellCostBuyPrice-6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice-6880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-6880
                            , 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 = '41', userid = '1', storedetaildate = '2024-08-08 17:44:13' WHERE storedetailid = '6484';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1809', '1', '16', '0', '18012', 'حذف فاتورة مبيعات', 'sellbillController.php', '25.00', '41', '1', '2024-08-08 17:44:13','0','0');
UPDATE sellbilldetail SET  lastbuyprice = 430.00 , meanbuyprice = 430.00, lastbuyprice_withDiscount = 430.00, meanbuyprice_withDiscount = 430.00
                where sellbilldetailid = 53295;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1808, '2024-08-08', 6880, 6880, 6880
                    , 6880, 6880, 6880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0,16,0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-6880, sellCostBuyPrice =sellCostBuyPrice-6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice-6880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-6880
                            , 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-16
                        , netQuantityRet = netQuantityRet-0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 6880, 6880, 6880
                    , 6880, 6880, 6880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-6880, sellCostBuyPrice =sellCostBuyPrice-6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice-6880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-6880
                            , 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 = '99', userid = '1', storedetaildate = '2024-08-08 17:44:13' WHERE storedetailid = '6483';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1808', '1', '16', '0', '18012', 'حذف فاتورة مبيعات', 'sellbillController.php', '83.00', '99', '1', '2024-08-08 17:44:13','0','0');
CALL clientInUse(426,@clientdebt,@clientname);
UPDATE client SET  clientdebt = '0', userid = '1' WHERE clientid = '426';
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 ('426','13760.00','13760.00','1','حذف فاتورة مبيعات','18012', '0', '2024-08-08 17:44:13', '1', 'sellbillController.php', 'حذف فاتورة مبيعات', '13760', '0', null, '0', null, null,'', '0','1','1','13760','1');
UPDATE client SET  inUse = 0 where clientid = 426;
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2024-08-08', 13760, 13760, 13760
                    , 13760, 13760, 13760, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-13760, sellCostBuyPrice =sellCostBuyPrice-13760
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-13760, sellCostMeanBuyPrice = sellCostMeanBuyPrice-13760
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-13760, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-13760
                            , 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 (426, '2024-08-08', 13760, 13760, 13760
                    , 13760, 13760, 13760, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-13760, sellCostBuyPrice =sellCostBuyPrice-13760
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-13760, sellCostMeanBuyPrice = sellCostMeanBuyPrice-13760
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-13760, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-13760
                            , 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, 13760, 13760, 13760
                    , 13760, 13760, 13760, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal-13760, netSellCostBuyPrice = netSellCostBuyPrice-13760
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice-13760
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice-13760
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount-13760
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount-13760
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice-0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill delete end - sellbill with id = 18012
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:14:14";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:44:14", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:44:14', '1', 'sucess', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:14:16";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:44:16", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:44:16', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:14:20";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:44:20", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 17:44:20', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:16:09";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:46:09", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 17:46:09', '1', 'add', '156.210.66.235', '', 'DESKTOP');
INSERT INTO client (clientname, clientaddress, clientphone, clientmobile, clientdebt, clientdetails, conditions, clientdate, userid,clientareaid,clientcode,dailyentryid ,rondomtxt,clientStoreIds,obygyPatientId,debtLimit,typeclientid,priceTypeId,card_number,file_faida,specialDiscount,specialDiscountVal,file,addDate,mandobCollectRatio,webApiId,clientRFID,linkedSupplierId,postponeDays,studentid) VALUES ('ابوعبداللة سنتر المحلة' , 'المحلة الكبرى', '', '', '0', '', '0', '2024-08-08 17:46:09', '1', '0','','0','','-10','0','10000',',-20,','-1','0','','0','0','.','2024-08-08','0','0','','0','0','0');
INSERT INTO tamweenclientdetail (clientid, noOfPersonsTamween, noOfPersonsDa3m, cardNum, cardPassword) VALUES ('427', '0', '0', '', '');
INSERT INTO clientdebtchange (clientid, clientdebtchangebefore, clientdebtchangeamount, clientdebtchangetype, processname, clientdebtchangemodelid, clientdebtchangeafter, clientdebtchangedate, userid, tablename, comment, totalOperationCost,discount,reciptid,dailyentryid , num , billid , paytype, costcenterid,currencyId,conversionFactor,payedInCurrency,saveConversionFactor ) VALUES ('427','0','0','0','إضافة عميل جديد','427', '0', '2024-08-08 17:46:09', '0', 'clientController.php', '', '0', '0', null, '0', null, null,'', '0','1','1','0','1');
INSERT INTO accountstree (name, customName, parent, itemtype, itemfrom, notes, del, userid, mydate, itemtype2, theValue, theOrder, layingOrder,reportid) VALUES ('ابوعبداللة سنتر المحلة', 'ابوعبداللة سنتر المحلة', '23', '3', '0', '', '0', '1', '2024-08-08', '1', '0', '0', '','2');
UPDATE client SET clientname = 'ابوعبداللة سنتر المحلة', clientaddress = 'المحلة الكبرى', clientphone = '', clientmobile = '', clientdebt = '0.00', clientdetails = '', conditions = '0', clientdate = '2024-08-08', userid = '1'  , clientareaid = '0'  ,clientcode = '',dailyentryid = '0' , rondomtxt = '',clientStoreIds = '-10', obygyPatientId = '0' , debtLimit='10000' , typeclientid=',-20,',priceTypeId='-1',lastEditUser = '0',card_number = '0',file_faida = '',specialDiscount = '0',specialDiscountVal = '0',file = '.',mandobCollectRatio='0',clientRFID = '',linkedSupplierId = '0',postponeDays='0', studentid='0' WHERE clientid = '427';
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:16:10";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:46:10", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 17:46:10', '1', 'sucess', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:16:12";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:46:12", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 17:46:12', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:16:15";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:46:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:46:15', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:18:27";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:48:27", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 17:48:27', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:19:01";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:49:01", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientController.php', '2024-08-08 17:49:01', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:19:42";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 17:49:42", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 17:49:42', '4', '', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:19:45";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:49:45", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 17:49:45', '1', 'all', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:19:54";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:49:55", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 17:49:55', '1', 'all', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:19:59";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:49:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:49:59', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:20:39";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:50:39", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:50:39', '1', 'addAndRetuen', '156.210.66.235', '', '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 066b4db17e444f
-- ----------------------------------------------------------------------------------------------------

BEGIN;
CALL clientInUse(427,@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 ('2024-08-08 17:49:59', '066b4db17e444f', '427', '0.00', '13760', '0', '1', '13760', '13760', '0', '13760', '1', '2024-08-08 17:50:39', '', '1', '0', 'ابوعبداللة سنتر المحلة', '1', '1', '3', '0', 'ابوعبداللة سنتر المحلة', '32' ,'0','','','','','-1','0','0','0','0','0','13760','0','','0','0','0','0','0','0','0','0','0','0','0','');
UPDATE client SET  clientdebt = '13760', userid = '1' WHERE clientid = '427';
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 ('427','0.00','13760','0','اضافة فاتورة مبيعات','18016', '13760', '2024-08-08 17:50:39', '1', 'sellbillController.php', 'اضافة فاتورة مبيعات', '13760', '0', null, '0', null, null,'', '0','1','1','13760','1');
UPDATE client SET  inUse = 0 where clientid = 427;
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 ('430','01809', '18016', '1', '1809', '16', '430', '6880', '0', '', '0', '2024-08-08 17:50:39', '1809', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 430.00 , meanbuyprice = 430.00, lastbuyprice_withDiscount = 430.00, meanbuyprice_withDiscount = 430.00
                where sellbilldetailid = 53299;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1809, '2024-08-08', 6880, 6880, 6880
                    , 6880, 6880, 6880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 16, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+6880, sellCostBuyPrice =sellCostBuyPrice+6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice+6880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+6880
                            , 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+16
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 6880, 6880, 6880
                    , 6880, 6880, 6880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+6880, sellCostBuyPrice =sellCostBuyPrice+6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice+6880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+6880
                            , 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 = '25', userid = '1', storedetaildate = '2024-08-08 17:50:39' WHERE storedetailid = '6484';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1809', '1', '16', '1', '18016', 'اضافة فاتورة مبيعات', 'sellbillController.php', '41.00', '25', '1', '2024-08-08 17:50:39','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 ('430','01808', '18016', '1', '1808', '16', '430', '6880', '0', '', '0', '2024-08-08 17:50:39', '1808', '0.00', '0', '1','0','','','0','0','0','0','0','0','0','0','','');
UPDATE sellbilldetail SET  lastbuyprice = 430.00 , meanbuyprice = 430.00, lastbuyprice_withDiscount = 430.00, meanbuyprice_withDiscount = 430.00
                where sellbilldetailid = 53300;
 INSERT INTO quickprofitproduct (productId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice,netQuantity,netQuantityRet)
                    VALUES (1808, '2024-08-08', 6880, 6880, 6880
                    , 6880, 6880, 6880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0, 16, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+6880, sellCostBuyPrice =sellCostBuyPrice+6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice+6880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+6880
                            , 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+16
                        , netQuantityRet = netQuantityRet+0;
 INSERT INTO quickprofitstore (storeId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount, returnSellCostOverAllAveragePrice)
                    VALUES (1, '2024-08-08', 6880, 6880, 6880
                    , 6880, 6880, 6880, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+6880, sellCostBuyPrice =sellCostBuyPrice+6880
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+6880, sellCostMeanBuyPrice = sellCostMeanBuyPrice+6880
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+6880, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+6880
                            , 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 = '83', userid = '1', storedetaildate = '2024-08-08 17:50:39' WHERE storedetailid = '6483';
INSERT INTO storereport (productid, storeid, productquantity, storereporttype, storereportmodelid, processname, tablename, productbefore, productafter, userid, storereportdate,sizeid,colorid) VALUES ('1808', '1', '16', '1', '18016', 'اضافة فاتورة مبيعات', 'sellbillController.php', '99.00', '83', '1', '2024-08-08 17:50:39','0','0');
 INSERT INTO quickprofitday (theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice)
                    VALUES ('2024-08-08', 13760, 13760, 13760
                    , 13760, 13760, 13760, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+13760, sellCostBuyPrice =sellCostBuyPrice+13760
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+13760, sellCostMeanBuyPrice = sellCostMeanBuyPrice+13760
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+13760, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+13760
                            , 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 (427, '2024-08-08', 13760, 13760, 13760
                    , 13760, 13760, 13760, 0
                    , 0, 0, 0, 0
                    , 0, 0, 0)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+13760, sellCostBuyPrice =sellCostBuyPrice+13760
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+13760, sellCostMeanBuyPrice = sellCostMeanBuyPrice+13760
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+13760, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+13760
                            , 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, 13760, 13760, 13760
                    , 13760, 13760, 13760, 0)
                ON DUPLICATE KEY UPDATE netSellVal = netSellVal+13760, netSellCostBuyPrice = netSellCostBuyPrice+13760
                , netSellCostLastBuyPrice = netSellCostLastBuyPrice+13760
                , netSellCostMeanBuyPrice = netSellCostMeanBuyPrice+13760
                , netSellCostLastBuyPricewithDiscount = netSellCostLastBuyPricewithDiscount+13760
                , netSellCostMeanBuyPricewithDiscount = netSellCostMeanBuyPricewithDiscount+13760
                , netSellCostOverAllAveragePrice = netSellCostOverAllAveragePrice+0;
COMMIT;

-- ----------------------------------------------------------------------------------------------------
-- bill add end - with serial 066b4db17e444f and sellbillId = 18016 and returnsellbillId = 
-- ----------------------------------------------------------------------------------------------------

UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:20:40";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 17:50:40", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:50:40', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:20:43";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 17:50:43", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 17:50:43', '4', 'add', '197.35.195.208', '', 'DESKTOP');
BEGIN;
INSERT INTO expenses (expensestypeid, expensesname, expensesdetails, expensesValue, expensesdate, userid, conditions,costcenterid,saveid,dailyentryid,bankid,bankaccountid,checknum,productid) VALUES ('-1', 'قبض احمد توكل اسبوع', '', '1000', '2024-08-08', '4', '0','-1','7','0','0','0','','0');
UPDATE save SET  savecurrentvalue = '5615',  userid = '4' WHERE saveid = '7';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('6615.00','1000', '1', '7', 'إضافة مصروف', '5296', '5615', '2024-08-08 17:50:43', '4',  'expensesController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '1000', '1000', '2024-08-08', '4', '0', '0', '2024-08-08 17:50:43','اضافة اسم مصروف( قبض احمد توكل اسبوع )','1','0','-1');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('10819', '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 = '-4609105', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '160';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('10819', '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 = '-2223962', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '141';
UPDATE expenses SET expensestypeid = '-1', expensesname = 'قبض احمد توكل اسبوع', expensesdetails = '', expensesValue = '1000.00', expensesdate = '2024-08-08', userid = '4', conditions = '0',saveid = '7' , dailyentryid = '10819', bankid = '0', bankaccountid = '0', checknum = '', productid = '0' WHERE expensesid = '5296';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:20:43";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 17:50:43", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 17:50:44', '4', 'sucess', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:20:45";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 17:50:45", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('expensesController.php', '2024-08-08 17:50:45', '4', 'show', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:20:50";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 17:50:51", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('clientReportsController.php', '2024-08-08 17:50:51', '4', '', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:20:52";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 17:50:52", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('savedailyController.php', '2024-08-08 17:50:52', '4', '', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:21:07";
UPDATE user SET loginip = "197.35.195.208", lastactivetime = "2024-08-08 17:51:07", deviceType = "DESKTOP" WHERE userid = 4;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 17:51:07', '4', 'addsellBill', '197.35.195.208', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:28:02";
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:32:00";
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
INSERT IGNORE INTO relusergroupproperties (usergroupid, propertyid, propertyvalue, theorder)
                SELECT -1,propertyid , 0,0
                from properties;
INSERT IGNORE INTO usergroupadmin (propertyid, isallowed)
                SELECT propertyid , propertydefault
                from properties;
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 < "2024-08-08 14:37:18";
UPDATE user SET loginip = "154.183.41.29", lastactivetime = "2024-08-08 18:07:18", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('index.php', '2024-08-08 18:07:18', '8', '', '154.183.41.29', '', '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 < "2024-08-08 14:37:18";
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 < "2024-08-08 14:37:32";
UPDATE user SET loginip = "154.183.41.29", lastactivetime = "2024-08-08 18:07:32", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 18:07:32', '8', 'addsellBill', '154.183.41.29', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:38:45";
UPDATE user SET loginip = "154.183.41.29", lastactivetime = "2024-08-08 18:08:45", deviceType = "DESKTOP" WHERE userid = 8;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 18:08:45', '8', 'addsellBill', '154.183.41.29', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:41:31";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 18:11:31", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2024-08-08 18:11:31', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:42:12";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 18:12:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2024-08-08 18:12:13', '1', 'add', '156.210.66.235', '', 'DESKTOP');
BEGIN;
INSERT INTO transfermoney (saveidfrom, saveidto, transfermoneyvalue, transfermoneydate, userid, conditions, dailyentryid , comment) VALUES ('8','9', '9465', '2024-08-08', '1', '0', '0','ليد الشيخ وليد');
UPDATE save SET  savecurrentvalue = '1100',  userid = '1' WHERE saveid = '8';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('10565.00','9465', '1', '8', 'تحويل امول الى الخزنة  [ الشيخ وليد ] ', '781', '1100', '2024-08-08 18:12:13', '1',  'transfermoneyController.php','0','');
UPDATE save SET  savecurrentvalue = '9106323',  userid = '1' WHERE saveid = '9';
INSERT INTO savedaily (savedailysavebefore, savedailychangeamount, savedailychangetype, saveid, processname, savedailymodelid, savedailysaveafter, savedailydate, userid, tablename,clientid ,note) VALUES ('9096858.00','9465', '0', '9', 'تحويل امول من الخزنة  [ خزينة محل ابو كريم ] ', '781', '9106323', '2024-08-08 18:12:13', '1',  'transfermoneyController.php','0','');
INSERT INTO dailyentry (totalcreditor, totaldebtor, thedate, userid, `condition`, reverseofid, dDateTime,entryComment,fromFlag,related,branchid) VALUES ( '9465', '9465', '2024-08-08', '1', '0', '0', '2024-08-08 18:12:13','اضافة تحويل من خزينة محل ابو كريم الى الشيخ وليد','1','0','0');
INSERT INTO dailyentrydebtor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('10820', '156', '9465', '','0');
UPDATE accountstree SET name = 'الشيخ وليد', customName = 'الشيخ وليد', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-09', itemtype2 = '1', theValue = '9106323', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '156';
INSERT INTO dailyentrycreditor (dailyentryid, accountstreeid, value, dComment,costcenterid) VALUES ('10820', '142', '9465', '','0');
UPDATE accountstree SET name = 'خزينة محل ابو كريم', customName = 'خزينة محل ابو كريم', parent = '20', itemtype = '3', itemfrom = '0', notes = '', del = '0', userid = '1', mydate = '2021-11-07', itemtype2 = '1', theValue = '-3021756', theOrder = '0', layingOrder = '',reportid = '2' WHERE id = '142';
UPDATE transfermoney SET saveidfrom = '8', saveidto = '9', transfermoneyvalue = '9465.00', transfermoneydate = '2024-08-08', userid = '1', conditions = '0' , dailyentryid = '10820' , comment = 'ليد الشيخ وليد' WHERE transfermoneyid = '781';
COMMIT;
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:42:13";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 18:12:13", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2024-08-08 18:12:13', '1', 'sucess', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:42:15";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 18:12:15", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2024-08-08 18:12:15', '1', 'show', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:43:24";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 18:13:24", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('transfermoneyController.php', '2024-08-08 18:13:24', '1', '', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 14:58:51";
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 15:02:59";
UPDATE user SET loginip = "156.210.66.235", lastactivetime = "2024-08-08 18:32:59", deviceType = "DESKTOP" WHERE userid = 1;
INSERT INTO movementmanage (operationname, movementmanagedate, userid, currentDo, ip, mac, deviceType) VALUES ('sellbillController.php', '2024-08-08 18:32:59', '1', 'addsellBill', '156.210.66.235', '', 'DESKTOP');
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 15:03:11";
UPDATE user SET loginip = "" WHERE lastactivetime < "2024-08-08 15:03:13";
