API Forum

This forum is in read-only mode.
Please refer to our API support in case you have any questions.
We can be reached at api@e-conomic.com
e-conomic API developer forum

Really? UpdateFromData needs this much variabels?

+1

I thought I would do the quick way of creating an order. First I ran this:


        $OrderHandle = $client->Order_Create(array(
        'debtorHandle' =>  $debHandle->DebtorHandle))->Order_CreateResult;


This will create an order with default data for my debtor. Works perfect.

Then my idea was to just simple use Order_UpdateFromData and set Delivery and Debtor data.

And just that! Becuse everything else is set by default, since i used Order_Create, and when I created my debtor, I  sat alot of Default Values.

 

BUT Apprently UpdateFromData needs more then just what my idea was.


            $ECOrderData = array("data" => array(
                "Handle" => $OrderHandle, // Must have it
                "DebtorHandle" => $debHandle->DebtorHandle, // Must have it
                "DebtorName" => $orderdata["Name_Combined"], // Maybe must have it
                "DebtorAddress" => $orderdata["Street"],
                "DebtorPostalCode" => $orderdata["Postal_Code"],
                "DebtorCity" => $orderdata["City"],
                "DeliveryAddress" => $orderdata["Ship_Name_Combined"] . "\n" . $orderdata["Ship_Street"],
                "DeliveryPostalCode" => $orderdata["Ship_Postal_Code"],
                "DeliveryCity" => $orderdata["Ship_City"],
                "Heading" => $ordernr,
            ));


That is what i was going for. Instead I got


        $OrderNumber = $client->Order_GetNumber(array("orderHandle" => $OrderHandle))->Order_GetNumberResult;
        $PayNameArray = array(
            "payson_invoice" => "Payson Faktura",
            "payson" => "Payson",
        );
        $PayName = $PayNameArray[$orderdata["Pay_Method_Code"]];
        $PaymentHandle = $client->TermOfPayment_FindByName(array('name' => $PayName))->TermOfPayment_FindByNameResult->TermOfPaymentHandle;
            $date = date("Y-m-d");
            $time = date("H:m:s");
            $XsdDateTime = $date . "T" . $time;
        $Currency = $client->Currency_FindByCode(array(
            'code' => 'SEK'))->Currency_FindByCodeResult;
        $LayoutString = 'Mobilfynd';
        $Layout = $client->TemplateCollection_FindByName(array(
        'name' => $LayoutString))->TemplateCollection_FindByNameResult->TemplateCollectionHandle;
            $ECOrderData = array("data" => array(
                "Handle" => $OrderHandle, // Must have it
                "DebtorHandle" => $debHandle->DebtorHandle, // Must have it
                "Number" => $OrderNumber, // Must have it
                "Date" => $XsdDateTime, // Must have it
                "ExchangeRate" => 100, // Must have it
                "IsVatIncluded" => true, // Must have it
                "IsArchived" => false, // Must have it
                "IsSent" => false, // Must have it
                "NetAmount" => 0, // Must have it
                "VatAmount" => 0, // Must have it
                "GrossAmount" => 0, // Must have it
                "Margin" => 0, // Must have it
                "MarginAsPercent" => 0, // Must have it
                "TermOfPaymentHandle" => $PaymentHandle, // Must have it
                "CurrencyHandle" => $Currency, // Must have it
                "LayoutHandle" => $Layout, // Must have it
                // Yay! Now I can update with my data
                "DebtorName" => $orderdata["Name_Combined"], // Maybe must have it
                "DebtorAddress" => $orderdata["Street"],
                "DebtorPostalCode" => $orderdata["Postal_Code"],
                "DebtorCity" => $orderdata["City"],
                "DeliveryAddress" => $orderdata["Ship_Name_Combined"] . "\n" . $orderdata["Ship_Street"],
                "DeliveryPostalCode" => $orderdata["Ship_Postal_Code"],
                "DeliveryCity" => $orderdata["Ship_City"],
                "Heading" => $ordernr,
            ));
        $client->Order_UpdateFromData($ECOrderData)->Order_UpdateFromDataResult;


