// cuponUsedWithInvoice procedure

BEGIN
    DECLARE existingUsedTotal INTEGER DEFAULT 0;
    DECLARE newUsedTotal INTEGER DEFAULT 0;
    
    SET existingUsedTotal=(SELECT cuponUsedTotal FROM `coupon` WHERE id=cuponID);
    
    SET newUsedTotal=existingUsedTotal+1;
    
    UPDATE `coupon` SET cuponUsedTotal=newUsedTotal WHERE id=cuponID;
    
END


// topProductCount procedure

BEGIN
DECLARE currentProductQuantity INTEGER DEFAULT 0;
DECLARE totalProductQuantity INTEGER DEFAULT 0;
SET currentProductQuantity = (SELECT totalOrder FROM products WHERE id = productId);
SET totalProductQuantity = currentProductQuantity + newQuantity;
UPDATE products set totalOrder = totalProductQuantity where id = productId;
END