/** * 获取供应商列表 * @param number $type * @return unknown */ public function getList($type = 0) { $sql = $this->select()->setIntegrityCheck(false)->from(array('t1' => $this->_name), array('id', 'tax_id', 'name' => new Zend_Db_Expr("concat(t1.code, ' ', case when t1.cname = '' then t1.ename else t1.cname end)"), 'currency_id' => 'bank_currency'))->joinLeft(array('t2' => $this->_dbprefix . 'erp_setting_currency'), "t1.bank_currency = t2.id", array('currency' => 't2.code'))->joinLeft(array('t3' => $this->_dbprefix . 'erp_setting_tax'), "t1.tax_id = t3.id", array('tax_name' => 'name'))->where("t1.type = " . $type)->order("t1.code"); $data = $this->fetchAll($sql)->toArray(); $taxRateModel = new Erp_Model_Setting_Taxrate(); for ($i = 0; $i < count($data); $i++) { $data[$i]['tax_rate'] = $taxRateModel->getCurrentRate($data[$i]['tax_id']); } return $data; }
public function getData($id = null) { $sql = $this->select()->setIntegrityCheck(false)->from(array('t1' => $this->_name))->joinLeft(array('t2' => $this->_dbprefix . 'user'), "t2.id = t1.create_user", array())->joinLeft(array('t3' => $this->_dbprefix . 'employee'), "t3.id = t2.employee_id", array('creater' => 'cname'))->joinLeft(array('t4' => $this->_dbprefix . 'user'), "t4.id = t1.update_user", array())->joinLeft(array('t5' => $this->_dbprefix . 'employee'), "t5.id = t4.employee_id", array('updater' => 'cname'))->order(array('CONVERT( t1.name USING gbk )')); if ($id) { $sql->where("t1.id = " . $id); $data = $this->fetchAll($sql)->toArray(); $rate = new Erp_Model_Setting_Taxrate(); $data[0]['rate'] = $rate->getCurrentRate($data[0]['id']); return $data[0]; } $data = $this->fetchAll($sql)->toArray(); $tax = new Erp_Model_Setting_Taxrate(); for ($i = 0; $i < count($data); $i++) { $data[$i]['create_time'] = strtotime($data[$i]['create_time']); $data[$i]['update_time'] = strtotime($data[$i]['update_time']); $data[$i]['active'] = $data[$i]['active'] == 1 ? true : false; $data[$i]['default'] = $data[$i]['default'] == 1 ? true : false; $data[$i]['current_rate'] = $tax->getCurrentRate($data[$i]['id']); } return $data; }
public function edittaxrateAction() { // 返回值数组 $result = array('success' => true, 'info' => '编辑成功'); $request = $this->getRequest()->getParams(); $tax_id = isset($request['tax_id']) ? $request['tax_id'] : null; if ($tax_id) { $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; $json = json_decode($request['json']); $updated = $json->updated; $inserted = $json->inserted; $deleted = $json->deleted; $tax_rate = new Erp_Model_Setting_Taxrate(); if (count($updated) > 0) { foreach ($updated as $val) { $val->date = substr($val->date, 0, 10); $data = array('date' => $val->date, 'rate' => $val->rate, 'remark' => $val->remark, 'update_time' => $now, 'update_user' => $user_id); if ($tax_rate->fetchAll("id != " . $val->id . " and tax_id = " . $tax_id . " and date = '" . $val->date . "'")->count() > 0) { $result['success'] = false; $result['info'] = '当前税率的生效日期[' . $val->date . ']已存在,请勿重复添加!'; } else { try { $tax_rate->update($data, "id = " . $val->id); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } } if (count($inserted) > 0) { foreach ($inserted as $val) { $val->date = substr($val->date, 0, 10); $data = array('tax_id' => $tax_id, 'date' => $val->date, 'rate' => $val->rate, 'remark' => $val->remark, 'create_time' => $now, 'create_user' => $user_id, 'update_time' => $now, 'update_user' => $user_id); if ($tax_rate->fetchAll("tax_id = " . $tax_id . " and date = '" . $val->date . "'")->count() > 0) { $result['success'] = false; $result['info'] = '当前税率的生效日期[' . $val->date . ']已存在,请勿重复添加!'; } else { try { $tax_rate->insert($data); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } } if (count($deleted) > 0) { foreach ($deleted as $val) { $val->date = substr($val->date, 0, 10); if (time() >= strtotime($val->date)) { $result['success'] = false; $result['info'] = '当前日期已超过[' . $val->date . '],不能删除!'; } else { try { $tax_rate->delete("id = " . $val->id); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } } } else { $result['success'] = false; $result['info'] = '保存失败,没有选择税种!'; } echo Zend_Json::encode($result); exit; }