public function refreshInvoiceTotal($invoice_id) { $invoiceData = array('total' => 0, 'total_tax' => 0, 'total_no_tax' => 0, 'forein_total' => 0, 'forein_total_tax' => 0, 'forein_total_no_tax' => 0); if ($invoice_id) { $dataTmp = $this->fetchAll("invoice_id = " . $invoice_id); if ($dataTmp->count() > 0) { $items = $dataTmp->toArray(); foreach ($items as $item) { $data = array('total' => 0, 'total_tax' => 0, 'total_no_tax' => 0, 'forein_total' => 0, 'forein_total_tax' => 0, 'forein_total_no_tax' => 0); if ($item['currency_rate'] == 1) { // 本币 $data['total'] = $item['price'] * $item['qty']; if ($item['price_tax'] == 1) { // 价格含税 $data['total_no_tax'] = $data['total'] / (1 + $item['tax_rate']); $data['total_tax'] = $data['total'] - $data['total_no_tax']; } else { // 价格不含税 $data['total_no_tax'] = $data['total']; $data['total_tax'] = $data['total'] * $item['tax_rate']; $data['total'] = $data['total_no_tax'] + $data['total_tax']; } } else { // 外币 $data['forein_total'] = $item['price'] * $item['qty']; if ($item['price_tax'] == 1) { // 价格含税 $data['forein_total_no_tax'] = $data['total'] / (1 + $item['tax_rate']); $data['forein_total_tax'] = $data['total'] - $data['forein_total_no_tax']; } else { // 价格不含税 $data['forein_total_no_tax'] = $data['forein_total']; $data['forein_total_tax'] = $data['forein_total'] * $item['tax_rate']; $data['forein_total'] = $data['forein_total_no_tax'] + $data['forein_total_tax']; } } $this->update($data, "id = " . $item['id']); $invoiceData['total'] += $data['total']; $invoiceData['total_tax'] += $data['total_tax']; $invoiceData['total_no_tax'] += $data['total_no_tax']; $invoiceData['forein_total'] += $data['forein_total']; $invoiceData['forein_total_tax'] += $data['forein_total_tax']; $invoiceData['forein_total_no_tax'] += $data['forein_total_no_tax']; } } } $invoice = new Erp_Model_Purchse_Invoice(); $invoice->update($invoiceData, "id = " . $invoice_id); }
public function editattachAction() { $result = array('success' => true, 'info' => '上传成功'); $request = $this->getRequest()->getParams(); $invoice_id = isset($request['invoice_id']) ? $request['invoice_id'] : null; //$remark = isset($request['attach_remark']) ? $request['attach_remark'] : null; if ($invoice_id && isset($_FILES['attach_file'])) { $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; $file = $_FILES['attach_file']; $file_name = $file['name']; $file_extension = strrchr($file_name, "."); $h = new Application_Model_Helpers(); $tmp_file_name = $h->getMicrotimeStr() . $file_extension; $savepath = "../upload/files/" . date('Y-m-d') . '/'; if (!is_dir($savepath)) { mkdir($savepath); // 目录不存在则创建目录 } $tmp_file_path = $savepath . $tmp_file_name; move_uploaded_file($file["tmp_name"], $tmp_file_path); $invoice = new Erp_Model_Purchse_Invoice(); $invoiceData = $invoice->getData(null, $invoice_id); if ($invoiceData['attach_path'] != '' && file_exists($invoiceData['attach_path'])) { unlink($invoiceData['attach_path']); } $invoiceData = array('attach_name' => $file_name, 'attach_path' => $tmp_file_path, 'update_user' => $user_id, 'update_time' => $now); $invoice->update($invoiceData, "id = " . $invoice_id); } echo Zend_Json::encode($result); exit; }