Is this really needed!?  I use Update for god sake! Can't it just asume that the values i don't enter is set to my likeing? I can understand the Number var, but all the others?  I'm updateing. Not creating. I don't know. With this amount of code, I might just as well just run Order_SetDeliveryAddress and so on..

 

created Mar 26, 2013 by PhpMadman
100% Accept Rate
Q 3 A 8 C 2

2 Answers

+1
 
Best answer

Have you tried using Order_GetData function for getting the default values for the newly created order?

I would think you could modify the values in the object that request returns, and then use Order_UpdateFromData with that data object ? Then you wouldn't have to write 20-30 lines of setting default values for an object you are sending, and you are only doing one request instead of one for each value you set?

answered Apr 3, 2013 by tg24
selected Apr 3, 2013 by PhpMadman
0
Thank you. That was a very good idea.

New code looks like this.

        $AllData = $client->Order_GetData(array("entityHandle" => $OrderHandle))->Order_GetDataResult;
            $Data = array(
                "Date" =>  date("Y-m-d") . "T" . date("H:m:s"), // Must have it
                "ExchangeRate" => $AllData->ExchangeRate, // Must have it
                "IsVatIncluded" => $AllData->IsVatIncluded, // Must have it
                "IsArchived" => (!empty($AllData->IsArchived) ? true : false), // Must have it
                "IsSent" => (!empty($AllData->IsSent) ? true : false), // Must have it
                "NetAmount" => $AllData->NetAmount, // Must have it
                "VatAmount" => $AllData->VatAmount, // Must have it
                "GrossAmount" => $AllData->GrossAmount, // Must have it
                "Margin" => $AllData->Margin, // Must have it
                "MarginAsPercent" => $AllData->MarginAsPercent, // Must have it
                "TermOfPaymentHandle" => $PaymentHandle, // Must have it
                "CurrencyHandle" => $AllData->CurrencyHandle, // Must have it
                "LayoutHandle" => $AllData->LayoutHandle, // Must have it

                "Handle" => $OrderHandle, // Must have it
                "DebtorHandle" => $debHandle->DebtorHandle, // Must have it
                "Number" => $OrderNumber, // Must have it
                // Yay! Now I can update with my data
                 ... MORE CODE....       

I still set Payment manually, but it is posibole to use GetData to set that as well.
answered Apr 3, 2013 by PhpMadman
I'm not sure if you understood me correctly. Here is a code example of creating a payment. CashBookEntry_CreateFromData has 31 fields or something. I only want some of it.

First I create the payment

$ce_payment = $ws->CashBookEntry_CreateManualDebtorInvoice($cb_entry_request);

Then I receive all it's data. Then I only set those values I need.

$ce_data_request = $ws->CashBookEntry_GetData($ce_data_request);
        $ce_data = $ce_data_request->CashBookEntry_GetDataResult;

        $now = new DateTime("", new DateTimeZone("UTC"));
        // Setting the data
        $ce_data->Date = $now->format("c");
        $ce_data->Amount = $amount;
        $ce_data->Text = $payment_text;
        $ce_data->DebtorInvoiceNumber = $invoice_number;

Then I update the payment with the data I received, and those fields that I needed to change.

        $ce_update = $ws->CashBookEntry_UpdateFromData($ce_data_update_request);

So instead of having 31 lines of setting default values or more. Creating handles for every default handle I want there to be, I just get the default values from the API and change the values I need. 4 lines instead of 31.

This also saves me the round trip of 3 requests when creating a payment which isn't a lot maybe, but it's might help.
Oh. You meant like that.
Yeah that saves alot of code.
I'm defently gonna change to that instead.
Thanks for the help.
Visma e-conomic A/S
...