reduce two total number of notes with one payment





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















i have case like, i have 2 note, first have total 100.000, second 50.000.
i pay 120.000. so i want first note is become 0. and second note become 30.000.
which he paid first until 0 and then next. i was try with for, and foreach to update.
this part of my code



$query      = "SELECT GROUP_CONCAT(DCTN_NBR) as DCTN_NBR, SUM(TND_AMT) as TND_AMT, GROUP_CONCAT(ORD_NBR_RT) as ORD_NBR_RT FROM $RTL.RTL_STK_DCTN WHERE DEL_NBR = 0";
// echo $query;
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($result))
{
$totdctnamt = $row['TND_AMT'];
// this result is total of paid = 120.000
}


foreach ($PrnNbr as $index => $PrnNbrStrs)
{
$querystknote = " SELECT TOT_AMT FROM $RTL.RTL_STK_HEAD WHERE ORD_NBR =".$PrnNbr[$index];
$resultstknote = mysqli_query($connect, $querystknote);
$rowstknote = mysqli_fetch_array($resultstknote);
$rowstknote['TOT_AMT'];
// this result from 2 note 100.000 and 50.000
$querytotrem = " UPDATE $RTL.RTL_STK_HEAD SET TOT_REM = 0 WHERE ORD_NBR =".$PrnNbr[$index];
// echo $querytotrem;
}


now how to update first nota to 0 and the rest of pay first note to pay second note










share|improve this question

























  • I understood that $totdctnamt has the value 120,000 but which variable contains the notes 100,000 and 50,000 ? Is it $rowtknote['TOT_AMT']?

    – Ahmad
    Nov 29 '18 at 5:33











  • yes, it $rowtknote['TOT_AMT'];

    – Beny Bond Banjarnahor
    Nov 29 '18 at 5:35


















0















i have case like, i have 2 note, first have total 100.000, second 50.000.
i pay 120.000. so i want first note is become 0. and second note become 30.000.
which he paid first until 0 and then next. i was try with for, and foreach to update.
this part of my code



$query      = "SELECT GROUP_CONCAT(DCTN_NBR) as DCTN_NBR, SUM(TND_AMT) as TND_AMT, GROUP_CONCAT(ORD_NBR_RT) as ORD_NBR_RT FROM $RTL.RTL_STK_DCTN WHERE DEL_NBR = 0";
// echo $query;
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($result))
{
$totdctnamt = $row['TND_AMT'];
// this result is total of paid = 120.000
}


foreach ($PrnNbr as $index => $PrnNbrStrs)
{
$querystknote = " SELECT TOT_AMT FROM $RTL.RTL_STK_HEAD WHERE ORD_NBR =".$PrnNbr[$index];
$resultstknote = mysqli_query($connect, $querystknote);
$rowstknote = mysqli_fetch_array($resultstknote);
$rowstknote['TOT_AMT'];
// this result from 2 note 100.000 and 50.000
$querytotrem = " UPDATE $RTL.RTL_STK_HEAD SET TOT_REM = 0 WHERE ORD_NBR =".$PrnNbr[$index];
// echo $querytotrem;
}


now how to update first nota to 0 and the rest of pay first note to pay second note










share|improve this question

























  • I understood that $totdctnamt has the value 120,000 but which variable contains the notes 100,000 and 50,000 ? Is it $rowtknote['TOT_AMT']?

    – Ahmad
    Nov 29 '18 at 5:33











  • yes, it $rowtknote['TOT_AMT'];

    – Beny Bond Banjarnahor
    Nov 29 '18 at 5:35














0












0








0








i have case like, i have 2 note, first have total 100.000, second 50.000.
i pay 120.000. so i want first note is become 0. and second note become 30.000.
which he paid first until 0 and then next. i was try with for, and foreach to update.
this part of my code



$query      = "SELECT GROUP_CONCAT(DCTN_NBR) as DCTN_NBR, SUM(TND_AMT) as TND_AMT, GROUP_CONCAT(ORD_NBR_RT) as ORD_NBR_RT FROM $RTL.RTL_STK_DCTN WHERE DEL_NBR = 0";
// echo $query;
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($result))
{
$totdctnamt = $row['TND_AMT'];
// this result is total of paid = 120.000
}


foreach ($PrnNbr as $index => $PrnNbrStrs)
{
$querystknote = " SELECT TOT_AMT FROM $RTL.RTL_STK_HEAD WHERE ORD_NBR =".$PrnNbr[$index];
$resultstknote = mysqli_query($connect, $querystknote);
$rowstknote = mysqli_fetch_array($resultstknote);
$rowstknote['TOT_AMT'];
// this result from 2 note 100.000 and 50.000
$querytotrem = " UPDATE $RTL.RTL_STK_HEAD SET TOT_REM = 0 WHERE ORD_NBR =".$PrnNbr[$index];
// echo $querytotrem;
}


