支票付款 [英] Checking payment

查看:84
本文介绍了支票付款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于每笔付款,学生都可以接受培训.

For each payment, the student can follow a training.

例如,我为学生Menier的付款进行了编码.

For example, I encode a payment for the student Menier.

然后,我为学生Menier的培训编码.

Then, I encode a training for the student Menier.

是正确的!

现在,当我为同一个学生的另一笔付款进行编码时Menier

Now, when I encode another payment for the same student Menier

我无法添加培训,它正在阻止???

I can't add a training, it's blocking ???

在学生每次付款后如何将支票归零?

How to put to zero the checking, after each payment of the student?

$conflitpayment = Payment::where('fk_student', $request->get('fk_student'))
        ->whereDate('date_payment', ">" , $date_seance)
        ->first();

        if(isset($conflitpayment)){
            return redirect()->route('trainings.index')
                ->with('error', 'Payment! ');
        }

        $thisStudentsTrainings = Training::with(['payments' => function($query) use($fk_student){
        $query->where('fk_student', $fk_student);
        }])->get();

        $hasPaidForThisTraining = $thisStudentsTrainings ->contains('id', $request->get('fk_training'));



        if( count($thisStudentsTrainings) >= 1) { 
            return redirect()->route('trainings.index')
            ->with('error', 'No payment ! ');
        }



        else{
            Training::create($request->all());
                return redirect()->route('trainings.index')
                    ->with('success', 'Add');
        }

谢谢您的帮助.

控制器培训

public function store(Request $request)
    {
        $request->validate([
                'date_seance' => 'required',
                'hour_start' => 'required',
                'hour_end' => 'required',
                'fk_motorbike' => 'required',
                'fk_former' => 'required',
                'fk_student' => 'required',
                'fk_typeseance' => 'required'


        ]);


       $date_seance = $request->get('date_seance'); 
       $hour_start = $request->get('hour_start'); 
       $hour_end = $request->get('hour_end'); 
       $fk_motorbike = $request->get('fk_motorbike');
       $fk_student = $request->get('fk_student');
       $fk_former = $request->get('fk_former');
       $fk_typeseance = $request->get('fk_typeseance');

       $paiements = Payment::where('fk_student', $request->get('fk_student'))->first();

        if(!isset($paiements)){ 
            return redirect()->route('trainings.index')
                    ->with('error', 'No payment, no training!');
        }


        $conflitpayment = Payment::where('fk_student', $request->get('fk_student'))
        ->whereDate('date_payment', ">" , $date_seance)
        ->first();

        if(isset($conflitpayment)){
            return redirect()->route('trainings.index')
                ->with('error', 'Payment! ');
        }


        $PaymentHasBeenMadeForThisTraining = Payment::where('fk_student', $fk_student)  
        ->where('fk_training', $request->get('fk_training')) 
        ->first(); 

        $thisStudentsTrainings = Training::with(['payments' => function($query) use($fk_student){
        $query->where('fk_student', $fk_student);
        }])->get();

        $hasPaidForThisTraining = $thisStudentsTrainings->contains('id', $request->get('fk_training'));



        if( count($thisStudentsTrainings) >= 1) { 
            return redirect()->route('trainings.index')
            ->with('error', 'No payment ! ');
        }



        else{
            Training::create($request->all());
                return redirect()->route('trainings.index')
                    ->with('success', 'Add');
        }



    }

推荐答案

我不知道此控制器是什么,或它在喂食什么.但是,看来代码正在正确地执行与编写的代码相反的工作.看来是在阻止学生向已付款的培训添加付款.

I don't know what this controller is, or what is feeding it. But, it appears that the code is working correctly against what it is written to do. It looks to be blocking a student from adding a payment to a training that he has already paid for.

此行:

$hasPaidForThisTraining = $thisStudentsTrainings ->contains('id', $request->get('fk_training'));

查看学生接受的所有培训,然后检查从表单传递的培训ID是否与他要付费的培训ID相同.如果匹配,则阻止他付款.这似乎可行(尽管我不确定是否需要对$conflitpayment的第一个查询,或者它是否正确-但这不是这里的问题).我不明白的是,为什么在创建新培训的同一部分中要支票付款.检查多次付款的方法可能应该是创建付款方式,而不是培训-因为您要阻止多次付款,而不一定是培训.

Looks at all trainings that a student has, and then checks to see if the training id passed from the form is the same one that he is trying to pay for. If it is a match, then block him from making the payment. That seems to work (though I'm not sure about the very first query for $conflitpayment being needed or if it is correct - but that's not the issue here). What I don't understand is why there are checks for payments made in the same section as the creation of a new training. Checks for multiple payment should probably be in the payment creation method, not the training - since you are trying to block multiple payments, not necessarily trainings.

我怀疑可能正在发生的事情是,此添加新培训的表单正在通过 payment 表单运行.或者付款和培训表单正在通过在您的控制器中使用相同的方法.在IE中,表单上有一个fk_training字段,它带有一个值进入此方法.如果要创建新的培训,则该方法中不应包含fk_training字段.将付款的if-checks逻辑与创建新付款的逻辑分离为不同的方法,这应该可以解决您的问题.

What I suspect might be happening, is that this form for adding a new training is running through the payment form.. OR the payment and training forms are going through the same method in your controller. IE you have a field of fk_training on the form, and it is coming in to this method with a value. If you are creating a new training, you should not have a fk_training field in that method. Separate the logic of the if-checks on payments from the logic on creating a new payment into different methods and this should solve your problem.

