<?php

class Sale extends CI_Model {

	public function get_info($sale_id) {
		$this->db->from('sales');
		$this->db->where('sale_id', $sale_id);
		return $this->db->get();
	}

	function exists($sale_id) {
		$this->db->from('sales');
		$this->db->where('sale_id', $sale_id);
		$query = $this->db->get();

		return ($query->num_rows() == 1);
	}

	function update($sale_data, $sale_id) {
		$this->db->where('sale_id', $sale_id);
		$success = $this->db->update('sales', $sale_data);

		return $success;
	}

	function save($items, $customer_id, $employee_id, $comment, $payments, $sale_id = false, $receive_location, $location,$data) {

		if (count($items) == 0)
		return -1;

		//Alain Multiple payments
		//Build payment types string
		$payment_types = '';
		$current_due = 0;
		$current_use_point = 0;

		$total_receipt_amount=$data['final_due']+$data['total'];

		$return_amount=$data['grand_total']-$total_receipt_amount;


		if($data['final_due']<0){
			$payment_types = $payment_types . "Deduct Advance Payment: " . to_currency(abs($data['final_due'])) . '<br />';
		}
		if($data['final_due']>0){
			$payment_types = $payment_types . "Previous Due Payment: " . to_currency($data['final_due']) . '<br />';
		}

		foreach ($payments as $payment_id => $payment) {

			if ($payment['payment_type'] == "Due") {
				$current_due=$payment['payment_amount'];
				$payment_types = $payment_types . $payment['payment_type'] . ': ' . to_currency($payment['payment_amount']) . '<br />';
			}else{
				if($return_amount>0){
					if ($payment['payment_type'] == "Cash"){
						$payment_types = $payment_types . $payment['payment_type'] . ': ' . to_currency($payment['payment_amount']-$return_amount) . '<br />';
					}
				}

				if ($payment['payment_type'] == "User Point"){
					if($data['cart_point']>0){
						$payment_types = $payment_types . $payment['payment_type'] . ': ('.$data['cart_point'].'*'.$data['cart_point_value'].') '. to_currency($data['cart_point_cost']) . '<br />';
					}
				}else{
					$payment_types = $payment_types . $payment['payment_type'] . ': ' . to_currency($payment['payment_amount']) . '<br />';
				}
			}
		}


		if($data['mode']=="global"){
			if(trim($receive_location)==""){
				$receive_location=LOCATION_CODE;
			}
			$receipt_no=LOCATION_CODE.date("ymdHis")."GS";
		}else{
			if(trim($receive_location)==""){
				$receive_location=$location;
			}
			$receipt_no=LOCATION_CODE.date("ymdHis");
		}


		$this->db->set_dbprefix('ospos_');

		if($data['mode']=="global"){

			$sales_data = array(
			'sale_time' => date('Y-m-d H:i:s'),
			'customer_id' => $this->Customer->exists($customer_id) ? $customer_id : null,
			'employee_id' => $employee_id,
			'payment_type' => $payment_types,
			'comment' => $comment,
			'receive_location' => $receive_location,
			'location' => $location,
			'receipt_no' => $receipt_no,
			'acc_location' => LOCATION_CODE,
			'is_global' => 1,
			'bag_big'=>$_POST['bag_big'],
			'bag_medium'=>$_POST['bag_medium'],
			'bag_small'=>$_POST['bag_small']
			);

			$this->db->insert('sales', $sales_data);
			$sale_id = $this->db->insert_id();

		}else{

			if(trim($location)==""){
				$location=LOCATION_CODE;
			}
			$sales_data = array(
			'sale_time' => date('Y-m-d H:i:s'),
			'customer_id' => $this->Customer->exists($customer_id) ? $customer_id : null,
			'employee_id' => $employee_id,
			'payment_type' => $payment_types,
			'comment' => $comment,
			'receive_location' => $receive_location,
			'location' => $location,
			'receipt_no' => $receipt_no,
			'acc_location' => $location,
			'bag_big'=>$_POST['bag_big'],
			'bag_medium'=>$_POST['bag_medium'],
			'bag_small'=>$_POST['bag_small']
			);
			
			$this->db->insert('sales', $sales_data);
			$sale_id = $this->db->insert_id();

		}

		$tax_array=$this->sale_lib->get_taxes();

		foreach ($items as $line => $item) {

			$item_discount=0;
			$total_discount=0;


			$item_discount=0;

			if($item['discount']>0){
				$item_discount=($item['price']*$item['discount'])/100;
				//$total_discount=($item['price']*$item['quantity']*$item['discount'])/100;
			}


			$vat_amount_shawpon=((($item['price']-$item_discount)*$item['quantity'])*$item['vat_rate'])/100;
			$total_sale_amount_shawpon=($item['price']-$item_discount)*$item['quantity'];
			$total_sale_amount_with_vat_shawpon=$item['price_with_vat']*$item['quantity'];

			$total_discount=$total_sale_amount_with_vat_shawpon-$total_sale_amount_shawpon-$vat_amount_shawpon;



			$sales_items_data = array(
			'sale_id' => $sale_id,
			'stock_id' => $item['item_id'],
			'description' => $item['name'],
			'lot_no' => $item['lot_no'],
			'line' => $item['line'],
			'quantity_purchased' => $item['quantity'],
			'item_cost_price' => $item['price'],
			'item_unit_price' => $item['price']-$item_discount,
			'discount_percent' => $item['discount'],
			'total_discount' => $total_discount,
			'total_sale_amount' => $total_sale_amount_shawpon,
			'vat_enable_price' => ($item['price']-$item_discount)*$item['quantity'],
			'vat_percentage' => $item['vat_rate'],
			'vat_amount' => $vat_amount_shawpon
			);

			$this->db->insert('sales_items', $sales_items_data);
		}
		if($data['final_due']<0){
			$sales_payments_data = array
			(
			'sale_id' => $sale_id,
			'payment_type' => 'Deduct Advance Payment',
			'payment_amount' => abs($data['final_due'])
			);
			$this->db->insert('sales_payments', $sales_payments_data);

		}

		foreach ($payments as $payment_id => $payment) {

			if ($payment['payment_type'] == 'User Point') {
				if($data['cart_point_cost']>0){
					$sales_payments_data = array
					(
					'sale_id' => $sale_id,
					'payment_type' => $payment['payment_type'],
					'payment_amount' => $data['cart_point_cost']
					);
					$this->db->insert('sales_payments', $sales_payments_data);
				}
			}
			if ($payment['payment_type'] == 'Due') {
				$sales_payments_data = array
				(
				'sale_id' => $sale_id,
				'payment_type' => $payment['payment_type'],
				'payment_amount' => $payment['payment_amount']
				);
				$this->db->insert('sales_payments', $sales_payments_data);
			}
			if ($payment['payment_type'] == 'Purchase Bunus') {
				$sales_payments_data = array
				(
				'sale_id' => $sale_id,
				'payment_type' => $payment['payment_type'],
				'payment_amount' => $payment['payment_amount']
				);
				$this->db->insert('sales_payments', $sales_payments_data);
			}

			if ($payment['payment_type'] == 'Credit Card') {
				$sales_payments_data = array
				(
				'sale_id' => $sale_id,
				'payment_type' => $payment['payment_type'],
				'payment_amount' => $payment['payment_amount'],
				'bank_id' => $payment['bank_name_credit'],
				'card_no' => $payment['card_no_credit'],
				'account_holder_name' => $payment['holder_name_credit'],
				'credit_card_expire_month' => $payment['card_expire_month'],
				'credit_card_expire_year' => $payment['card_expire_year']
				);
				$this->db->insert('sales_payments', $sales_payments_data);
			}

			if ($payment['payment_type'] == 'Debit Card') {

				$sales_payments_data = array
				(
				'sale_id' => $sale_id,
				'payment_type' => $payment['payment_type'],
				'payment_amount' => $payment['payment_amount'],
				'bank_id' => $payment['bank_name_debit'],
				'card_no' => $payment['card_no_debit'],
				'account_holder_name' => $payment['holder_name_debit']
				);

				$this->db->insert('sales_payments', $sales_payments_data);
			}

			if ($payment['payment_type'] == 'Check') {

				$sales_payments_data = array
				(
				'sale_id' => $sale_id,
				'payment_type' => $payment['payment_type'],
				'payment_amount' => $payment['payment_amount'],
				'branch_name' => $payment['branch_name_check'],
				'bank_id' => $payment['bank_name_check'],
				'account_no' => $payment['ac_no_check'],
				'account_holder_name' => $payment['holder_name_check'],
				'check_no' => $payment['card_expire_month'],
				'check_date' => $payment['check_date']
				);

				$this->db->insert('sales_payments', $sales_payments_data);
			}

			//
			if ($payment['payment_type'] == 'Cash') {

				$sales_payments_data = array
				(
				'sale_id' => $sale_id,
				'payment_type' => $payment['payment_type'],
				'payment_amount' => $payment['payment_amount']
				);

				$this->db->insert('sales_payments', $sales_payments_data);
			}

		}
		$this->db->trans_complete();

		
		/////////////////////////////////////////////////////////////Temporary Block:SHAWPON//////////////////////////////////////////
		
		
		$this->db->trans_start();
		$this->db->set_dbprefix('');
		
		
		/*	Sync into live database	*/
		$query_item = $this->db->query("
                    SELECT *
                    FROM ospos_sales
					WHERE sale_id='".$sale_id."' AND location='".$location."' AND is_sync=0");

		$sale_time="";
		$receipt_no_ref="";

		foreach ($query_item->result() as $row) {

			$sales_data = array(
			'sale_time' => $row->sale_time,
			'customer_id' =>  $row->customer_id,
			'employee_id' => $row->employee_id,
			'payment_type' => $row->payment_type,
			'comment' => $row->comment,
			'receive_location' => $row->receive_location,
			'location' => $row->location,
			'receipt_no' =>$row->receipt_no,
			'acc_location' => $row->acc_location,
			'is_global' => $row->is_global,
			'is_delivered' => $row->is_delivered,
			'bag_big'=>$row->bag_big,
			'bag_medium'=>$row->bag_medium,
			'bag_small'=>$row->bag_small
			);

			$sale_time=$row->sale_time;
			$receipt_no_ref=$row->receipt_no;
			$this->db->insert('pos_ospos_sales', $sales_data);
			$sale_id_live = $this->db->insert_id();
		}

		$query_item_details = $this->db->query("
                    SELECT *
                    FROM ospos_sales_items
					WHERE sale_id='".$sale_id."'");

		foreach ($query_item_details->result() as $row) {

			$sales_items_data = array(
			'sale_id' => $sale_id_live,
			'stock_id' => $row->stock_id,
			'description' => $row->description,
			'lot_no' => $row->lot_no,
			'line' => $row->line,
			'quantity_purchased' => $row->quantity_purchased,
			'item_cost_price' => $row->item_cost_price,
			'item_unit_price' => $row->item_unit_price,
			'discount_percent' => $row->discount_percent,
			'total_discount' => $row->total_discount,
			'total_sale_amount' => $row->total_sale_amount,
			'vat_enable_price' => $row->vat_enable_price,
			'vat_percentage' => $row->vat_percentage,
			'vat_amount' => $row->vat_amount
			);

			$this->db->insert('pos_ospos_sales_items', $sales_items_data);

			$query_moves = $this->db->query("SELECT a.*
					FROM stock_moves AS a
					WHERE a.stock_id='".mysql_real_escape_string($row->stock_id)."' AND a.lot_no='".mysql_real_escape_string($row->lot_no)."' GROUP BY a.stock_id,a.lot_no");

			$stock_moves_lot_data=$query_moves->row();



			$stock_moves_data = array(
			'trans_no' => $sale_id_live,
			'stock_id' => $stock_moves_lot_data->stock_id,
			'type' => 201,
			'loc_code' => $location,
			'tran_date' => $sale_time,
			'person_id' => $sale_id_live,
			'price' => $stock_moves_lot_data->price,
			'reference' => $receipt_no_ref,
			'qty' => -$row->quantity_purchased,
			'discount_percent' => $row->discount_percent,
			'standard_cost' => $stock_moves_lot_data->standard_cost,
			'visible' => $stock_moves_lot_data->visible,
			'lot_no' => $row->lot_no,
			'is_imported' => $stock_moves_lot_data->is_imported,
			'swatch_code' => $stock_moves_lot_data->swatch_code
			);
			$this->db->insert('stock_moves', $stock_moves_data);
			/*	VAT Account	*/
			$query_coa = $this->db->query("SELECT d.sales_gl_code AS vat_account,a.inventory_account,a.sales_account
					FROM stock_master AS a
					LEFT JOIN item_tax_type_exemptions AS c ON c.item_tax_type_id=a.tax_type_id
					LEFT JOIN tax_types AS d ON c.tax_type_id=d.id
					WHERE a.stock_id='".mysql_real_escape_string($row->stock_id)."'");

			$coa=$query_coa->row();

			if($row->discount_percent>0){
				$query_discount = $this->db->query("SELECT * FROM sys_prefs WHERE name='default_sales_discount_act'");
				$discount_account=$query_discount->row();
			}


			$gl_trans_data_inventory_account = array(
			'type' => 201,
			'type_no' => $sale_id_live,
			'tran_date' => $sale_time,
			'account' => $coa->inventory_account,
			'memo_' => $receipt_no_ref,
			'amount' => -($row->total_discount+$row->total_sale_amount+$row->vat_amount),
			'person_type_id' => 201,
			'person_id' => $sale_id_live
			);

			$this->db->insert('gl_trans', $gl_trans_data_inventory_account);


			$gl_trans_data_sales_account = array(
			'type' => 201,
			'type_no' => $sale_id_live,
			'tran_date' => $sale_time,
			'account' => $coa->sales_account,
			'memo_' => $receipt_no_ref,
			'amount' => $row->total_sale_amount,
			'person_type_id' => 201,
			'person_id' => $sale_id_live
			);

			$this->db->insert('gl_trans', $gl_trans_data_sales_account);


			$gl_trans_data_vat_account = array(
			'type' => 201,
			'type_no' => $sale_id_live,
			'tran_date' => $sale_time,
			'account' => $coa->vat_account,
			'memo_' => $receipt_no_ref,
			'amount' => $row->vat_amount,
			'person_type_id' => 201,
			'person_id' => $sale_id_live
			);

			$this->db->insert('gl_trans', $gl_trans_data_vat_account);


			if($row->discount_percent>0){


				$gl_trans_data_default_sales_discount_act= array(
				'type' => 201,
				'type_no' => $sale_id_live,
				'tran_date' => $sale_time,
				'account' => $discount_account->value,
				'memo_' => $receipt_no_ref,
				'amount' => $row->total_discount,
				'person_type_id' => 201,
				'person_id' => $sale_id_live
				);
				$this->db->insert('gl_trans', $gl_trans_data_default_sales_discount_act);
			}
		}

		$query_sales_payments = $this->db->query("
                    SELECT *
                    FROM ospos_sales_payments
					WHERE sale_id='".$sale_id."'");

		foreach ($query_sales_payments->result() as $row) {
			$this->db->set_dbprefix('');
			$sales_items_payment_data = array(
			'sale_id' => $sale_id_live,
			'payment_type' => $row->payment_type,
			'payment_amount' => $row->payment_amount,
			'bank_id' => $row->bank_id,
			'branch_name' => $row->branch_name,
			'account_holder_name' => $row->account_holder_name,
			'account_no' => $row->account_no,
			'card_no' => $row->card_no,
			'check_no' => $row->check_no,
			'check_date' => $row->check_date,
			'credit_card_expire_month' => $row->credit_card_expire_month,
			'credit_card_expire_year' => $row->credit_card_expire_year
			);

			$this->db->insert('pos_ospos_sales_payments', $sales_items_payment_data);

			/*		PARMENT TRANS	*/

		}
		$this->db->where('receipt_no', $receipt_no);
		$this->db->update('ospos_sales', array('is_sync' => 1));

		$this->db->set_dbprefix('ospos_');

		$this->db->trans_complete();

		$return_array['receipt_no']=$receipt_no;
		$return_array['sale_id']=$sale_id;

		return $return_array;
	}

	function delete($sale_id) {
		//Run these queries as a transaction, we want to make sure we do all or nothing
		$this->db->trans_start();

		$this->db->delete('sales_payments', array('sale_id' => $sale_id));
		$this->db->delete('sales_items_taxes', array('sale_id' => $sale_id));
		$this->db->delete('sales_items', array('sale_id' => $sale_id));
		$this->db->delete('sales', array('sale_id' => $sale_id));

		$this->db->trans_complete();

		return $this->db->trans_status();
	}

	function get_sale_items($sale_id) {
		$this->db->from('sales_items');
		$this->db->where('sale_id', $sale_id);
		return $this->db->get();
	}
	function get_sale_items_by_receive_id_local($sale_id) {
		$this->db->from('sales_items');
		$this->db->where('sale_id', $sale_id);
		return $this->db->get();
	}

	function get_sale_items_by_receive_id_live($sale_id) {

		$this->db->set_dbprefix('');
		$this->db->from('pos_ospos_sales_items');
		$this->db->where('sale_id', $sale_id);
		$return_data=array();
		$return_data=$this->db->get();
		$this->db->set_dbprefix('ospos_');
		return $return_data;
	}

	function get_sale_payments($sale_id) {
		$this->db->from('sales_payments');
		$this->db->where('sale_id', $sale_id);
		return $this->db->get();
	}

	function get_customer($sale_id) {
		$this->db->from('sales');
		$this->db->where('sale_id', $sale_id);
		return $this->Customer->get_info($this->db->get()->row()->customer_id);
	}

	function get_customer_local($sale_id) {
		$this->db->from('sales');
		$this->db->where('sale_id', $sale_id);
		return $this->Customer->get_info($this->db->get()->row()->customer_id);
	}
	function get_customer_server($sale_id) {
		$this->db->set_dbprefix('');
		$this->db->from('pos_ospos_sales');
		$this->db->where('sale_id', $sale_id);
		$customer_info=$this->Customer->get_info($this->db->get()->row()->customer_id);
		$this->db->set_dbprefix('ospos_');
		return $customer_info;
	}

	//We create a temp table that allows us to do easy report/sales queries
	public function create_sales_items_temp_table() {
		$this->db->query("CREATE TEMPORARY TABLE " . $this->db->dbprefix('sales_items_temp') . "
		(SELECT date(sale_time) as sale_date, " . $this->db->dbprefix('sales_items') . ".sale_id, comment,payment_type, customer_id, employee_id, 
		" . $this->db->dbprefix('items') . ".item_id, supplier_id, quantity_purchased, item_cost_price, item_unit_price, SUM(percent) as item_tax_percent,
		discount_percent, (item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100) as subtotal,
		" . $this->db->dbprefix('sales_items') . ".line as line, " . $this->db->dbprefix('sales_items') . ".description as description,
		ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)*(1+(SUM(percent)/100)),2) as total,
		ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)*(SUM(percent)/100),2) as tax,
		(item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100) - (item_cost_price*quantity_purchased) as profit
		FROM " . $this->db->dbprefix('sales_items') . "
		INNER JOIN " . $this->db->dbprefix('sales') . " ON  " . $this->db->dbprefix('sales_items') . '.sale_id=' . $this->db->dbprefix('sales') . '.sale_id' . "
		INNER JOIN " . $this->db->dbprefix('items') . " ON  " . $this->db->dbprefix('sales_items') . '.stock_id=' . $this->db->dbprefix('items') . '.item_id' . "
		LEFT OUTER JOIN " . $this->db->dbprefix('suppliers') . " ON  " . $this->db->dbprefix('items') . '.supplier_id=' . $this->db->dbprefix('suppliers') . '.person_id' . "
		LEFT OUTER JOIN " . $this->db->dbprefix('sales_items_taxes') . " ON  "
		. $this->db->dbprefix('sales_items') . '.sale_id=' . $this->db->dbprefix('sales_items_taxes') . '.sale_id' . " and "
		. $this->db->dbprefix('sales_items') . '.stock_id=' . $this->db->dbprefix('sales_items_taxes') . '.item_id' . " and "
		. $this->db->dbprefix('sales_items') . '.line=' . $this->db->dbprefix('sales_items_taxes') . '.line' . "
		GROUP BY sale_id, stock_id, line)");

		//Update null item_tax_percents to be 0 instead of null
		$this->db->where('item_tax_percent IS NULL');
		$this->db->update('sales_items_temp', array('item_tax_percent' => 0));

		//Update null tax to be 0 instead of null
		$this->db->where('tax IS NULL');
		$this->db->update('sales_items_temp', array('tax' => 0));

		//Update null subtotals to be equal to the total as these don't have tax
		$this->db->query('UPDATE ' . $this->db->dbprefix('sales_items_temp') . ' SET total=subtotal WHERE total IS NULL');
	}

	public function get_giftcard_value($giftcardNumber) {
		if (!$this->Giftcard->exists($this->Giftcard->get_giftcard_id($giftcardNumber)))
		return 0;

		$this->db->from('giftcards');
		$this->db->where('giftcard_number', $giftcardNumber);
		return $this->db->get()->row()->value;
	}

	function insert_user_points($table, $data) {
		$this->db->insert($table, $data);
		return $this->db->insert_id();
	}

	function get_value($column, $table, $where = '') {
		$this->db->select($column);
		$this->db->from($table);
		if ($where) {
			foreach ($where as $key => $val) {
				$this->db->where($key, $val);
			}
		}

		$query = $this->db->get();
		if ($query->num_rows() > 0) {
			return $query->row();
		} else {
			return FALSE;
		}
		$query->free_result();
	}

	function insert_data($table, $data) {
		$this->db->insert($table, $data);
		return $this->db->insert_id();
	}
	function update_data($table, $data, $where)
	{
		$res = $this->db->update($table, $data, $where);
		if ($res) {
			return true;
		} else {
			return false;
		}
	}

	function getPointCost() {
		$this->db->select('value');
		$this->db->from('app_config');
		$this->db->where('key', 'point_per_sell');
		$query = $this->db->get();
		if ($query->num_rows() > 0) {
			return $query->row();
		} else {
			return FALSE;
		}
		$query->free_result();
	}

	public function get_sale_by_invoice_number($invoice_number) {
		$this->db->from('sales');
		$this->db->where('sale_id', $invoice_number);

		return $this->db->get();
	}

	public function get_sale_by_invoice_number_shawpon_local($invoice_number) {
		$this->db->from('sales');
		$this->db->where('receipt_no', $invoice_number);
		return $this->db->get();
	}
	public function get_sale_by_invoice_number_shawpon_server($invoice_number) {
		$this->db->set_dbprefix('');
		$this->db->from('pos_ospos_sales');
		$this->db->where('receipt_no', $invoice_number);
		$return_data=$this->db->get();
		$this->db->set_dbprefix('ospos_');
		return $return_data;
	}

	public function get_global_items($sale_id){
		$this->db->select('*');
		$this->db->from('sales');
		$this->db->where('sales.sale_id', $sale_id);
		$this->db->where('sales.receive_location', 0);
		$this->db->join('sales_items', 'sales.sale_id = sales_items.sale_id','INNER');

		$query = $this->db->get();
		if ($query->num_rows() > 0) {
			return $query->result();
		} else {
			return FALSE;
		}
		$query->free_result();
	}


	public function get_global_items_shawpon($sale_id){

		$query = $this->db->query("
                    SELECT a.*,b.*,CONCAT(c.first_name,' ',c.last_name) AS customer_name,c.phone_number,c.previous_due,
                    d.description AS item_description,e.size AS item_size
                    ,f.description AS category_description
FROM ospos_sales AS a
INNER JOIN ospos_sales_items AS b ON a.sale_id=b.sale_id
LEFT JOIN pos_ospos_customers AS c ON a.customer_id=c.id
LEFT JOIN stock_master AS d ON b.stock_id=d.stock_id
LEFT JOIN stock_category AS f ON d.category_id=f.category_id
LEFT JOIN pos_item_sizes AS e ON d.item_size_id=e.id
WHERE a.receipt_no='".$sale_id."' AND a.receive_location='".LOCATION_CODE."' AND a.is_global=1 AND is_delivered=0");


		if ($query->num_rows() > 0) {
			return $query->result();
		} else {
			return FALSE;
		}
		$query->free_result();
	}


	public function get_sale_payments_data_shawpon($sale_id)
	{
		$this->db->from('sales_payments');
		$this->db->where('sale_id',$sale_id);
		return $this->db->get();
	}

	public function update_delivery_global($receipt_no,$bag_big,$bag_medium,$bag_small)
	{
		$this->db->where('receipt_no', $receipt_no);
		$success = $this->db->update('ospos_sales', array('is_delivered' => 1,'bag_big' => $bag_big,'bag_medium' => $bag_medium,'bag_small' => $bag_small));
		return $success;
	}

}

?>
