建造合同会计分录 - 代码示例和解释
建造合同会计分录代码示例
本示例代码演示了如何使用 PHP 代码实现建造合同的会计分录,包括收入、支出、预算等方面的记录和管理。
class ContractAccount {
// 添加记录
public function addrecord($data) {
try {
//添加收入信息
$d = array(
'type' => 1,
'name' => $data['name'],
'money' => $data['money'],
'ctime' => time(),
'cid' => $data['cid'],
'uid' => $data['uid'],
'status' => '1',
);
$this->add($d);
//添加财务信息
$d2 = array(
'type' => 2,
'name' => $data['name'],
'money' => $data['money'],
'ctime' => time(),
'cid' => $data['cid'],
'uid' => $data['uid'],
'status' => '1',
);
$this->add($d2);
$this->commit();
return true;
} catch (Exception $e) {
$this->rollback();
return false;
}
}
//获取支出记录
public function getpaylist($cid) {
$condition = array(
'cid' => $cid,
'status' => '1',
'type' => '2',
);
return $this->where($condition)->select();
}
//获取收入记录
public function getincomelist($cid) {
$condition = array(
'cid' => $cid,
'status' => '1',
'type' => '1',
);
return $this->where($condition)->select();
}
//添加预算记录
public function addbudget($data) {
$d = array(
'name' => '预算',
'money' => $data['budget'],
'ctime' => time(),
'cid' => $data['cid'],
'uid' => $data['uid'],
'status' => '1',
'type' => '1',
);
return $this->add($d);
}
//更新预算
public function updatebudget($data) {
$condition = array(
'cid' => $data['cid'],
'name' => '预算',
'type' => '1',
);
$d = array(
'money' => $data['budget'],
'utime' => time(),
);
return $this->where($condition)->save($d);
}
//获取预算
public function getbudget($cid) {
$condition = array(
'cid' => $cid,
'name' => '预算',
'status' => '1',
'type' => '1',
);
return $this->where($condition)->getField('money');
}
//根据id获取记录
public function getrecordbyid($id) {
$condition = array(
'id' => $id,
'status' => '1',
);
return $this->where($condition)->find();
}
//修改记录
public function saverecord($data) {
$condition = array(
'id' => $data['id'],
'status' => '1',
);
$d = array(
'name' => $data['name'],
'money' => $data['money'],
'utime' => time(),
);
return $this->where($condition)->save($d);
}
//删除记录
public function deleterecord($id) {
$condition = array(
'id' => $id,
'status' => '1',
);
$d = array(
'status' => '0',
);
return $this->where($condition)->save($d);
}
}
代码解析:
- addrecord() 函数: 添加收入和支出记录,分别用
type为1和2表示。 - getpaylist() 函数: 获取指定合同的支出记录。
- getincomelist() 函数: 获取指定合同的收入记录。
- addbudget() 函数: 添加预算记录。
- updatebudget() 函数: 更新预算记录。
- getbudget() 函数: 获取指定合同的预算。
- getrecordbyid() 函数: 根据 ID 获取记录。
- saverecord() 函数: 修改记录。
- deleterecord() 函数: 删除记录。
注意: 以上代码仅为示例,实际应用中需根据具体情况进行修改和完善。
本示例代码仅供参考,实际应用中需要根据具体情况进行调整和完善。
原文地址: https://www.cveoy.top/t/topic/lfTL 著作权归作者所有。请勿转载和采集!