now how to update first nota to 0 and the rest of pay first note to pay second note










share|improve this question
















i have case like, i have 2 note, first have total 100.000, second 50.000.
i pay 120.000. so i want first note is become 0. and second note become 30.000.
which he paid first until 0 and then next. i was try with for, and foreach to update.
this part of my code



$query      = "SELECT GROUP_CONCAT(DCTN_NBR) as DCTN_NBR, SUM(TND_AMT) as TND_AMT, GROUP_CONCAT(ORD_NBR_RT) as ORD_NBR_RT FROM $RTL.RTL_STK_DCTN WHERE DEL_NBR = 0";
// echo $query;
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($result))
{
$totdctnamt = $row['TND_AMT'];
// this result is total of paid = 120.000
}


foreach ($PrnNbr as $index => $PrnNbrStrs)
{
$querystknote = " SELECT TOT_AMT FROM $RTL.RTL_STK_HEAD WHERE ORD_NBR =".$PrnNbr[$index];
$resultstknote = mysqli_query($connect, $querystknote);
$rowstknote = mysqli_fetch_array($resultstknote);
$rowstknote['TOT_AMT'];
// this result from 2 note 100.000 and 50.000
$querytotrem = " UPDATE $RTL.RTL_STK_HEAD SET TOT_REM = 0 WHERE ORD_NBR =".$PrnNbr[$index];
// echo $querytotrem;
}


now how to update first nota to 0 and the rest of pay first note to pay second note







php mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 29 '18 at 5:39







Beny Bond Banjarnahor

















asked Nov 29 '18 at 5:27









Beny Bond BanjarnahorBeny Bond Banjarnahor

1159




1159













  • I understood that $totdctnamt has the value 120,000 but which variable contains the notes 100,000 and 50,000 ? Is it $rowtknote['TOT_AMT']?

    – Ahmad
    Nov 29 '18 at 5:33











  • yes, it $rowtknote['TOT_AMT'];

    – Beny Bond Banjarnahor
    Nov 29 '18 at 5:35



















  • I understood that $totdctnamt has the value 120,000 but which variable contains the notes 100,000 and 50,000 ? Is it $rowtknote['TOT_AMT']?

    – Ahmad
    Nov 29 '18 at 5:33











  • yes, it $rowtknote['TOT_AMT'];

    – Beny Bond Banjarnahor
    Nov 29 '18 at 5:35

















I understood that $totdctnamt has the value 120,000 but which variable contains the notes 100,000 and 50,000 ? Is it $rowtknote['TOT_AMT']?

– Ahmad
Nov 29 '18 at 5:33





I understood that $totdctnamt has the value 120,000 but which variable contains the notes 100,000 and 50,000 ? Is it $rowtknote['TOT_AMT']?

– Ahmad
Nov 29 '18 at 5:33













yes, it $rowtknote['TOT_AMT'];

– Beny Bond Banjarnahor
Nov 29 '18 at 5:35





yes, it $rowtknote['TOT_AMT'];

– Beny Bond Banjarnahor
Nov 29 '18 at 5:35












1 Answer
1






active

oldest

votes


















1














In your loop, always decrement your total and set the current note to zero if current note is less than the total.



Until total becomes less than the current note amount, then do the other way around: set note amount = note - amount, and update total.



foreach ($PrnNbr as $index => $PrnNbrStrs) 
{
$querystknote = " SELECT TOT_AMT FROM $RTL.RTL_STK_HEAD WHERE ORD_NBR =".$PrnNbr[$index];
$resultstknote = mysqli_query($connect, $querystknote);
$rowstknote = mysqli_fetch_array($resultstknote);

$note = $rowstknote['TOT_AMT']; // assuming this will be 100,000 then 50,000
if($totdctnamt>=$note) {
$totdctnamt -= $note; //reduce the total amount
// it was 120k
// now it is 120k-100k = 20k
$note = 0;
} else {
$note -= $totdctnamt; // the second iteration,
// note is 50k, and total is 20k
// so note will be 50k-20k = 30k

$totdctnamt = 0; // to avoid other notes being affected

}

// finally, we update the table
$querytotrem = " UPDATE $RTL.RTL_STK_HEAD SET TOT_REM = $note WHERE ORD_NBR =".$PrnNbr[$index];
// echo $querytotrem;
}





share|improve this answer
























  • why when i change the value like. 2 of notes is note a = 100.000 and note b = 50.000. when i pay with 132.000. note b = 0 and note a become = 30.000. it should be 18.000. 132.000 - 50.000 = 82.000 to pay 100.000 = 18.000

    – Beny Bond Banjarnahor
    Nov 29 '18 at 6:02











  • what u mean. i dont understand.

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:10











  • when i pay with 132.000. the echo result is . 70.000 $totdctnamt and 30.000 for $note

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:18











  • 50.000 and 100.000

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:25











  • sorry i miss something. it worked well. thank u ahmad. @Ahmad

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:41














Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53532399%2freduce-two-total-number-of-notes-with-one-payment%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














