offer jobs

This commit is contained in:
CHIEFSOFT\ameye
2024-01-09 13:34:22 -05:00
parent 85dd3fe301
commit 51beca9a44
+14 -57
View File
@@ -1639,24 +1639,26 @@ long WrenchSendJobsOfferGroup(CVars in, CVars &out) {
CVars u;
long total_member = 0;
load_db_record(out, "SELECT count(id) AS m_count FROM members_job_groupmember WHERE group_id = %lu AND member_id= %lu", in["group_id"].Long(), in["member_id"].Long());
load_db_record(out, "SELECT count(id) AS m_count "
" FROM members_job_groupmember "
" WHERE group_id = %lu AND member_id= %lu", in["group_id"].Long(), in["member_id"].Long());
// valid load of job needed
total_member = out["m_count"].Long() + 0;
if (total_member == 0) {
out["status"] = "Empty members in group";
out["status_message"] = "cannot_send_offer_to_empty_group";
return ret;
}
// we need this job id
if (load_db_record(y, " SELECT * FROM members_jobs WHERE id =%lu", in["job_id"].Long())) {
// make sure job is valid
if (load_db_record(y, " SELECT * FROM members_jobs "
" WHERE id =%lu AND status = 1", in["job_id"].Long())) {
// valid load of job needed
} else {
out["status"] = "Unable to create offer";
out["status_message"] = "cannot_find_valid_offer";
return ret;
}
@@ -1674,7 +1676,8 @@ long WrenchSendJobsOfferGroup(CVars in, CVars &out) {
// Now do you have money to do this ....
z["balance"] = "0";
z["balance"].set_valid(true); // just initialize it
if (load_db_record(z, " SELECT * FROM members_wallet WHERE id =%lu AND member_id =%lu AND amount >= %lu",wallet_id, in["member_id"].Long(), y["price"].Long())) {
if (load_db_record(z, " SELECT * FROM members_wallet WHERE id =%lu "
" AND member_id =%lu AND amount >= %lu",wallet_id, in["member_id"].Long(), y["price"].Long())) {
} else {
out["status"] = "Insufficient balance to create this offer";
@@ -1687,22 +1690,14 @@ long WrenchSendJobsOfferGroup(CVars in, CVars &out) {
return ret;
}
/*
if (y["price"].Long() * total_member >= z["balance"].Long()) // note that we have all members here for the price
{
out["status"] = "Insufficient balance to create this offer";
logfmt(logINFO, "Price = %lu Balance = %lu", y["price"].Long(), z["balance"].Long());
return ret;
}
*/
logfmt(logINFO, "Price = %lu Balance = %lu", y["price"].Long() * total_member, z["amount"].Long());
try {
const PGresult *res = pgsql_query("SELECT email FROM members_job_groupmember WHERE group_id=%lu AND member_id = %lu AND status=1", in["group_id"].Long(), in["member_id"].Long());
const PGresult *res = pgsql_query("SELECT email FROM members_job_groupmember "
" WHERE group_id = %lu "
" AND member_id = %lu "
" AND status=1", in["group_id"].Long(), in["member_id"].Long());
if (res != NULL && pgsql_num_rows(res) > 0) {
for (int i = 0, n = pgsql_num_rows(res); i < n; i++) {
map<const char*, const char*>f = pgsql_fetch_assoc(res, i);
@@ -1721,46 +1716,8 @@ long WrenchSendJobsOfferGroup(CVars in, CVars &out) {
if (call_ret == PHP_CREATED_OK) {
ret = PHP_CREATED_OK;
}
}
}
// if ( load_db_record( out, "SELECT count(id) AS duplicate_name FROM members_jobs_offer WHERE LOWER(group_name)=LOWER('%s') AND member_id =%lu AND status = 1",in["group_name"].c_str(), in["member_id"].Long() ))
// {
// if ( out["duplicate_name"].Long() > 0 ) { return PHP_API_BAD_PARAM; } // return no duplicate on any active name
// } // this action blocks out duplicate
/*
x["member_id"] = in["member_id"]; x["member_id"].set_valid( true );
x["job_id"] = in["job_id"]; x["job_id"].set_valid( true );
x["group_id"] = in["group_id"]; x["group_id"].set_valid( true );
x["job_description"] = in["job_description"]; x["job_description"].set_valid( true );
x["offer_code"] = in["offer_code"]; x["offer_code"].set_valid( true );
const char * loc = getenv("REMOTE_ADDR");
x["loc"] = loc; x["loc"].set_valid(true);
offer_id = insert_db_record( DBS_VALID, "members_jobs_offer", "members_jobs_offer_id_seq", x );
if (offer_id > 0) {
char offer_code[15] = "";
GetOfferCode(offer_id, offer_code, sizeof (offer_code)); // this stamp the offer code directly in that call
pgsql_exec("UPDATE members_jobs_offer SET expire = now() + '1 day' WHERE id = %lu",offer_id);
ret = PHP_CREATED_OK;
x["offer_id"] = offer_id; x["offer_id"].set_valid( true );
job_email(JOBS_GROUP_OFFER_MAIL,x,out);
load_db_record( out, "SELECT *,id AS offer_id FROM members_jobs_offer WHERE id = %lu ", offer_id );
out["status"] = "Offer sent to recipient";
} else {
out["status"] = "Unanble to create offer";
}
*/
} catch (bad_parameter) {
out["log_status"] = "Invalid Log Action";
}