payment.php 2.11 KB
Newer Older
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
1 2 3 4
<?php

class Payment extends Record {
    public $id;
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
5
    public $subscription_id;
6
    public $payment_method_name;
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
7
    public $amount, $comments;
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
    public $check_bank_name, $check_owner_name;
    public $created_at;

	public static $table = "lud_payments";

	public function __construct($id = 0) {
    	if (!$this->id) {
			$this->id = $id;
	    }
	}

    /*
     * function fetch_all
     * fetches all payments for a given subscription, in an array by ref
     * @return the number of payments
     */
	public static function fetch_all(&$payments, $subscription_id) {
        $payments = array();
		// SQL SELECT lud_payments
27
        $sql = "SELECT p.id, p.payment_method_name,
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
28 29
                p.amount, p.comments,
                p.check_bank_name, p.check_owner_name, p.created_at
30
            FROM ".Payment::$table." p
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
31 32
            WHERE p.subscription_id = $subscription_id
            ORDER BY p.id"; 
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
33 34 35 36 37 38
        $GLOBALS["data"]->select($sql, $payments, "Payment", 1);
        return sizeof($payments);
    }

	public static function fetch($id) {
        // SQL SELECT lud_payments
39
        $sql = "SELECT  id, payment_method_name, amount, comments,
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
40 41 42 43 44 45
                check_bank_name, check_owner_name, created_at
            FROM ".Payment::$table."
            WHERE id = ".$id;
        $GLOBALS["data"]->select($sql, $payment, "Payment");
        return $payment;
    }
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
46 47


48
    public static function create_from_post($subscription_id, $payment_method_name,
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
49 50 51
            $comments, $amount) {
        $payment = new Payment();
        $payment->subscription_id = $subscription_id;
52
        $payment->payment_method_name = $payment_method_name;
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
53 54 55 56 57 58 59 60
        $payment->comments = $comments;
        $payment->amount = $amount;
        $payment->save();
        return $payment;
    }

    public function save() {
        // SQL INSERT lud_payments
61 62
        $sql = " INSERT INTO ".Payment::$table." (subscription_id, payment_method_name, amount, comments)
            VALUES ('".$this->subscription_id."', '".$this->payment_method_name."',
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
63 64 65
                    '".$this->amount."', '".$this->comments."' )";
        $this->id = $GLOBALS["data"]->insert($sql);
    }
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
66
}