In your loop, always decrement your total and set the current note to zero if current note is less than the total.



Until total becomes less than the current note amount, then do the other way around: set note amount = note - amount, and update total.



foreach ($PrnNbr as $index => $PrnNbrStrs) 
{
$querystknote = " SELECT TOT_AMT FROM $RTL.RTL_STK_HEAD WHERE ORD_NBR =".$PrnNbr[$index];
$resultstknote = mysqli_query($connect, $querystknote);
$rowstknote = mysqli_fetch_array($resultstknote);

$note = $rowstknote['TOT_AMT']; // assuming this will be 100,000 then 50,000
if($totdctnamt>=$note) {
$totdctnamt -= $note; //reduce the total amount
// it was 120k
// now it is 120k-100k = 20k
$note = 0;
} else {
$note -= $totdctnamt; // the second iteration,
// note is 50k, and total is 20k
// so note will be 50k-20k = 30k

$totdctnamt = 0; // to avoid other notes being affected

}

// finally, we update the table
$querytotrem = " UPDATE $RTL.RTL_STK_HEAD SET TOT_REM = $note WHERE ORD_NBR =".$PrnNbr[$index];
// echo $querytotrem;
}





share|improve this answer
























  • why when i change the value like. 2 of notes is note a = 100.000 and note b = 50.000. when i pay with 132.000. note b = 0 and note a become = 30.000. it should be 18.000. 132.000 - 50.000 = 82.000 to pay 100.000 = 18.000

    – Beny Bond Banjarnahor
    Nov 29 '18 at 6:02











  • what u mean. i dont understand.

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:10











  • when i pay with 132.000. the echo result is . 70.000 $totdctnamt and 30.000 for $note

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:18











  • 50.000 and 100.000

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:25











  • sorry i miss something. it worked well. thank u ahmad. @Ahmad

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:41


















1














In your loop, always decrement your total and set the current note to zero if current note is less than the total.



Until total becomes less than the current note amount, then do the other way around: set note amount = note - amount, and update total.



foreach ($PrnNbr as $index => $PrnNbrStrs) 
{
$querystknote = " SELECT TOT_AMT FROM $RTL.RTL_STK_HEAD WHERE ORD_NBR =".$PrnNbr[$index];
$resultstknote = mysqli_query($connect, $querystknote);
$rowstknote = mysqli_fetch_array($resultstknote);

$note = $rowstknote['TOT_AMT']; // assuming this will be 100,000 then 50,000
if($totdctnamt>=$note) {
$totdctnamt -= $note; //reduce the total amount
// it was 120k
// now it is 120k-100k = 20k
$note = 0;
} else {
$note -= $totdctnamt; // the second iteration,
// note is 50k, and total is 20k
// so note will be 50k-20k = 30k

$totdctnamt = 0; // to avoid other notes being affected

}

// finally, we update the table
$querytotrem = " UPDATE $RTL.RTL_STK_HEAD SET TOT_REM = $note WHERE ORD_NBR =".$PrnNbr[$index];
// echo $querytotrem;
}





share|improve this answer
























  • why when i change the value like. 2 of notes is note a = 100.000 and note b = 50.000. when i pay with 132.000. note b = 0 and note a become = 30.000. it should be 18.000. 132.000 - 50.000 = 82.000 to pay 100.000 = 18.000

    – Beny Bond Banjarnahor
    Nov 29 '18 at 6:02











  • what u mean. i dont understand.

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:10











  • when i pay with 132.000. the echo result is . 70.000 $totdctnamt and 30.000 for $note

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:18











  • 50.000 and 100.000

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:25











  • sorry i miss something. it worked well. thank u ahmad. @Ahmad

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:41
















1












1








1







In your loop, always decrement your total and set the current note to zero if current note is less than the total.



Until total becomes less than the current note amount, then do the other way around: set note amount = note - amount, and update total.



foreach ($PrnNbr as $index => $PrnNbrStrs) 
{
$querystknote = " SELECT TOT_AMT FROM $RTL.RTL_STK_HEAD WHERE ORD_NBR =".$PrnNbr[$index];
$resultstknote = mysqli_query($connect, $querystknote);
$rowstknote = mysqli_fetch_array($resultstknote);

$note = $rowstknote['TOT_AMT']; // assuming this will be 100,000 then 50,000
if($totdctnamt>=$note) {
$totdctnamt -= $note; //reduce the total amount
// it was 120k
// now it is 120k-100k = 20k
$note = 0;
} else {
$note -= $totdctnamt; // the second iteration,
// note is 50k, and total is 20k
// so note will be 50k-20k = 30k

$totdctnamt = 0; // to avoid other notes being affected

}

// finally, we update the table
$querytotrem = " UPDATE $RTL.RTL_STK_HEAD SET TOT_REM = $note WHERE ORD_NBR =".$PrnNbr[$index];
// echo $querytotrem;
}





