<?php
namespace FAAPI;

class Sales {
	// Get Items
	public function get($rest, $trans_type)
	{
		$req = $rest->request();
		include_once (API_ROOT . "/sales.inc");

		$page = $req->get("page");

		if ($page == null) {
			sales_all($trans_type);
		} else {
			// If page = 1 the value will be 0, if page = 2 the value will be 1, ...
			$from = -- $page * RESULTS_PER_PAGE;
			sales_all($trans_type, $from);
		}
	}
        
        public function get_payments($rest)
	{
		$req = $rest->request();
		include_once (API_ROOT . "/sales.inc");

		$page = $req->get("page");

		if ($page == null) {
                    payments_all();
		} else {
			// If page = 1 the value will be 0, if page = 2 the value will be 1, ...
			$from = -- $page * RESULTS_PER_PAGE;
			payments_all($from);
		}
	}
        
        // Get Specific payment by Id
	public function getPayamentById($rest, $trans_no, $trans_type) {
		include_once (API_ROOT . "/sales.inc");
		payment_get($trans_no, $trans_type);
	}
        
        // Get Specific payment by Id
	public function getMpesaUnallocatedPayments($rest) {
		include_once (API_ROOT . "/sales.inc");
		mpesa_unallocated_payments();
	}

	// Get Specific Item by Id
	public function getById($rest, $trans_no, $trans_type) {
		include_once (API_ROOT . "/sales.inc");
		sales_get($trans_no, $trans_type);
	}

	// Add Item
	public function post($rest) {
		include_once (API_ROOT . "/sales.inc");
		sales_add();
	}
        
        // Add Item
	public function post_pos($rest) {
		include_once (API_ROOT . "/sales.inc");
		pos_add();
	}
        
        // order2invoice
	public function order2invoice($rest) {
		include_once (API_ROOT . "/sales.inc");
		order2invoice();
	}
        
        // Add Item
	public function post_pay($rest) {
		include_once (API_ROOT . "/sales.inc");
		pos_pay();
	}

	// Edit Specific Item
	public function put($rest, $trans_no, $trans_type) {
		include_once (API_ROOT . "/sales.inc");
		sales_edit($trans_no, $trans_type);
	}

	// Delete Specific Item
	public function delete($rest, $trans_type, $trans_no) {
		include_once (API_ROOT . "/sales.inc");
		sales_cancel($trans_type, $trans_no);
	}
}