示例#1
0
<?php

require_once 'app/master.php';
$master = Master::getInstance();
include 'index.php';
 function SaveOrder($abv, $amt, $total, $surcharge)
 {
     $db = Master::getInstance();
     $mysqli = $db->getConnection();
     $res = $mysqli->query("select id, name, rates, surchage from fcurrency where abreviation = '{$abv}'");
     $row = $res->fetch_assoc();
     $fCurrencyID = $row['id'];
     $name = $row['name'];
     $surchageAmount = $surcharge;
     $r = $mysqli->query("insert into purchase_order (amount_purchased, amount_to_be_paid, amount_surcharged, date_created, fcurrency_id) values ('{$amt}', '{$total}', '{$surchageAmount}', NOW(), '{$fCurrencyID}')");
     $n = $mysqli->affected_rows;
     if ($n == 1) {
         $orderID = $mysqli->insert_id;
         if ($abv == "GBP") {
             $message = "Foreign Currency purchased: " . $name . "\n Amount Purchased = " . $amt . "\n Amount to pay in ZAR = " . $total . "\n";
             $db->sendMail($message);
         }
         if ($abv == "EUR") {
             $afterDiscount = $total - $total * 0.02;
             $results = $mysqli->query("update purchase_order set after_discount = {$afterDiscount} where id = '{$orderID}'");
         }
         return TRUE;
     }
     return FALSE;
 }