Click here to Skip to main content
15,076,130 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a function called `getPrice` with two parameters `$id` and `$codenumber` the behavior of this function or method is to fetch a specific column in the name of Items which contains a `JSON` array and then the method uses `json_decode` function to return a PHP array to work around the array for getting values depending on keys, the method `getPrice` works, What I get stuck in? first of all decoded array items well be inside a `table` each column holds a value returned from the array and the last column for each row has two `buttons` for edit and remove the row, edit button fires another DOM a `modal` contains a couple of inputs to edit the `row`, so the propose of the `getPrice` function is to fill an input with the `Price` the problem is in defining which one of the rows or the items as it appears in the screenshot, the one that I want to get his information to fill the modal

Table

What I have tried:

Core.php [ Contains `getPrice`]


PHP
<?PHP
public function getBillItems($BillID){
        if($this->connected === true){
            try{
                $items = $this->connection->prepare("SELECT `items` FROM `bills` WHERE id=:id");
                $items->bindParam(":id",$BillID);
                $items->execute();
                return $items->fetchColumn();
            }
            catch(PDOException $e){
                if($this->errors === true){
                    return $this->error($e->getMessage());
                }else{
                    return false;
                }
            }
        }
    }
    public function getPrice($id,$codenumber){
        if($this->connected === true){
            try{
                $items = $this->connection->prepare("SELECT `items` FROM `bills` WHERE id=:id");
                $items->bindParam(":id",$id);
                $items->execute();
                $fetchedItems = $items->fetchColumn();
                $items = json_decode($fetchedItems);
                $array = array_column($items, null, 'codenumber');
                return $array[$codenumber]->price; 
            }
            catch(PDOException $e){
                if($this->errors === true){
                    return $this->error($e->getMessage());
                }else{
                    return false;
                }
            }
        }
    }
?>


billing.php

PHP
<pre><?php $AcBilling = $db->getRows("SELECT * FROM `bills` WHERE statues='active' ORDER BY billingdate DESC")?>
            <div class="container-fluid bg-light">
                <?foreach($AcBilling as $activebill){?>
                    <!-- invoice template -->
                    <?$billingJSON = $db->getBillItems($activebill['id']); $decoded = json_decode($billingJSON);?> <!-- retrive Array of Object contains the order items-->
                    <?$id = $activebill['pharmacyid'];?>
                    <div id="<?=$activebill['invoicecodenum']?>" role="tablist" aria-multiselectable="true">
                        <div class="card">
                            <div class="card-header" style="font-family:hana;" role="tab" id="section1HeaderId" data-toggle="collapse" data-parent="#<?=$activebill['invoicecodenum']?>" href="#section1Content<?=$activebill['invoicecodenum']?>" aria-expanded="true" aria-controls="section1ContentId">
                            </div>
                            <div id="section1Content<?=$activebill['invoicecodenum']?>" class="collapse in" role="tabpanel" aria-labelledby="section1HeaderId">
                                <div class="card-body">
                                    <div class="container" style="font-family:hana;">
                                        <table class="table" style="direction: rtl;" >
                                            <thead>
                                                <tr>
                                                    <th>#</th>
                                                    <th>إسم المنتج</th>
                                                    <th>سعر القطعة</th>
                                                    <th>تاريخ الإنتاج</th>
                                                    <th>تاريخ إنتهاء صلاحية</th>
                                                    <th>الكمية</th>
                                                    <th>Free</th>
                                                    <th>السعر النهائي</th>
                                                    <th>إجراءات</th>
                                                </tr>
                                            </thead>
                                            <tbody style="font-family: Tahoma; text-align:right;">
                                                <tr>
                                                <!-- Parsing $billingJSON to the table -->
                                                <? foreach ($decoded as $Product){?>
                                                    <td scope="row">1</td>
                                                    <td><?=$Product->name;?></td>
                                                    <td><?=$Product->price;?></td>
                                                    <td><?=$Product->productiondate;?></td>
                                                    <td><?=$Product->expirationdate;?></td>
                                                    <td><?=$qty=50;?></td>
                                                    <td>5</td>
                                                    <td><?=$pricewsale = $Product->price * $qty?></td>
                                                    <td>^__i class="fas fa-marker edit-symbol"></td>
                                                </tr>
                                                <?}?>
                                            </tbody>
                                        </table>

Modal Class :-
HTML
<pre>    <div class="modal fade" id="modelId" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                        <h5 class="modal-title" style="justify-content: right; font-family:hana;">تعديل</h5>
                </div>
                <div class="modal-body" style="text-align: right; direction:rtl;">
                    <div class="card">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-sm col-lg">
                                    <label for="qtyfield" style="font-family: hana;">عدد القطع :-</label>
                                    <input type="text" class="form-control" name="qty-input" id="qtyfield" placeholder="">
                                </div>
                                <div class="col-sm col-lg">
                                    <label for="qtyfield" style="font-family:hana;">سعر القطعة :-</label>
                                    <input type="text" class="form-control" name="qty-input" id="qtyfield" placeholder="">
                                </div>
                            </div><br>
                            <div class="row">
                                <div class="col-sm col-lg">
                                    <label for="qtyfield" style="font-family: hana;">السعر النهائي :-</label>
                                    <input type="text" class="form-control" name="qty-input" id="qtyfield" placeholder="" value ="">
                                </div>
                                <div class="col-sm col-lg">

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer"  style="font-family:hana;">
                    <button type="button" class="btn btn-danger btn-sm" data-dismiss="modal">إلغاء </button>
                    <button type="button" class="btn btn-Success btn-sm">حفظ ^__i class="fas fa-check"></button>

                </div>
            </div>
        </div>
    </div>
Posted
Updated 23-Jun-20 5:30am
v2
Comments
MohammedZr 23-Jun-20 16:36pm
   
I need help, this is very necessary.
thank you Richard MacCutchan for updating the code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900