<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type');
require_once('../lib/dbclass.php');

extract($_POST);
$data   = $_REQUEST;
$ids    = $_REQUEST['id'];
$amount = $_REQUEST['amount'];

unset($data['id']);


$datay = findQuery('SELECT * FROM tbl_challenge WHERE status=0 AND CURDATE() between challenge_startdate and challenge_enddate');

if ($data['item'] == 1) {
    $data['Totqty'] = $data['qty'] * $datay[0]['productconversion1'];
} elseif ($data['item'] == 2) {
    $data['Totqty'] = $data['qty'] * $datay[0]['productconversion2'];
} else {
    $data['Totqty'] = $data['qty'] * $datay[0]['productconversion3'];
}

$id = saveArray('tbl_transactiondetails', $data, 0);






//updateQuery("update tbl_transactiondetails set Totqty=qty where item=2");
//updateQuery("update tbl_transactiondetails set Totqty=qty where item!=2");

if ($id > 0) {
    $datasy = findQuery("SELECT * FROM tbl_transaction WHERE id=$ids");

    if ($datasy) {
        if ($datasy[0]['Received'] > 0) {
            updateQuery("update tbl_transaction set Amount=$amount,Received=$amount where id=$ids");
        } else {
            updateQuery("update tbl_transaction set Amount=$amount,Received=0 where id=$ids");
        }
    }


    $message = 'True';
    $data2   = $id;
} else {
    $message = 'False';
    $data2   = 0;
}

echo json_encode(['Status' => $message, 'data' => $data2]);








return;
?>	   


