Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- p_email IN VARCHAR2,
- p_projID IN INTEGER,
- p_quantity IN INTEGER,
- p_amount IN NUMBER
- )
- IS
- ex_ERROR EXCEPTION;
- lv_errorMsg_txt VARCHAR(100);
- lv_donationid INTEGER;
- lv_shoppingcartid INTEGER;
- lv_donorid INTEGER;
- lv_ischecked INTEGER;
- lv_cartcount INTEGER;
- lv_donorcount INTEGER;
- lv_projectcount INTEGER;
- lv_donationcount INTEGER;
- lv_projectstatus VARCHAR(100);
- CURSOR cur_isChecked IS
- SELECT isChecked
- FROM GG_DONATION
- WHERE DONOR_ID = lv_donorid;
- CURSOR cur_donationid IS
- SELECT donation_transactionID
- FROM GG_DONATION
- WHERE DONOR_ID = lv_donorid;
- BEGIN
- -- Checking that parameters are provided.
- IF p_projID IS NULL THEN
- lv_errorMsg_txt := 'Please specify a project ID.';
- RAISE ex_ERROR;
- ELSIF p_email IS NULL THEN
- lv_errorMsg_txt := 'Please enter an email.';
- RAISE ex_ERROR;
- ELSIF p_quantity IS NULL THEN
- lv_errorMsg_txt := 'You must specify a donation quantity.';
- RAISE ex_ERROR;
- ELSIF (p_amount <= 0) THEN
- lv_errorMsg_txt := 'You must enter an amount greater than 0.';
- RAISE ex_ERROR;
- ELSIF (p_quantity <= 0) THEN
- lv_errorMsg_txt := 'You must enter a quantity greater than 0.';
- RAISE ex_ERROR;
- END IF;
- -- Checking if there is a donor with the specified email address.
- SELECT COUNT(donor_id) INTO lv_donorcount
- FROM GG_DONOR
- WHERE GG_DONOR.donor_email = p_email;
- IF lv_donorcount = 0 THEN
- lv_errorMsg_txt := 'The email-address was not found in the database.';
- RAISE ex_ERROR;
- END IF;
- -- Checking if there is a project with the specified project id.
- SELECT COUNT(project_id) INTO lv_projectcount
- FROM GG_PROJECT
- WHERE GG_PROJECT.project_id = p_projID;
- IF lv_projectcount = 0 THEN
- lv_errorMsg_txt := 'There is no project with the specified project ID.';
- RAISE ex_ERROR;
- END IF;
- -- Checking if the status is retired.
- SELECT project_status INTO lv_projectstatus
- FROM GG_PROJECT
- WHERE GG_PROJECT.project_id = p_projID;
- IF lv_projectstatus = 'retired' THEN
- lv_errorMsg_txt := 'The project is retired and you can no longer donate.';
- RAISE ex_ERROR;
- END IF;
- -- Get the donor id from the supplied email.
- SELECT GG_DONOR.donor_id
- INTO lv_donorid
- FROM GG_DONOR
- WHERE GG_DONOR.donor_email = p_email;
- -- Checking if there are any donations for the donor. Need this to determine
- -- if the donor has an open transaction or not.
- SELECT COUNT(donation_transactionID)
- INTO lv_donationcount
- FROM GG_DONATION
- WHERE DONOR_ID = lv_donorid;
- DBMS_OUTPUT.PUT_LINE('Donations: ' || lv_donationcount);
- OPEN cur_isChecked;
- OPEN cur_donationid;
- LOOP
- FETCH cur_isChecked INTO lv_ischecked;
- DBMS_OUTPUT.PUT_LINE('lv_ischecked: ' || lv_ischecked);
- FETCH cur_donationid INTO lv_donationid;
- DBMS_OUTPUT.PUT_LINE('lv_donationid ' || lv_donationid);
- --EXIT WHEN cur_isChecked%NOTFOUND;
- --EXIT WHEN cur_donationid%NOTFOUND;
- IF lv_ischecked IS NULL OR lv_ischecked = 1 THEN
- lv_donationid := DONATION_SEQ.NEXTVAL;
- DBMS_OUTPUT.PUT_LINE('lv_donationid ' || lv_donationid);
- INSERT INTO GG_DONATION(
- donation_transactionID,
- donation_date,
- donor_id
- )
- VALUES (
- lv_donationid,
- SYSDATE,
- lv_donorid
- );
- DBMS_OUTPUT.PUT_LINE('-- Added donation.');
- INSERT INTO GG_DONATIONDETAIL(
- donation_transactionID,
- project_id,
- donationdetail_amount,
- donationdetail_qty,
- donationdetail_extAmount
- )
- VALUES (
- lv_donationid,
- p_projID,
- p_amount,
- p_quantity,
- p_amount
- );
- EXIT;
- ELSIF lv_donationcount > 0 AND lv_ischecked = 0 THEN
- INSERT INTO GG_DONATIONDETAIL(
- donation_transactionID,
- project_id,
- donationdetail_amount,
- donationdetail_qty,
- donationdetail_extAmount
- )
- VALUES (
- lv_donationid,
- p_projID,
- p_amount,
- p_quantity,
- p_amount
- );
- EXIT;
- END IF;
- END LOOP;
- CLOSE cur_donationid;
- CLOSE cur_isChecked;
- COMMIT;
- DBMS_OUTPUT.PUT_LINE('Donation with ID: ' || lv_donationID ||
- ' added to shopping cart of Donor: ' || lv_donorID );
- EXCEPTION
- WHEN ex_ERROR THEN DBMS_OUTPUT.PUT_LINE(lv_errorMsg_txt);
- ROLLBACK;
- WHEN OTHERS THEN
- DBMS_OUTPUT.PUT_LINE('An error occurred.');
- DBMS_OUTPUT.PUT_LINE('Error code: ' || SQLCODE);
- DBMS_OUTPUT.PUT_LINE('Error message: ' || SQLERRM);
- ROLLBACK;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement