<?php

//
//// Retrieves Sales Invoice #5 (trans_no=5, type=13) in Array Format
//$trans_no = 5;
//$type = 13; // Sales Invoice
//$a = file_get_contents("http://localhost/frontaccounting/modules/api/sales/$trans_no/$type");
//header('Content-type: text/plain');
//header('Content-Disposition: attachment; filename="FA_Doc_' . $type . '_' . $trans_no . '.txt"');
//echo $a;
//
//$token = base64_encode("{$this->username}:{$this->password}");
$data = array(//'type' => 'bungalow',
    'category' => "Residential Rental Houses",
    'agentid' => "1",
    'location' => "Marurui",
    'longitude' => "111111",
    'latitude' => "1012301",
    'door_no' => "B20",
    'balcony' => TRUE,
    'bathrooms' => 1,
    'bedrooms' => 2,
    'floor' => 2,
    'rent_amount' => 15000,
    'amenities' => "Lift Available,Car Parking",
    'furnishings' => "",
    'size' => "",
    'goodwill' => "",
    'stock_value' => "",
    'period_in_business' => "",
    'profit' => "",
    'property_id' => "1",
    'file' => "image.png",
    'image_for' => "",
    'user_bio_id' => "4",
    'date' => "2019-08-16",
    'time' => "2019-08-16 06:40:33",
    'type' => "33",
    'status' => "0");

$data_string = json_encode($data);
$data_string = '{"delivery_address":"Cash Sales null","ref":"auto","bank":"","branch_id":"7","display_total":1,"payment":"1","dimension2_id":"","email":"","trans_type":"10","trans_no":0,"comments":"","sales_type":"1","due_date":"12/02/2020","deliver_to":"Cash Sales null","freight_cost":0,"order_date":"12/02/2020","phone":"","dimension_id":"0","deliver_date":"12/02/2020","ship_via":"1","sub_total":1,"location":"DEF","customer_id":7,"cust_ref":"","items":[{"is_taxed":0,"price":1,"qty":1,"discount":0,"description":"Vital Joto 2kg","stock_id":"10812280"}]}';
//$ch = curl_init('http://app.vacantroom.co.ke/modules/api/property/image?filename=property_95_imagefor_1&image_for=1&property_id=95');
//$ch = curl_init('http://localhost/frontaccounting/modules/api/property');
//$ch = curl_init('oshwal.oshwalaluminium.com/modules/api/hrm/clockin_clockout');
//$ch = curl_init('http://nyagah.liquibill.com/modules/api/sales/pospay');
//$ch = curl_init('https://nyagah.liquibill.com/modules/crm/CustMobilePaySaf/PaymentValidation.php?co=0&l=2&a=4@4%$45mj');
$ch = curl_init('https://localhost/frontaccounting/modules/api/inventory?category=6');
//$ch = curl_init('http://localhost/frontaccounting/reporting/prn_redirect.php?PARAM_0=10&PARAM_1=10&PARAM_2=&PARAM_3=0&PARAM_4=0&PARAM_5=&PARAM_6=0&REP_ID=109');
$ch = curl_init('https://localhost/frontaccounting/modules/api/sales/void/10/193');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Accept: application/json',
    'X-COMPANY:0',
    'X-USER:admin',
    'X-PASSWORD:qt12')
);
//curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Cookie: FAea2c25b156a4d770f5eb3b4a876d1c4a=maeian9j1bo54om1bdasepm8b7"));

//curl_setopt(
//    $ch,
//    CURLOPT_POSTFIELDS,
//    array(
//      'files' => '@' . realpath('upload.jpg')
//    ));

$result = curl_exec($ch);
echo $result;
/*
  Sample Output of Invoice indented for readability:

  {"ref":"auto",
  "comments":"Cash Sale",
  "order_date":"11\/14\/2017",
  "payment":"4",
  "payment_terms":{"0":"4",
  "terms_indicator":"4",
  "1":"Cash Only",
  "terms":"Cash Only",
  "2":"0",
  "days_before_due":"0",
  "3":"0",
  "day_in_following_month":"0",
  "4":"0",
  "inactive":"0",
  "5":"1",
  "cash_sale":"1"},
  "due_date":"11\/14\/2017",
  "phone":"",
  "cust_ref":"",
  "delivery_address":"N\/A",
  "ship_via":"1",
  "deliver_to":"Donald Easter LLC",
  "delivery_date":"11\/14\/2017",
  "location":"DEF",
  "freight_cost":"0",
  "email":"",
  "customer_id":"1",
  "branch_id":"1",
  "sales_type":"1",
  "dimension_id":"0",
  "dimension2_id":"0",
  "line_items":[
  {"id":"13",
  "stock_id":"102",
  "qty":2,
  "units":"each",
  "price":"250",
  "discount":"0",
  "description":"iPhone 6 64GB"},
  {"id":"14",
  "stock_id":"103",
  "qty":2,
  "units":"each",
  "price":"50",
  "discount":"0",
  "description":"iPhone Cover Case"}
  ],
  "sub_total":600,
  "display_total":600}
 */
?>
