This is a PHP function called determineFrequency that determines if a donor should be charged based on the frequency of their donations. It takes in three parameters: $now, $last, and $frequency.
$now represents the current date and time and is passed to the function as a Carbon object.
$last represents the date of the last payment made by the donor and is also passed to the function as a Carbon object.
$frequency is an integer that represents the frequency of donations, with the same values as the previous function.
The function first initializes a boolean variable called $charge to false. It then uses a switch statement to check the frequency of donations and determines if the donor should be charged based on the current date and the date of the last payment.
For monthly donations, the function checks if the current date is greater than or equal to one month after the last payment. If it is, the function adds 14 days to the last payment date and checks if the current date is less than the future date. If it is, the donor should be charged.
For quarterly, semi-annually, and annually donations, the function follows the same logic as monthly donations, but checks if the current date is greater than or equal to three, six, or twelve months after the last payment, respectively.
Finally, the function returns the value of $charge, which will be either true or false depending on whether the donor should be charged.
As for the SQL query, it would depend on the table structure and the data you are working with. Please provide more details if you need help with an SQL query.