share|improve this answer













In your loop, always decrement your total and set the current note to zero if current note is less than the total.



Until total becomes less than the current note amount, then do the other way around: set note amount = note - amount, and update total.



foreach ($PrnNbr as $index => $PrnNbrStrs) 
{
$querystknote = " SELECT TOT_AMT FROM $RTL.RTL_STK_HEAD WHERE ORD_NBR =".$PrnNbr[$index];
$resultstknote = mysqli_query($connect, $querystknote);
$rowstknote = mysqli_fetch_array($resultstknote);

$note = $rowstknote['TOT_AMT']; // assuming this will be 100,000 then 50,000
if($totdctnamt>=$note) {
$totdctnamt -= $note; //reduce the total amount
// it was 120k
// now it is 120k-100k = 20k
$note = 0;
} else {
$note -= $totdctnamt; // the second iteration,
// note is 50k, and total is 20k
// so note will be 50k-20k = 30k

$totdctnamt = 0; // to avoid other notes being affected

}

// finally, we update the table
$querytotrem = " UPDATE $RTL.RTL_STK_HEAD SET TOT_REM = $note WHERE ORD_NBR =".$PrnNbr[$index];
// echo $querytotrem;
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 29 '18 at 5:39









AhmadAhmad

8,37243764




8,37243764













  • why when i change the value like. 2 of notes is note a = 100.000 and note b = 50.000. when i pay with 132.000. note b = 0 and note a become = 30.000. it should be 18.000. 132.000 - 50.000 = 82.000 to pay 100.000 = 18.000

    – Beny Bond Banjarnahor
    Nov 29 '18 at 6:02











  • what u mean. i dont understand.

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:10











  • when i pay with 132.000. the echo result is . 70.000 $totdctnamt and 30.000 for $note

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:18











  • 50.000 and 100.000

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:25











  • sorry i miss something. it worked well. thank u ahmad. @Ahmad

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:41





















  • why when i change the value like. 2 of notes is note a = 100.000 and note b = 50.000. when i pay with 132.000. note b = 0 and note a become = 30.000. it should be 18.000. 132.000 - 50.000 = 82.000 to pay 100.000 = 18.000

    – Beny Bond Banjarnahor
    Nov 29 '18 at 6:02











  • what u mean. i dont understand.

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:10











  • when i pay with 132.000. the echo result is . 70.000 $totdctnamt and 30.000 for $note

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:18











  • 50.000 and 100.000

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:25











  • sorry i miss something. it worked well. thank u ahmad. @Ahmad

    – Beny Bond Banjarnahor
    Nov 29 '18 at 7:41



















why when i change the value like. 2 of notes is note a = 100.000 and note b = 50.000. when i pay with 132.000. note b = 0 and note a become = 30.000. it should be 18.000. 132.000 - 50.000 = 82.000 to pay 100.000 = 18.000

– Beny Bond Banjarnahor
Nov 29 '18 at 6:02





why when i change the value like. 2 of notes is note a = 100.000 and note b = 50.000. when i pay with 132.000. note b = 0 and note a become = 30.000. it should be 18.000. 132.000 - 50.000 = 82.000 to pay 100.000 = 18.000

– Beny Bond Banjarnahor
Nov 29 '18 at 6:02













what u mean. i dont understand.

– Beny Bond Banjarnahor
Nov 29 '18 at 7:10





what u mean. i dont understand.

– Beny Bond Banjarnahor
Nov 29 '18 at 7:10













when i pay with 132.000. the echo result is . 70.000 $totdctnamt and 30.000 for $note

– Beny Bond Banjarnahor
Nov 29 '18 at 7:18





when i pay with 132.000. the echo result is . 70.000 $totdctnamt and 30.000 for $note

– Beny Bond Banjarnahor
Nov 29 '18 at 7:18













50.000 and 100.000

– Beny Bond Banjarnahor
Nov 29 '18 at 7:25





50.000 and 100.000

– Beny Bond Banjarnahor
Nov 29 '18 at 7:25













sorry i miss something. it worked well. thank u ahmad. @Ahmad

– Beny Bond Banjarnahor
Nov 29 '18 at 7:41







sorry i miss something. it worked well. thank u ahmad. @Ahmad

– Beny Bond Banjarnahor
Nov 29 '18 at 7:41






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53532399%2freduce-two-total-number-of-notes-with-one-payment%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)