Php Quickbooks-选择发票的所有付款
我正在尝试使用ConsoleByte quickbooks php工具包查询分配给发票的所有付款。我希望我可以使用查询将这些内容拉回来,但到目前为止,我能看到的唯一方法是抓取所有付款,然后循环检查LinkedTxn数组中的内容,并检查它是否具有“发票”类型,以及“TxnId”值是否与我存储的发票id匹配。到目前为止,我所拥有的是这样一种方法,即获取付款,但这显然不是一个未来的选择,因为系统中可能有成千上万的付款:Php Quickbooks-选择发票的所有付款,php,quickbooks,quickbooks-online,Php,Quickbooks,Quickbooks Online,我正在尝试使用ConsoleByte quickbooks php工具包查询分配给发票的所有付款。我希望我可以使用查询将这些内容拉回来,但到目前为止,我能看到的唯一方法是抓取所有付款,然后循环检查LinkedTxn数组中的内容,并检查它是否具有“发票”类型,以及“TxnId”值是否与我存储的发票id匹配。到目前为止,我所拥有的是这样一种方法,即获取付款,但这显然不是一个未来的选择,因为系统中可能有成千上万的付款: public function getAllPaymentsForInvoice(
public function getAllPaymentsForInvoice(Invoice $invoice)
{
$query = "SELECT * FROM Payment";
$payments = $this->qbPaymentService->query($this->context, $this->realm, $query);
$lines = [];
foreach ($payments as $payment) {
$num_lines = $payment->countLine();
for ($i = 0; $i < $num_lines; $i++) {
$line = $payment->getLine($i);
$txnId = $this->parseResponse($line->getLinkedTxn()->getTxnId());// convert {-1} to 1
$txnType = $line->getLinkedTxn()->getTxnType();
if ($txnType == 'Invoice' && $txnId == $invoice->qb_ref) {
$lines[] = $line;
}
}
}
return $lines;
}
公共函数getAllPaymentsForInvoice(发票$Invoice)
{
$query=“从付款中选择*”;
$payments=$this->qbPaymentService->query($this->context,$this->realm,$query);
$lines=[];
foreach($payment作为$payment支付){
$num_line=$payment->countLine();
对于($i=0;$i<$num_行;$i++){
$line=$payment->getLine($i);
$txnId=$this->parseResponse($line->getLinkedTxn()->getTxnId());//将{-1}转换为1
$txnType=$line->getLinkedTxn()->getTxnType();
如果($txnType=='Invoice'&&$txnId===$Invoice->qb_ref){
$line[]=$line;
}
}
}
返回$line;
}
有谁能帮我找到更好的方法吗?使用QuickBooks Online API实现这一点没有简单、简单的方法。这并不是QuickBooks Online本身所支持的 您可以采用两种不同的方法来优化所做的工作
SELECT*FROM Payment,其中CustomerRef='xyz'
其中xyz
是发票中的CustomerRef
。然后,使用您现有的代码精确地检查应用于哪些发票付款->cdc(…)
方法的日期/时间,您可以不断获得自上次查询以来已更改的任何对象的轻量级更新
<?php
$CDCService = new QuickBooks_IPP_Service_ChangeDataCapture();
// What types of objects do you want to get?
$objects = array(
'Payment',
'Invoice',
);
// The date they should have been updated after
$timestamp = QuickBooks_Utilities::datetime($datetime_you_last_called_cdc_method);
$cdc = $CDCService->cdc($Context, $realm,
$objects,
$timestamp);
// You would cache all the stuff you get back here
print_r($cdc);
无论如何,这个问题已经很老了,以防有人在寻找答案:
$InvoiceService = new QuickBooks_IPP_Service_Invoice();
// $invoices = $InvoiceService->query($Context, $realm, "SELECT * FROM Invoice STARTPOSITION 1 MAXRESULTS 10");
// If, we have QB Invoice # i.e.DocNumber
$invoice_no = 1001;
$invoices = $InvoiceService->query($Context, $realm, "SELECT * FROM Invoice WHERE DocNumber = '$invoice_no' ");
foreach ($invoices as $Invoice)
{
$txnId = 0;
if (is_object($Invoice->getLinkedTxn()) && $Invoice->getLinkedTxn()->getTxnType() == 'Payment') {
$txnId = $Invoice->getLinkedTxn()->getTxnId();
}
print('Invoice # '.$Invoice->getDocNumber().' has a total of $'.$Invoice->getTotalAmt().' and Linked Payment ID: ' . $txnId . "\n");
}
嗨,基思。只是刚刚注意到你已经发布了答案。到目前为止,我已经使用了一种解决方案,涉及从发票中获取链接的交易,对它们进行内爆,然后在付款表上查询ID位于字符串中的付款。e、 g:“从Id位于(“.”的付款中选择*。内爆(“,”,$PaymentId)。“)”。其中,$PaymentId已预处理,以从发票中获取所有链接的交易记录。这似乎是我需要的。对你来说,这似乎是一个好的解决方案吗?这个带有“IN(…)”的解决方案非常好,在我看来,应该是一个公认的答案