Jump to content

How to handle master detail update and delete request in JSON


Abrar

Recommended Posts

Hi Friends ,

We have the JSON Data coming in this format,

$invoice_data = {
    "CONTACT_ID": "1",
    "INV_SERIAL_NO": "100",
    "NAME": "baby",
    "INV_DATE": "2018-06-27",
    "DUE_DATE": "2018-06-27",
    "CURRENCY": "KD",
    "SUBTOTAL": "143",
    "TAX_TOTAL": "13",
     "shipment_data": [
         {
            "SHIP_SERIAL_NO": "44",
            "MASTER_NO": "55",
            "HOUSE_NO": "88",
            "cost_revenue_items": [
                {
                    "CHARGE_REF": "tt",
                    "CURRENCY": "INR",
                    "QUANTITY": "2",
                    "SELLING_RATE": "45",
                    "EXCHANGE_RATE": "987"                                       
                },{
                    "CHARGE_REF": "ii",
                    "CURRENCY": "INR",
                    "QUANTITY": "2",
                    "SELLING_RATE": "45",
                    "EXCHANGE_RATE": "456"
                },{
                    "CHARGE_REF": "op",
                    "CURRENCY": "INR",
                    "QUANTITY": "2",
                    "SELLING_RATE": "45",
                    "EXCHANGE_RATE": "456"
                }
            ]
        }
    ]
}

How to write DELETE End-point for child data-set "cost_revenue_items". What I mean to say is how to handle the request to delete one of item from "cost_revenue_items".

When "cost_revenue_items" will be deleted ,master "invoice_data" will be updated. This update , we can handle by PUT, but how do we know under that PUT, we have to
DELETE one of "cost_revenue_items". Like how the JSON request to only delete one of "cost_revenue_items" will look like.

Will JSON request to delete "cost_revenue_items" looks like this ,if it want to delete last record :

$invoice_data = {
    "CONTACT_ID": "1",
    "INV_SERIAL_NO": "100",
    "NAME": "baby",
    "INV_DATE": "2018-06-27",
    "DUE_DATE": "2018-06-27",
    "CURRENCY": "KD",
    "SUBTOTAL": "143",
    "TAX_TOTAL": "13",
     "shipment_data": [
         {
            "SHIP_SERIAL_NO": "44",
            "MASTER_NO": "55",
            "HOUSE_NO": "88",
            "cost_revenue_items": [
                {
                    "CHARGE_REF": "tt",
                    "CURRENCY": "INR",
                    "QUANTITY": "2",
                    "SELLING_RATE": "45",
                    "EXCHANGE_RATE": "987"
                },{
                    "CHARGE_REF": "ii",
                    "CURRENCY": "INR",
                    "QUANTITY": "2",
                    "SELLING_RATE": "45",
                    "EXCHANGE_RATE": "456"
                }
            ]
        }
    ]
}

Kindly help me to know , how JSON request will look like ?

 

Thanks a lot

Link to comment
Share on other sites

You could try something like this

$temp = json_decode($invoice_data);
unset($temp->shipment_data[0]->cost_revenue_items[2]);
$new_inv_data = json_encode($temp);

echo '<pre>' . print_r($temp, 1) . '</pre>';

giving

stdClass Object
(
    [CONTACT_ID] => 1
    [INV_SERIAL_NO] => 100
    [NAME] => baby
    [INV_DATE] => 2018-06-27
    [DUE_DATE] => 2018-06-27
    [CURRENCY] => KD
    [SUBTOTAL] => 143
    [TAX_TOTAL] => 13
    [shipment_data] => Array
        (
            [0] => stdClass Object
                (
                    [SHIP_SERIAL_NO] => 44
                    [MASTER_NO] => 55
                    [HOUSE_NO] => 88
                    [cost_revenue_items] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [CHARGE_REF] => tt
                                    [CURRENCY] => INR
                                    [QUANTITY] => 2
                                    [SELLING_RATE] => 45
                                    [EXCHANGE_RATE] => 987
                                )

                            [1] => stdClass Object
                                (
                                    [CHARGE_REF] => ii
                                    [CURRENCY] => INR
                                    [QUANTITY] => 2
                                    [SELLING_RATE] => 45
                                    [EXCHANGE_RATE] => 456
                                )

                        )

                )

        )

)

 

Link to comment
Share on other sites

Hello Barand,

Thanks for replying .

Sorry, I could not make you understand.

I want to know , how the JSON request will Look like when we want to delete one record from "cost_revenue_items".

Why I am confused, because "cost_revenue_items" is nested within "$invoice_data -> "Shipment_data". So If they only want to delete only a record from "cost_revenue_items" , in what format JSON request will come ? Will it be nested and sent within parent or will be sent standalone.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.