LNO 101 :".date('dMY His')."$gsp_base_url";;
echo "
Basic Token : $gsp_access_token
";
echo "
API Token : $api_access_token
";
echo "
GSTIN: $co_gstin
";
echo "Contents :
";
echo '{
"action": "GENEWAYBILL",
"data": {
'.$doc_details.',
'.$from_details.',
'.$to_details.',
'.$txn_details.',
'.$value_details.',
'.$transporter_details.',
"itemList": ['.$item_data_details.']
}
}
';
}
//exit;
//Generate
/*
Here is a simpler code for the same:
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, $fp);
where $fp is a file handle to output errors. For example:
$fp = fopen(dirname(__FILE__).'/json_files/log/errorlog.txt', 'w');
*/
$fp = fopen(dirname(__FILE__).'/json_files/log/errorlog_'.time().'.txt', 'w');
$curl_3 = curl_init();
//$fp = tmpfile();
curl_setopt_array($curl_3, array(
CURLOPT_URL => $gsp_base_url.'/ewb/enc/v1.03/ewayapi',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_VERBOSE => 1,
CURLOPT_STDERR => $fp,
CURLOPT_POSTFIELDS =>'{
"action": "GENEWAYBILL",
"data": {
'.$doc_details.',
'.$from_details.',
'.$to_details.',
'.$txn_details.',
'.$value_details.',
'.$transporter_details.',
"itemList": ['.$item_data_details.']
}
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'gstin: '.$co_gstin.'',
'X-Connector-Auth-Token: l7xxba7aa16e968646b992298b377e955e7c:20180607093257:'.$co_gstin.'',
'action: GENEWAYBILL',
'Accept: application/json',
'Authorization: Bearer '.$api_access_token,
'X-Connector-Version: 1.2',
'X-Product-Version: 1.2'
),
));
// echo "Apit $api_access_token";
$response_3 = curl_exec($curl_3);
/*
fseek($fp, 0);
echo fread($fp, 32*1024); # output up to 32 KB cURL verbose log
fclose($fp);
*/
// var_dump($response_3);echo "
";
curl_close($curl_3);
$Jresponse_3=json_decode($response_3);
$ewb_status=$Jresponse_3->status;
// echo "$ewb_status
";
if($debug=='y'){
echo $response_3;
}
/*
{"data":{"ewayBillDate":"13/03/2022 06:15:00 PM","ewayBillNo":301002808907,"alert":"The distance between the given pincodes are not available in the system., ","validUpto":"14/03/2022 11:59:00 PM"},"status":"1"}
*/
if($ewb_status=='0'){
//ERROR
/*{"error":[{"errorCodes":"604","errorMsg":"E-way bill(s) are already generated for the same document number, you cannot generate again on same document number"}],"status":"0"}*/
$raw_error=$Jresponse_3->error;
$error_codes=$raw_error[0]->errorCodes;;
// echo "$error_codes
";
// if($error_codes=='604'){
// //already generated
// //echo $raw_error[0]->errorMsg;
// }
echo $raw_error[0]->errorMsg;
}elseif($ewb_status=='1'){
$data3=$Jresponse_3->data;
$ewb_no=$data3->ewayBillNo;
$ewb_date=$data3->ewayBillDate;
$ewb_valid=$data3->validUpto;
if($ewb_no!=""){
// $upd_sales_h="UPDATE [DC_H] SET []='',[]='', []='' WHERE [DOC_NO]='$inv_id'";
$q164="INSERT INTO [ewb_data] ([ewb_no],[ewb_date],[ewb_validity],[ewb_dtt],[inv_id],[inv_date],[inv_no],[tblprfx],[generate_dtt],[status],[doc_type]) VALUES ('$ewb_no','$ewb_date','$ewb_valid','".date('Y-m-d H:i:s')."','$inv_id','$inv_date_db','$inv_no_db','$tblprfx','".date('Y-m-d H:i:s')."','generated','DC')";
//echo "
Success : $q164;
";
$ins_ewb=sqlsrv_query($conn, $q164);
$q1521="UPDATE TOP (1) [DC_H] SET [EWB_NO]='$ewb_no',[EWB_DATE]='$ewb_date',[EWB_VALIDITY]='$ewb_valid' WHERE [DOC_NO]='$inv_id'";
$upd_salesH=sqlsrv_query($conn, $q1521);
//QRC Generation
include('php_qr_code/library/php_qr_code/qrlib.php'); // Include a library for PHP QR code
//its a location where generated QR code can be stored.
// $qr_code_file_path = dirname(__FILE__).DIRECTORY_SEPARATOR.'qr_image'.DIRECTORY_SEPARATOR;
// $set_qr_code_path = 'qr_image/ewb/dc/';
//its a location where generated QR code can be stored.
$set_qr_code_path = 'qr_image/ewb/dc/';
// $qr_code_file_path = dirname(__FILE__).DIRECTORY_SEPARATOR.'qr_image'.DIRECTORY_SEPARATOR;
$qr_code_file_path = dirname(__FILE__).DIRECTORY_SEPARATOR.$set_qr_code_path;
// If directory is not created, the create a new directory
if(!file_exists($qr_code_file_path)){
mkdir($qr_code_file_path);
}
//Set a file name of each generated QR code
$filename = $qr_code_file_path.$inv_id.'.png';
$errorCorrectionLevel = "L";
$matrixPointSize = 2;
$frm_link = $ewb_no;
QRcode::png($frm_link, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
//!QRC Generation
echo "Eway Bill No $ewb_no generated for DC No $inv_no_db. Valid till $ewb_valid";
echo "
QRCode Generated";
}else{
$q164="INSERT INTO [ewb_data] ([ewb_no],[ewb_date],[ewb_validity],[ewb_dtt],[inv_id],[inv_date],[inv_no],[tblprfx],[generate_dtt],[status],[doc_type]) VALUES ('$ewb_no','$ewb_date','$ewb_valid','".date('Y-m-d H:i:s')."','$inv_id','$inv_date_db','$inv_no_db','$tblprfx','".date('Y-m-d H:i:s')."','failed','DC')";
// echo "
$q164;
";
$ins_ewb=sqlsrv_query($conn, $q164);
echo "
Error in Eway Bill generation for DC No $inv_no_db. Try again or call administrator";
}
}
//INSERT INTO [ewb_data] ([ewb_no],[ewb_date],[ewb_validity],[ewb_dtt],[inv_id],[inv_date],[inv_no],[tblprfx],[generate_dtt],[status],[doc_type]) VALUES ('301002934257','06/07/2022 08:18:00 PM','08/07/2022 11:59:00 PM','2022-07-06 20:17:46','2','2020/09/29','PP/DC/2/20-21','','2022-07-06 20:17:46','generated','DC');
//$q152="UPDATE TOP (1) [DC_H] SET [EWB_NO]='301002934257',[EWB_DATE]='06/07/2022 08:18:00 PM',[EWB_VALIDITY]='08/07/2022 11:59:00 PM' WHERE [DOC_NO]='2'";
?>