【问题标题】:Calculate total due in php codigniter在 php codeigniter 中计算到期总额
【发布时间】:2018-05-15 21:53:00
【问题描述】:

我有一个用 php CodeIgniter 编写的小型计费软件。这就是我在提交付款时保存价值的方式

    <?php
    public function addPayment() {

    $id = $this->input->post('id');
    $client_id = $this->input->post('client_id');
    $date = strtotime($this->input->post('date_from_addpayment'));
    $description = $this->input->post('description');
    $cash_pending = $this->input->post('cash_pending');
    $cash_recevied = $this->input->post('cash_recevied');

    $balance = $cash_pending - $cash_recevied;
    ?>

当每笔交易发生时,我想将当时客户的所有到期款项相加,并将其保存在 MySQL 的余额表中。 我的PHPMySQL支付栏结构如下:

https://i.stack.imgur.com/ELJrL.png

我只想当用户添加付款时,然后在此列中显示当时到期的余额。

截图:https://i.imgur.com/raboF4M.png

【问题讨论】:

  • 我看到你在做$due = $cash_pending - $cash_received,但语句末尾没有分号。其次,你$due = $cash_pending - $cash_received的结果是什么?
  • @YashKaranke 先生,如果我在 cash_pending 中放入 1000,在 cash_received 中放入 500,则 $due = 500。
  • 您的代码工作正常吗? $due 的输出是什么?
  • 因此您想将当前到期金额(上面的代码)添加到数据库中存储的到期金额中;而且我猜还要更改数据库中的现金待处理和收到的现金字段?

标签: php codeigniter billing


【解决方案1】:

首先,在结束 php 标记之前关闭函数的大括号。

在您的表中,id 是自动递增的,因此不需要将 id 作为输入来存储在数据库中。

像这样将所有必填字段作为您的表结构。

$data = array('client_id'=>$client_id, 'date'=>$date,

 'description'=>$description, 'cash_recevied'=>$cash_recevied, 'cash_pending'=>$cash_pending,

 'due'=>$due  );

$this->load->model('Your-model-name');

$this->your-model-name->function-name($data);

现在调用您的模型。然后在你的模型中这样做

function FunctionName($data){ 

return $this->db->insert('tablename', $data);

}

【讨论】:

    【解决方案2】:

    据我了解,余额、到期、cash_pending - 所有 3 个字段都相关 - 指的是同一个数字 - 待处理的金额。我相信你需要稍微重构一下代码。

    您需要有一张表来保持客户平衡(就像您现在的表一样)。只要你可以删除 cash_pending /到期字段。

    然后您需要有另一个表来记录所有收到的现金的交易。当收到现金时,您可以从客户的余额中减去该金额。

    如果需要为给付现金之类的东西添加任何超额金额 - 您可以将其添加到客户余额字段中。所以一直 - 你有一个适当的客户余额数字,也有从用户那里收到的所有现金的记录。

    【讨论】:

      猜你喜欢
      • 2023-04-07
      • 1970-01-01
      • 2020-11-14
      • 2012-11-29
      • 1970-01-01
      • 2023-03-23
      • 2019-08-22
      • 1970-01-01
      • 2020-11-28
      相关资源
      最近更新 更多