unset($product_row[$product_key]); } } $subject = "Search Ad - Search Ads products budget has ended"; $message = "The following Search Ad products have reached balance 0 (zero)." . PHP_EOL . PHP_EOL; foreach ($product_row as $product_details) { $new_balance = $product_details['balance'] - $product_details['last_cost']; $new_balance = $new_balance < 0 ? 0 : number_format($new_balance, 2); $add_product_to_message = false; if ($product_details['balance'] != '') { try { $values = array('budget_credit' => $new_balance, 'last_adwords_date' => $yesterday_date); $db_syssql->update()->table('sYra.google_advertising_product_credit')->values($values)->where('product_data_id = :monthly_budget_product_data_id')->binds(array(':monthly_budget_product_data_id' => $product_details['monthly_budget_product_data_id']))->execute(); } catch (DatabaseException $dbe) { //Show generic error for db class exceptions throw new Exception('An error has occurred, please try again'); } if ($new_balance <= 0) { $add_product_to_message = true; } } if ($add_product_to_message) { $message .= "Product ID: {$product_details['product_data_id']}" . PHP_EOL . "Member ID: {$product_details['member_id']}" . PHP_EOL . "Client ID: {$product_details['client_id']}" . PHP_EOL . PHP_EOL; $send_email = true; } } if ($send_email) { notification::send($to, FROM_EMAIL, FROM_EMAIL_NAME, $subject, $message); } } cron_commit($execution_id);