PHPDoctor


class/PaymentLog.class.php

Ofuz Open Source version is released under the GNU Affero General Public License, please read the full license at: http://www.gnu.org/licenses/agpl-3.0.html


/** Ofuz Open Source version is released under the GNU Affero General Public License, please read the full license at: http://www.gnu.org/licenses/agpl-3.0.html **/ 
// Copyright 2008 - 2010 all rights reserved, SQLFusion LLC, info@sqlfusion.com
/** Ofuz Open Source version is released under the GNU Affero General Public License, please read the full license at: http://www.gnu.org/licenses/agpl-3.0.html **/

class PaymentLog extends DataObject {

    public $table = 'paymentlog';
    protected $primary_key = 'idpaymentlog';


    /*
      Add Payment Log method
    */
    function addPaymentLog($ref_num,$pay_type,$idinvoice,$amt){
        $this->amount = $amt;
        $this->idinvoice = $idinvoice;
        $this->payment_type = $pay_type;
        $this->ref_num = $ref_num;
        $this->timestamp = time();
        $this->date_added = date("Y-m-d H:i:s");
        $this->add();
    }

    /*
        Check if its a duplicate entry for a ref num. 
        Needed for the Paypal as the Returned data is 
        a post value from Paypal and using f5 may create 
        a duplicate entry.
    */
    function isTransRefExists($ref_num,$idinvoice,$pay_type){
        $q = new sqlQuery($this->getDbCon());
        $q->query("Select * from ".$this->table. " Where ref_num = '".$ref_num."' AND
                   idinvoice = ".$idinvoice." AND payment_type = '".$pay_type."'
                  ");
        if($q->getNumRows()){
            return true;
        }else{
            return false;
        }
    }

    /*
        Function to get the payment Log for an invoice
    */
    function getPaymentLog($idinvoice){
      //$this->query("select * from ".$this->table. " where idinvoice = ".$idinvoice." order by ".$this->primary_key. " desc");
      $qry = "Select sum(payment_invoice.amount ) as amount,payment_invoice.idpayment_invoice,
              paymentlog.timestamp,paymentlog.ref_num,paymentlog.idpaymentlog from paymentlog 
              Inner Join payment_invoice on payment_invoice.idpayment = paymentlog.idpaymentlog
              Where payment_invoice.idinvoice = ".$idinvoice." GROUP BY payment_invoice.idpayment_invoice "; 
       $this->query($qry);       
    }

    function eventDeletePaymentLog(EventControler $evtcl){
      if($evtcl->id){
	$q = new sqlQuery($this->getDbCon());
	$sql = "SELECT COUNT(payment_invoice.idpayment) AS num_inv 
		FROM payment_invoice INNER JOIN paymentlog 
		ON paymentlog.idpaymentlog = payment_invoice.idpayment
		WHERE paymentlog.idpaymentlog = {$evtcl->id}
	       ";
	$q->query($sql);
	if($q->getNumRows()) {
	  $q->fetch();
	  $num_inv = $q->getData("num_inv");

	  if($num_inv == 1) {

	    $do_inv = new Invoice();
	    $this->getId($evtcl->id);
	    $idinvoice = $this->idinvoice;

	    $sql_del_paymentlog = "DELETE FROM {$this->table} WHERE idpaymentlog = '{$evtcl->id}'";
	    $sql_del_paymentinv = "DELETE FROM payment_invoice WHERE idpayment = '{$evtcl->id}'";
	    $sql_del_ext_amt = "DELETE FROM paymentlog_extra_amount WHERE idpaymentlog = '{$evtcl->id}'";

	    $q->query($sql_del_paymentlog);
	    $q->query($sql_del_paymentinv);
	    $q->query($sql_del_ext_amt);

	    $do_inv->deletePaymentFromInvoice($idinvoice,$evtcl->amt);

	    $_SESSION['in_page_message'] = _("Payment has been deducted from the invoice.");

	  } 
	  if($num_inv > 1) {
	    $_SESSION['in_page_message'] = _("This Payment can not be deleted since it is shared with multiple invoices.");
	  }

	}

          /*$do_inv = new Invoice();
          $this->getId($evtcl->id);
          $amt = $this->amount;
          $idinvoice = $this->idinvoice;

          $do_delete_paylog = new DeletePaymentLog();
          $do_delete_paylog->addNew();
          $do_delete_paylog->amount = $amt;
          $do_delete_paylog->idinvoice = $idinvoice;
          $do_delete_paylog->payment_type = $this->payment_type;
          $do_delete_paylog->ref_num = $this->ref_num;
          $do_delete_paylog->timestamp = $this->timestamp;
          $do_delete_paylog->add();
  
          $this->delete();
          $do_inv->deletePaymentFromInvoice($idinvoice,$amt);
          $_SESSION['in_page_message'] = _("Payment has been deducted from the invoice.");*/
      }
      
    }

  function getPaymentLogDetails($idinvoice) {
    $sql = "SELECT *
            FROM {$this->table}
            WHERE idinvoice = {$idinvoice}
           ";
    $this->query($sql);
  }

  function getPaymentLogExtraAmountDetails($idpaymentlog) {
    $sql = "SELECT *
            FROM `paymentlog_extra_amount`
            WHERE idpaymentlog = {$idpaymentlog}
           ";
    $this->query($sql);
  }
}
?>

PHPDoctor