Okay so let's say I have
A balance of $6.00 created from a credit.
An invoice of $12.00 created by an admin.
You subtract the invoice amount from the balance and get a total of $-6.00
How would you subtract the two until you reach $0.00 to figure out the amount taken from the balance to pay the invoice.
So you would get that the balance paid for was a total of $6.00 and the client still owes $6.00
My PHP code is as follows for this predicament!
if($balance >= $due)
{
$amount = $due;
}
else
{
$amount = $due - $balance;
}
if($balance > '0')
{
$data = array(
'invoice_id' => $invoice_id,
'balance_pay' => '1',
'amount' =>
);
$this->payment->create($data);
}
UPDATE
I'm just trying to figure out how much is still owed on the invoice. If I don't figure this out, because of how my application is set-up, it will display that the total invoice was paid when really only half of it was paid.
This is a VERY simple problem, that has needlessly been complicated, which often happens. Just need to take a step back rather than getting deeper into the problem (if that is even possible) and further complicatingn the issue.
Firstly, you don't have to subtract to reach $0.00.
In the most general case, the amount of current credit balance could be negative (customer currently owes you money), 0 (customer does not owe you any money currently), or positive (you currently owe customer money). But the actual calculation is the same in all three cases. Let the current credit balance for the customer be x.
Now you wish to generate an invoice. Let this invoice amount be y. (I assume that y will always be positive, but doesn't really matter.)
Then, z = x - y is the new credit balance for the customer:
If z < 0: customer did not have enough credit balance to pay off the new invoice. Customer still needs to pay z.
If z = 0: customer had just enough credit balance to completely pay off the new invoice, and the new credit balance is 0.
If z > 0: customer had more than enough credit to pay off the new invoice, and the new credit balance is z.
It's just straightforward addition/subtraction, needlessly complicated in your head by credit/debit/plus/minus signs, with the added confusion resulting from wanting to balance to zero when you really don't have to.
Related
I am working on a project where the subscriber can limit his subscription on monthly basis.
As an example below
Lets say i have 5 products A - Euro 40 ,B - Euro 40, C - Euro 40, D- Euro 40,E - Euro 40
Month 1 - A + B + C + D -> First order. I am using stripe ideal to generate the payment for 4 products. Total Euro 160
Month 2 - Subscriber cancels product D subscription. So now the recursive payment must work only for the price of A+B+C. So now the total comes Euro 120
Month 3 - Subscriber cancels product C subscription. So now the recursive payment must work only for the price of A+B. So now the total comes Euro 80
Month 4 - Subscriber cancels product A + B subscription. So the subscription should be cancelled.
Work done till now:
The stripe ideal is only one time payment. In this case, i can use SEPA but will get the update 14-16 working days.
https://stripe.com/docs/sources/ideal/recurring
I am using wordpress and initiating the ideal payment programatically (not using plugin) using Stripe PHP library.
What is the alternative i can go for iDEAL?
Is it possible, if i collect the card details of the customer and charge the card on recurring basis without user authorization.
Hope i made my question clear.
I'm admittedly not particularly learned in this world, but Stripe does have some guidance here:
https://stripe.com/docs/sources/ideal/recurring
Basically, you have to turn it into a SEPA Direct Debit source, then every month inform your customer of what they're going to owe. Hopefully that's helpful!
If we are using 100% discount voucher code and price gets 0 and needs to be processed via Stripe how can we do it? Or via subscriptions that are free how to do it?
The minimum value for a charge is $0.50 USD. If the invoice has an amount smaller than this, it will not create a charge, but rather add that as a "debt" on the customer for the next invoice.
amount A positive integer in the smallest currency unit (e.g., 100 cents to charge $1.00 or 100 to charge ¥100, a zero-decimal currency) representing how much to charge. The minimum amount is $0.50 US or equivalent in charge currency.
From Stripe API Reference.
I'm working on installment plan. Lets suppose we have a plan of 1,250,000 with 35 installments and payment frequency is after 1 month.
customer has to pay 5% extra after every 6 months. So regularly he will pay 1% and after every 6 months he will pay 6%.
So suppose after other payment charges we have payment of 812,500 that is 65% of total payment.
Now every 6th month customer will pay 1% of regular fee with 5% extra that is 62500.
For clearfication see screenshot. Currently I have to manually add that values but I need to automate this process to save time.
you can use the mod operator to find every 6th row like this .
for($i=1;$i<=20;$i++){
if($i%6 == 0)
echo $i;
}
I need to adjust/allocate the advance amount to the corresponding bills, if it's possible.
For example: Exactly advance amount is less than of invoice amount, may be if overpaid i just want to adjust the excess amount(means Invoice amt rs. 8500/- but paid amt is Rs.10,000/-, here Rs.1,500 is the excess amount) to the next corresponding bills when the excess amount turns zero.
If customer pay advance amount Rs.10,000/- I want to allocate the amount to the customer bills like: 1st bill like Rs.5000/-, 2nd bill Rs.3500/-, 3rd bill Rs.3000/-, after adjusting the advance amount Rs.10,000/- balance amount the customer wants to pay us is Rs.1500/-.
Assuming I have stored in the database the following
withdraw fee = 2
then upon withdrawing money i want the user to pay 2% for withdrawal fees for any amount he/she is receiving. Given the code below, it only deducts $2 instead of deducting %2 of the balance.
In my code, $postd_cashout is the fees to pay,
balance is the user's balance
What change should I make to this line for this to work
$postd_cashout = substr(number_format($ir['balance'], 3, '.', ','), 0, -1);
$postd_cashout = ($ir['balance']*(1.02));
This results in a gross withdrawal of the intended amount plus 2% of that amount. I am unclear if this is exactly what you are trying to achieve, however. The amount the withdrawee receives in hand would be represented in $ir['balance'] whereas the gross amount withdrawn is reflected in $postd_cashout.
optionally:
$withdrawalmultiplier = 1.02;
$postd_cashout = ($ir['balance']*($withdrawalmultiplier));
This allows you to change the fee amount anywhere it is referenced in the code as opposed to hardcoding a static number. the intial example is more clear, imho.
finally:
$fee = ($postd_cashout - $ir['balance'])
I suppose tracking the fee amount is useful for reporting a sum of fees paid or itemizing a receipt and it sounds like this is ultimately what you're wanting after re-reading the question a few times. If the fee amount is all you're after then the other answer fits more elegantly.
Just multiply the balance by the withdrawal fee as a percentage
$fees = ($ir['balance'] * $withdrawal_fee / 100);
You can then utilise $fees in your calculation.
Don't use number_format before the calculation as you want to avoid the commas - that converts the value to a string.