<?php
/*
Couffin - A simple PHP shopping basket.
Copyright 2005 by Georges Auberger
http://www.auberger.com/couffin
Couffin is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Couffin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, you can find it here:
http://www.gnu.org/copyleft/gpl.html
*/
class invoice {
var $customer;
var $shippingAddress;
var $cart;
var $shipToBillingAddress;
var $dateCreated;
var $orderNumber;
var $taxManager;
var $shippingManager;
function invoice($taxManager, $shippingManager) {
$this->customer = new customer;
$this->cart = new cart;
$this->shippingAddress = new address;
$this->dateCreated = time();
$this->newOrderNumber();
$this->shipToBillingAddress=true;
$this->shippingAddress->country="USA";
$this->taxManager = $taxManager;
$this->shippingManager = $shippingManager;
}
function generateOrderNumber() {
$filename = "invoice-sequence";
$handle=fopen($filename,'r');
$sequence=fgets($handle);
$sequence = ($sequence == 0) ? 100 : $sequence+1;
fclose($handle);
$handle=fopen($filename,'w');
fwrite($handle,$sequence);
fclose($handle);
return $sequence;
}
function getDateCreated() {
return date("m/d/Y", $this->dateCreated);
}
function getSubTotal() {
return $this->cart->getTotalPrice();
}
function getTotal() {
return $this->cart->getTotalPrice() + $this->getTaxAmount() + $this->getShippingAmount();
}
function getTaxAmount() {
return $this->cart->getTotalPrice() * $this->getTaxRate();
}
function getShippingAmount() {
return $this->shippingManager->computeShipping($this->cart->getTotalWeight());
}
function getTaxRate() {
return $this->taxManager->getTaxRate($this->customer->billingAddress->state);
}
function getShippingMethod() {
return $this->shippingManager->getShippingMethod();
}
function validate() {
return $this->customer->validate() && $this->shippingAddress->validate();
}
function newOrderNumber() {
$this->orderNumber = $this->generateOrderNumber();
}
}
?>