Exemplo n.º 1
0
 public static function addTransaction($invoiceId, $customer, $amount, $currency_code, $description = '')
 {
     if (is_numeric($customer)) {
         /// customer ID is passed. Need to get customer object
         $customer = CustomerDAO::getInstance()->getCustomer($customer);
     }
     /// Now need to convert transaction amount to customer base currency
     $currency = Transaction::$instance->getRegistry()->get('currency');
     $amountInCustomerCurrency = (double) $currency->convert($amount, $currency_code, $customer['base_currency_code']);
     $newCustomerBalance = $customer['balance'] - $amountInCustomerCurrency;
     Transaction::$instance->getDb()->query("\r\n            INSERT INTO customer_transaction\r\n            SET\r\n                customer_id = " . (int) $customer['customer_id'] . ",\r\n                invoice_id = " . (int) $invoiceId . ",\r\n                description = '" . Transaction::$instance->getDb()->escape($description) . "',\r\n                amount = {$amountInCustomerCurrency},\r\n                currency_code = '" . $customer['base_currency_code'] . "',\r\n                date_added = NOW(),\r\n                balance = {$newCustomerBalance},\r\n                balance_currency = '" . Transaction::$instance->getDb()->escape($customer['base_currency_code']) . "'\r\n        ");
     //$transactionId = Transaction::$instance->getDb()->getLastId();
     /// Update customer's balance
     Transaction::$instance->getDb()->query("\r\n                UPDATE customer\r\n                SET\r\n                    balance = {$newCustomerBalance}\r\n                WHERE customer_id = " . $customer['customer_id']);
     Transaction::$instance->getCache()->delete('customer.' . $customer['customer_id']);
     if (Transaction::$instance->user->isLogged()) {
         Audit::getInstance(Transaction::$instance->getRegistry())->addAdminEntry(Transaction::$instance->user->getId(), AUDIT_ADMIN_TRANSACTION_ADD, $_REQUEST);
     } elseif (Transaction::$instance->customer->isLogged()) {
         Audit::getInstance(Transaction::$instance->getRegistry())->addUserEntry(Transaction::$instance->customer->getId(), AUDIT_ADMIN_TRANSACTION_ADD, $_REQUEST);
     }
 }
Exemplo n.º 2
0
 public function disable()
 {
     $this->changeStatusProducts(0);
     Audit::getInstance($this->getRegistry())->addAdminEntry($this->getUser()->getId(), AUDIT_ADMIN_PRODUCT_DISABLE, $_REQUEST);
 }