如果此字段是通过表格填写的,并且是现有培训,即使是在付款方式上,也会阻止创建新培训.

If this field is coming through the form, and it is an existing training, even on the payment method, this will block the creation of a new training.

编辑

您在注释中指出为2项培训支付1项费用.在完成这2项培训后,我会再次支付".这与代码所做的非常不同.该代码先前检查过学生是否为特殊培训付费,如果是,则停止付款.您的评论背后的逻辑现在非常不同.并使代码更加复杂.

You note in the comments "1 payment for 2 trainings. After, the 2 trainings, I pay again." This is very different from what the code does. The code previously checked if a student paid for this particular training, and if so, stop the payment. The logic behind your comment is now very different. And makes the code more complicated.

要使其正常运行,您需要回答一些问题.首先,他们需要支付两次不同的培训费用吗?如果是这样,我们是否仍要阻止他们支付两次相同的培训费用?我认为是,这意味着$hasPaidForThisTraining检查是正确的.

There are some questions that you need to answer in order for this to work. First, they pay for two different trainings? If so, do we still want to prevent them from paying for the same training twice? I assume yes, which means the $hasPaidForThisTraining check is correct.

但是,如果不是,并且他们可以支付两次具有相同ID的培训费用,那么我们必须更改if-check来计数他有多少次支付相同的查询.现在,如果他们一次付款,它将失败.

But, if not, and they can pay for two trainings of the same ID, then we have to change the if-check to count how many times he has paid for the same query. Right now, it will fail if they paid ONCE.

if( count($thisStudentsTrainings) >= 1) { }  // CHANGE TO >=2

或者您可能想检查他们是否已经支付了两次培训费用并且已经到期? IE浏览器,他们现在需要再次付款?如果您直接在学生的培训中附加了付款,并且您只能为一项培训付费,这并不太难:

Or you might be wanting to check if they have paid for two trainings and those have expired? IE they now need to pay again? This is not too hard if you have a payment attached directly to the student's training and you can only pay for one training:

  $PaymentHasBeenMadeForThisTraining = Payment::where('fk_student', $fk_student)  
    ->where('fk_training', $request->get('fk_training')) 
    ->first(); 

您可以针对需要核实他们是否已付款的每次培训进行此操作.但是,这变得很复杂-如果您说他们可以为任何两次培训付费,然后如果他们接受了这些培训,那么他们需要再次付费.您需要先精简逻辑,然后才能进行编码.允许使用"付款的参数是什么?是根据日期吗?如果是这样,如果学生不参加该课程怎么办?您如何在代码中说明这一点?或者,如果他们花了一个钱又想买另外两个,该怎么办?他们可以这样做吗?如果可以,那么确定要支付第二笔款项的决心是什么?

You can do that for each training that you need to check if they have paid. However, where this gets complex - is if you are saying they can pay for any two trainings and then if they have taken those trainings, then they need to pay again. You will need to tighten the logic down before you can code it. What are the parameters that allow for a payment to be 'used'? Is it based on date? If so, what if the student didn't take the course? How do you account for that in the code? Or, what if they paid for one and want to buy two others? Can they do this, and if so, what is the determination to know that the second payment is made against?

我无法在代码中表示这一点,因为我无法理解所有规则,为了将其限制在代码中,您需要了解所有规则.我建议您简化这种方式.让您问题中的上述方法仅做一件事或两件事-也许检查一下是否已为所涉课程付款.然后再检查一下他们是否还有信用".

I can't represent this in code because I can't understand all the rules, which you need to know in order to constrain it in code. I suggest you simplify this way down. Let the method above in your question just do one or two things - maybe check to see if a payment has been made for the course in question. Then another check to see if they have 'credit' left.

我认为您永远不会使用这种方法来创建培训.如果有fk_training的外键(该键必须在此函数中,否则查询将失败),则已经存在可能无法通过if-check的培训.因此,它将永远不会像当前编码那样创建新的编码.建议您重新考虑本节的工作原理,并从新培训的 creation 中分离出付款支票.他们为这项培训支付了IE费用吗?是的,如果可以,他们是否有资格参加下一次培训?如果没有,请在表格上标记他们没有信用,然后才有机会进行培训.首先将付款作为一项单独的操作-然后在他们获得信用后再开始创建新的培训.

I don't think you will ever get to create a training in that method. If there is a foreign key for fk_training (which MUST be in this function or the queries will fail), there is ALREADY a training that may or may not hit the if-checks. So it will never create a new one as it is currently coded. I suggest you re-think how this section works, and separate out the payment checks from creation of a new training. IE did they pay for THIS training? OK, if so, do they have credit left for the NEXT training? If not, flag that they are out of credit on the form, before they are given a chance to create a training. Get the payment first as a separate action - then once they have credit, then allow for creation of a new training.

这甚至很难解释-我认为如果简化一下,您的生活就会轻松很多.以前,您可以按培训核对付款-一对一,并且根据这些规则可以正常工作.如果要允许两次付款,您要么需要制定复杂的规则...,要么只是将付款记为学生帐户的贷项,然后他们就可以根据系统中的贷项来选择课程.如果您的实际使用情况可以解决此问题,则简单得多.

This is hard to even explain - I think you will make your life a lot easier if you simplify this down. Previously you were OK to check payment against training - one to one, and that worked fine based on those rules. If you want to allow for 2 payments, you either need to come up with complex rules... OR just let the payment be a credit on the student account and they can take a course based on having credit in the system. Much simpler if your real world usage can handle this solution.

这篇关于支票付款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