我使用此代码从tally erp 9.0获取数据
<?php
$requestXML = '<ENVELOPE>'.
'<HEADER>'.
'<TALLYREQUEST>Export Data</TALLYREQUEST>'.
'</HEADER>'.
'<BODY>'.
'<EXPORTDATA>'.
'<REQUESTDESC>'.
'<REPORTNAME>Daybook</REPORTNAME>'.
'<STATICVARIABLES>'.
'<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>'.
'</STATICVARIABLES>'.
'</REQUESTDESC>'.
'</EXPORTDATA>'.
'</BODY>'.
'</ENVELOPE>';
$server = 'LOCALHOST:9000';
$headers = array( "Content-type: text/xml","Content-length:".strlen($requestXML) ,"Connection: close");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $server);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXML);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
if(curl_errno($ch)){
print curl_error($ch);
echo " something went wrong..... try later";
}else{
echo " request accepted";
print $data;
curl_close($ch);
}
但我的问题是如何使用php(curl)将数据推送(插入)到Tally ERP 9.0。
答案 0 :(得分:1)
而不是
$ server ='LOCALHOST:9000';
给
$ server = '10 .0.0.155:9000';
答案 1 :(得分:1)
使用tally生成xml格式,并使用相同的格式将数据插回到tally中,例如。 创建销售凭证,从理货中获取xml 即
GatewayOfTAlly - &gt;展示广告 - &gt;帐户图书 - &gt;销售登记 - &gt; chhose month - &gt; ctl + E导出凭证,
现在你有了xml格式,你很高兴。
答案 2 :(得分:1)
而不是
$server = 'LOCALHOST:9000';
使用
$server = 'http://localhost:9000';
答案 3 :(得分:0)
<form action="" method="post">
<table width="100%" border="1">
<tr>
<th scope="col">Name</th>
<td><input name="nm" id="nm" type="text" /></td>
</tr>
<tr>
<td colspan="4"><div align="center">
<label>
<input type="submit" name="sub" value="Submit" />
</label>
</div></td>
</tr>
</table>
</form>
<?php
/* This is PHP code to insert an entry in Tally. All required XML tags by Tally are taken here in a string and name for Ledger is taken by posted value from HTML form. */
if(isset($_POST['sub']))
{
$name = $_POST['nm'];
$requestXML = '<?xml version="1.0"?>
<ENVELOPE>
<HEADER>
<TALLYREQUEST>Import Data</TALLYREQUEST>
</HEADER>
<BODY>
<IMPORTDATA>
<REQUESTDESC>
<REPORTNAME>Vouchers</REPORTNAME>
<STATICVARIABLES>
<SVCURRENTCOMPANY>SAVH</SVCURRENTCOMPANY>
</STATICVARIABLES>
</REQUESTDESC>
<REQUESTDATA>
<TALLYMESSAGE xmlns:UDF="TallyUDF">
<VOUCHER REMOTEID="123" VCHTYPE="Receipt" VCHKEY="321" ACTION="Create" OBJVIEW="Accounting Voucher View">
<OLDAUDITENTRIES.LIST> </OLDAUDITENTRIES.LIST>
<ACCOUNTAUDITENTRIES.LIST> </ACCOUNTAUDITENTRIES.LIST>
<AUDITENTRIES.LIST> </AUDITENTRIES.LIST>
<OLDAUDITENTRYIDS.LIST TYPE="Number">
<OLDAUDITENTRYIDS>-1</OLDAUDITENTRYIDS>
</OLDAUDITENTRYIDS.LIST>
<DATE>20130401</DATE>
<GUID>f6c10ce3-4a15-42b8-961e-143a512a9e62-00000009</GUID>
<VOUCHERTYPENAME>Receipt</VOUCHERTYPENAME>
<VOUCHERNUMBER>5</VOUCHERNUMBER>
<PARTYLEDGERNAME>'.$name.'</PARTYLEDGERNAME>
<CSTFORMISSUETYPE/>
<CSTFORMRECVTYPE/>
<FBTPAYMENTTYPE>Default</FBTPAYMENTTYPE>
<PERSISTEDVIEW>Accounting Voucher View</PERSISTEDVIEW>
<VCHGSTCLASS/>
<DIFFACTUALQTY>No</DIFFACTUALQTY>
<AUDITED>No</AUDITED>
<FORJOBCOSTING>No</FORJOBCOSTING>
<ISOPTIONAL>No</ISOPTIONAL>
<EFFECTIVEDATE>20130401</EFFECTIVEDATE>
<ISFORJOBWORKIN>No</ISFORJOBWORKIN>
<ALLOWCONSUMPTION>No</ALLOWCONSUMPTION>
<USEFORINTEREST>No</USEFORINTEREST>
<USEFORGAINLOSS>No</USEFORGAINLOSS>
<USEFORGODOWNTRANSFER>No</USEFORGODOWNTRANSFER>
<USEFORCOMPOUND>No</USEFORCOMPOUND>
<ALTERID>20</ALTERID>
<EXCISEOPENING>No</EXCISEOPENING>
<USEFORFINALPRODUCTION>No</USEFORFINALPRODUCTION>
<ISCANCELLED>No</ISCANCELLED>
<HASCASHFLOW>Yes</HASCASHFLOW>
<ISPOSTDATED>No</ISPOSTDATED>
<USETRACKINGNUMBER>No</USETRACKINGNUMBER>
<ISINVOICE>No</ISINVOICE>
<MFGJOURNAL>No</MFGJOURNAL>
<HASDISCOUNTS>No</HASDISCOUNTS>
<ASPAYSLIP>No</ASPAYSLIP>
<ISCOSTCENTRE>No</ISCOSTCENTRE>
<ISSTXNONREALIZEDVCH>No</ISSTXNONREALIZEDVCH>
<ISEXCISEMANUFACTURERON>No</ISEXCISEMANUFACTURERON>
<ISBLANKCHEQUE>No</ISBLANKCHEQUE>
<ISDELETED>No</ISDELETED>
<ASORIGINAL>No</ASORIGINAL>
<VCHISFROMSYNC>No</VCHISFROMSYNC>
<MASTERID>9</MASTERID>
<VOUCHERKEY>177657027231784</VOUCHERKEY>
<INVOICEDELNOTES.LIST> </INVOICEDELNOTES.LIST>
<INVOICEORDERLIST.LIST> </INVOICEORDERLIST.LIST>
<INVOICEINDENTLIST.LIST> </INVOICEINDENTLIST.LIST>
<ATTENDANCEENTRIES.LIST> </ATTENDANCEENTRIES.LIST>
<ORIGINVOICEDETAILS.LIST> </ORIGINVOICEDETAILS.LIST>
<INVOICEEXPORTLIST.LIST> </INVOICEEXPORTLIST.LIST>
<ALLLEDGERENTRIES.LIST>
<AMOUNT>200000.00</AMOUNT>
<OLDAUDITENTRYIDS.LIST TYPE="Number">
<OLDAUDITENTRYIDS>-1</OLDAUDITENTRYIDS>
</OLDAUDITENTRYIDS.LIST>
<LEDGERNAME>'.$name.'</LEDGERNAME>
<GSTCLASS/>
<ISDEEMEDPOSITIVE>No</ISDEEMEDPOSITIVE>
<LEDGERFROMITEM>No</LEDGERFROMITEM>
<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>
<ISPARTYLEDGER>Yes</ISPARTYLEDGER>
<ISLASTDEEMEDPOSITIVE>No</ISLASTDEEMEDPOSITIVE>
<BANKALLOCATIONS.LIST></BANKALLOCATIONS.LIST>
<BILLALLOCATIONS.LIST></BILLALLOCATIONS.LIST>
<INTERESTCOLLECTION.LIST></INTERESTCOLLECTION.LIST>
<OLDAUDITENTRIES.LIST></OLDAUDITENTRIES.LIST>
<ACCOUNTAUDITENTRIES.LIST></ACCOUNTAUDITENTRIES.LIST>
<AUDITENTRIES.LIST></AUDITENTRIES.LIST>
<TAXBILLALLOCATIONS.LIST></TAXBILLALLOCATIONS.LIST>
<TAXOBJECTALLOCATIONS.LIST></TAXOBJECTALLOCATIONS.LIST>
<TDSEXPENSEALLOCATIONS.LIST></TDSEXPENSEALLOCATIONS.LIST>
<VATSTATUTORYDETAILS.LIST></VATSTATUTORYDETAILS.LIST>
<COSTTRACKALLOCATIONS.LIST></COSTTRACKALLOCATIONS.LIST>
</ALLLEDGERENTRIES.LIST>
<ALLLEDGERENTRIES.LIST>
<OLDAUDITENTRYIDS.LIST TYPE="Number">
<OLDAUDITENTRYIDS>-1</OLDAUDITENTRYIDS>
</OLDAUDITENTRYIDS.LIST>
<LEDGERNAME>Bank of Maharashtra</LEDGERNAME>
<GSTCLASS/>
<ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>
<LEDGERFROMITEM>No</LEDGERFROMITEM>
<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>
<ISPARTYLEDGER>Yes</ISPARTYLEDGER>
<ISLASTDEEMEDPOSITIVE>Yes</ISLASTDEEMEDPOSITIVE>
<AMOUNT>-200000.00</AMOUNT>
<BANKALLOCATIONS.LIST>
<DATE>20130401</DATE>
<INSTRUMENTDATE>20130401</INSTRUMENTDATE>
<BANKBRANCHNAME>Warje</BANKBRANCHNAME>
<TRANSACTIONTYPE>Cheque/DD</TRANSACTIONTYPE>
<BANKNAME>AXIS</BANKNAME>
<PAYMENTFAVOURING>'.$name.'</PAYMENTFAVOURING>
<INSTRUMENTNUMBER>50026</INSTRUMENTNUMBER>
<UNIQUEREFERENCENUMBER>38ROUrdV00QEKOhl</UNIQUEREFERENCENUMBER>
<STATUS>No</STATUS>
<CHEQUEPRINTED>-1</CHEQUEPRINTED>
<AMOUNT>-200000.00</AMOUNT>
</BANKALLOCATIONS.LIST>
<BILLALLOCATIONS.LIST></BILLALLOCATIONS.LIST>
<INTERESTCOLLECTION.LIST></INTERESTCOLLECTION.LIST>
<OLDAUDITENTRIES.LIST></OLDAUDITENTRIES.LIST>
<ACCOUNTAUDITENTRIES.LIST></ACCOUNTAUDITENTRIES.LIST>
<AUDITENTRIES.LIST></AUDITENTRIES.LIST>
<TAXBILLALLOCATIONS.LIST></TAXBILLALLOCATIONS.LIST>
<TAXOBJECTALLOCATIONS.LIST></TAXOBJECTALLOCATIONS.LIST>
<TDSEXPENSEALLOCATIONS.LIST></TDSEXPENSEALLOCATIONS.LIST>
<VATSTATUTORYDETAILS.LIST> </VATSTATUTORYDETAILS.LIST>
<COSTTRACKALLOCATIONS.LIST> </COSTTRACKALLOCATIONS.LIST>
</ALLLEDGERENTRIES.LIST>
<ATTDRECORDS.LIST> </ATTDRECORDS.LIST>
</VOUCHER>
</TALLYMESSAGE>
<TALLYMESSAGE xmlns:UDF="TallyUDF">
<COMPANY>
<REMOTECMPINFO.LIST MERGE="Yes">
<NAME>12</NAME>
<REMOTECMPNAME>SAVH</REMOTECMPNAME>
<REMOTECMPSTATE>Maharashtra</REMOTECMPSTATE>
</REMOTECMPINFO.LIST>
<REMOTECMPINFO.LIST MERGE="Yes">
<NAME>f6c10ce3-4a15-42b8-961e-143a512a9e62</NAME>
<REMOTECMPNAME>SAVH</REMOTECMPNAME>
<REMOTECMPSTATE>Maharashtra</REMOTECMPSTATE>
</REMOTECMPINFO.LIST>
</COMPANY>
</TALLYMESSAGE>
<TALLYMESSAGE xmlns:UDF="TallyUDF">
<COMPANY>
<REMOTECMPINFO.LIST MERGE="Yes">
<NAME>12</NAME>
<REMOTECMPNAME>SAVH</REMOTECMPNAME>
<REMOTECMPSTATE>Maharashtra</REMOTECMPSTATE>
</REMOTECMPINFO.LIST>
<REMOTECMPINFO.LIST MERGE="Yes">
<NAME>f6c10ce3-4a15-42b8-961e-143a512a9e62</NAME>
<REMOTECMPNAME>SAVH</REMOTECMPNAME>
<REMOTECMPSTATE>Maharashtra</REMOTECMPSTATE>
</REMOTECMPINFO.LIST>
</COMPANY>
</TALLYMESSAGE>
</REQUESTDATA>
</IMPORTDATA>
</BODY>
</ENVELOPE>';
/* Actual code for importing goes here */
$server = 'http://localhost:9000';
$headers = array( "Content-type: text/xml" ,"Content-length: ".strlen($requestXML) ,"Connection: close" );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $server);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXML);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
if(curl_errno($ch))
{
print curl_error($ch);
echo " something went wrong..... try later";
}
else
{
echo " request accepted";
print $data;
curl_close($ch);
}
}
?>
试试这个,它会起作用.... 给你的端口在“$ server”中,这是一个配置....
答案 4 :(得分:0)
<?php
if(count($_POST)) {
$group_name = strtoupper($_POST['group_name']);
$item_name = $_POST['item_name'];
/*$opening_balance = $_POST['opening_balance'];
$opening_value = $_POST['opening_value'];
$opening_rate = $opening_value * $opening_balance;*/
$res_str =<<<XML
<ENVELOPE>
<HEADER>
<TALLYREQUEST>Import Data</TALLYREQUEST>
</HEADER>
<BODY>
<IMPORTDATA>
<REQUESTDESC>
<REPORTNAME>All Masters</REPORTNAME>
</REQUESTDESC>
<REQUESTDATA>
<!-- Create Stock Group named "$group_name" -->
<TALLYMESSAGE xmlns:UDF="TallyUDF">
<STOCKGROUP NAME="{$group_name}" ACTION="Create">
<NAME.LIST>
<NAME>{$group_name}</NAME>
</NAME.LIST>
<PARENT/>
<ISADDABLE>Yes</ISADDABLE>
</STOCKGROUP>
</TALLYMESSAGE>
<!-- Create Stock Item named "$item_name" -->
<TALLYMESSAGE xmlns:UDF="TallyUDF">
<STOCKITEM NAME="{$item_name}" ACTION="Create">
<NAME.LIST>
<NAME>{$item_name}</NAME>
</NAME.LIST>
<PARENT>{$group_name}</PARENT>
<BATCHALLOCATIONS.LIST>
<NAME>Primary Batch</NAME>
<BATCHNAME>Primary Batch</BATCHNAME>
<GODOWNNAME>Main Location</GODOWNNAME>
<MFDON>20190120</MFDON>
<OPENINGBALANCE>0.000 NOS</OPENINGBALANCE>
<OPENINGVALUE>0.000</OPENINGVALUE>
<OPENINGRATE>0.000/NOS</OPENINGRATE>
</BATCHALLOCATIONS.LIST>
</STOCKITEM>
</TALLYMESSAGE>
</REQUESTDATA>
</IMPORTDATA>
</BODY>
</ENVELOPE>
XML;
//var_dump($res_str);die;
$url = "http://localhost:8000/";
//setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// Following line is compulsary to add as it is:
curl_setopt($ch, CURLOPT_POSTFIELDS,
"xmlRequest=" . $res_str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
$data = curl_exec($ch);
if(curl_errno($ch)){
var_dump($data);
} else {
$msg = $data;
}
curl_close($ch);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Tally</title>
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="col-md-6 col-md-offset-3" style="margin-top:20px">
<?php if(isset($msg) && $msg) :?>
<div class="alert alert-success" role="alert"><?=$msg?></div>
<?php endif;?>
<div class="pull-left"><a href="export.php">Item List</a> | </div>
<div class="pull-left"><a href="stockGroupItem.php">Create StockGroup Item</a> | </div>
<div class="pull-left"><a href="ledger.php">Create Ledger</a> | </div>
<hr>
<form class="form-horizontal" method="post" action="">
<div class="form-group">
<label for="group-name" class="col-sm-4 control-label">Stock Group name</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="group-name" placeholder="Stock Group name" name="group_name">
</div>
</div>
<div class="form-group">
<label for="item-name" class="col-sm-4 control-label">Stock Item name</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="item-name" placeholder="Stock Item name" name="item_name" required>
</div>
</div>
<!-- <div class="form-group">
<label for="opening_balance" class="col-sm-4 control-label">Quantity</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="opening_balance" placeholder="Item Quantity" name="opening_balance" required>
</div>
</div>
<div class="form-group">
<label for="opening_value" class="col-sm-4 control-label">Unit Price</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="opening_value" placeholder="Item Unit Price" name="opening_value" required>
</div>
</div> -->
<div class="form-group">
<div class="col-sm-offset-4 col-sm-6">
<button type="submit" class="btn btn-primary">Insert</button>
</div>
</div>
</form>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>