<?php
class ShipmentInvoicesController extends AppController {

	var $name = 'ShipmentInvoices';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->ShipmentInvoice->recursive = 0;
		$this->set('shipmentInvoices', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid ShipmentInvoice.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('shipmentInvoice', $this->ShipmentInvoice->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->ShipmentInvoice->create();
			if ($this->ShipmentInvoice->save($this->data)) {
				$this->Session->setFlash(__('The ShipmentInvoice has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The ShipmentInvoice could not be saved. Please, try again.', true));
			}
		}
		$shipments = $this->ShipmentInvoice->Shipment->find('list');
		$principles = $this->ShipmentInvoice->Principle->find('list');
		$currencies = $this->ShipmentInvoice->Currency->find('list');
		$freightForwarders = $this->ShipmentInvoice->FreightForwarder->find('list');
		$this->set(compact('shipments', 'principles', 'currencies', 'freightForwarders'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid ShipmentInvoice', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->ShipmentInvoice->save($this->data)) {
				$this->Session->setFlash(__('The ShipmentInvoice has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The ShipmentInvoice could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->ShipmentInvoice->read(null, $id);
		}
		$shipments = $this->ShipmentInvoice->Shipment->find('list');
		$principles = $this->ShipmentInvoice->Principle->find('list');
		$currencies = $this->ShipmentInvoice->Currency->find('list');
		$freightForwarders = $this->ShipmentInvoice->FreightForwarder->find('list');
		$this->set(compact('shipments','principles','currencies','freightForwarders'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for ShipmentInvoice', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->ShipmentInvoice->del($id)) {
			$this->Session->setFlash(__('ShipmentInvoice deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}

}
?>