function download_chips($guid, $clear = false) { $rows = db_getChipsByProj($guid); foreach ($rows as &$r) { unset($r['id']); } unset($r); $res[] = array('table' => 'chips', 'key' => 'qrcode', 'rows' => $rows, 'clear' => array('ProjGUID' => $guid)); $res[] = array('table' => 'bill', 'key' => 'BillGUID', 'rows' => db_getBills($guid), 'clear' => array('ProjGUID' => $guid)); $res[] = array('table' => 's_fee', 'key' => 'FeeGUID', 'rows' => db_getFees($guid), 'clear' => array('ProjGUID' => $guid)); $res[] = array('table' => 'p_cstattach', 'key' => 'CstAttachGUID', 'rows' => db_getCstAttach($guid), 'clear' => array('ProjGUID' => $guid)); $res[] = array('table' => 'p_customer', 'key' => 'CstGUID', 'rows' => db_getCustomers($guid)); $invoices = db_getInvoices($guid); $res[] = array('table' => 'p_invoice', 'key' => 'InvoGUID', 'rows' => $invoices, 'clear' => array('ProjGUID' => $guid), 'clearchild' => array('p_invoicedetail')); $InvoiceDetails = array(); foreach ($invoices as $i) { $InvoiceDetails = array_merge($InvoiceDetails, db_getInvoiceDetails($i['InvoGUID'])); } $res[] = array('table' => 'p_invoicedetail', 'key' => 'InvoDetailGUID', 'rows' => $InvoiceDetails); unset($invoices); return $res; }
/** * 导入票据明细及关系表 * 更新票据主表EndNo * @param $ */ function export_Invoice($projGUID, $progressFunc) { $res = array('total' => 0, 'update' => 0, 'failed' => 0); $invoKeys = array('InvoGUID', 'Invotype', 'BatchNo', 'Prefix', 'BgnNo', 'EndNo', 'Yzdw', 'Djr', 'DjDate', 'BuGUID', 'Remark', 'Application', 'signguid'); $detailKeys = array('InvoDetailGUID', 'InvoGUID', 'Invotype', 'InvoNO', 'Lyr', 'LyDate', 'Status', 'signguid'); $noteNo = function ($invo, $no) use(&$bgnNo, &$endNo) { $value = intval(str_replace($invo['Prefix'], '', $no)); if ($value > $endNo) { $endNo = $value; } if ($value < $bgnNo) { $bgnNo = $value; } }; $total = pdo_fetchcolumn('select count(*) from ' . tablename('p_invoicedetail') . ' where ErpSync=2'); $progress = 0; $index = 0; $showProgress = function () use(&$progress, $count, &$index, $progressFunc) { $index++; $value = intval($index * 5 / $count); if ($value > $progress) { $progress = $value; if (!empty($progressFunc)) { $progressFunc($value); } } }; $invoices = db_getInvoices($projGUID); foreach ($invoices as $invo) { $sql = 'select * from ' . tablename('p_invoicedetail') . ' where InvoGUID=:InvoGUID and ErpSync=2'; $details = pdo_fetchall($sql, array(':InvoGUID' => $invo['InvoGUID'])); $endNo = $invo['EndNo']; $bgnNo = $invo['BgnNo']; if (count($details) > 0) { $erp = MsSql()->fetch('select InvoGUID from p_Invoice ' . " where InvoGUID='{$invo['InvoGUID']}'"); if (empty($erp)) { MsSql()->insertObject('p_Invoice2Proj', array('InvoGUID' => $invo['InvoGUID'], 'ProjGUID' => $invo['ProjGUID'])); $invo['signguid'] = $projGUID; MsSql()->insertObject('p_Invoice', array_elements($invoKeys, $invo)); } foreach ($details as $d) { $showProgress(); $res['total']++; $noteNo($invo, $d['InvoNO']); $inserted = false; //检查是否存在? $data = MsSql()->fetch('select * from p_InvoiceDetail' . " where InvoDetailGUID='{$d['InvoDetailGUID']}'"); if (empty($data)) { $d['signguid'] = $projGUID; $inserted = MsSql()->insertObject('p_InvoiceDetail', array_elements($detailKeys, $d)); } else { //处理存在? } if ($inserted) { $res['update']++; } else { $res['failed']++; } pdo_update('p_invoicedetail', array('ErpSync' => 1), array('InvoDetailGUID' => $d['InvoDetailGUID'])); } $sql = "update p_Invoice set BgnNo={$bgnNo},EndNo={$endNo} where InvoGUID='{$invo['InvoGUID']}'"; MsSql()->query($sql); } } return $res; }