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

Creating new order is _VERY_ slow

0
Hi guys

I might (very plausible) be going about this the wrong way - when creating a new quote I add individual quotation_lines one by one - this makes the proces very slow...

 

A quotation with perhaps 10 orderlines takes upwards 50 seconds before a PDF is returned, this is not what I expected.

Heres my code at present.. Please advice how to speed up things... (this makes a new quotation which in end are upgraded to an order later on)

// Denne funktion skulle gerne danne en ny quotation på kunden...
function createEconomicQuote($tilbudnr,$quoteid,$kundenr,$varelinjer){
    global $formdata,$db,$start,$kundenavn;
    $client = __connect();
    if(strlen( $quoteid )>0){
        $res = $client->Quotation_GetData(array("entityHandle"=>array("Id"=>(int)$quoteid)))->Quotation_GetDataResult;
        if($res == null ){
            echo json_encode(array("succes"=>false,"msg"=>"Der skete en fejl, forsøg vet. at slette tilbud og opret det igen :("));
            return false;
        }
    }
    if( $quoteid != null ){
        // OK så vi HAR altså oprettet dette tilbud....
        try{
        $quoteid = (int)$quoteid;

        // Vi må sætte det til ikke sendt for at fjerne KLADDE
        $client->Quotation_CancelSentStatus(array("quotationHandle"=>array("Id"=>$quoteid)))->Quotation_CancelSentStatusResponse;
        $quotelines = $client->Quotation_GetLines(array("quotationHandle"=>array("Id"=>$quoteid)))->Quotation_GetLinesResult;
        $q = get_object_vars($quotelines);
        if(count($q["QuotationLineHandle"])>1){
            foreach($q["QuotationLineHandle"] as $line){
                $client->QuotationLine_Delete(array("quotationLineHandle"=>array("Id"=>$line->Id,"Number"=>$line->Number)))->QuotationLine_DeleteResponse;
            }
        } else if(count($q["QuotationLineHandle"])==1){
            $data = (array)$quotelines;
            $client->QuotationLine_Delete(array("quotationLineHandle"=>array("Id"=>$data["QuotationLineHandle"]->Id,"Number"=>$data["QuotationLineHandle"]->Number)))->QuotationLine_DeleteResponse;
        }
        }
        catch (Exception $e) {
              echo json_encode(array("succes"=>false,"msg"=>"Der skete en fejl, forsøg vet. at slette tilbud og opret det igen :("));
              return false;
              sendmail("mymail@gmail.com","Fejl fra GM",var_dump($e) );
         }
    } else {
        // Find kunden
        $debtor = $client->Debtor_FindByNumber(array("number"=>$kundenr))->Debtor_FindByNumberResult;
        // Opret tilbuddet og gem referencen
        $quotationhandle = $client->Quotation_Create(array("debtorHandle"=>$debtor))->Quotation_CreateResult;
        $quoteid = (int)$quotationhandle->Id;
        $db->update("ordrer",array("quoteid"=>$quoteid),"tilbudnr='$tilbudnr'");
        // Sæt overskriften på tilbuddet til tilbudnr
        $response = $client->Quotation_SetHeading(array("quotationHandle"=>$quotationhandle,"value"=>"Tilbud nr.".$tilbudnr))->Quotation_SetHeadingResponse;
        // Vi sætter lige other reference til vores tilbudsnr
        $response = $client->Quotation_SetOtherReference(array("quotationHandle"=>$quotationhandle,"value"=>$tilbudnr))->Quotation_SetOtherReferenceResponse;
    }
    foreach($varelinjer as $r){
        if( (float)$r["antal"] > 0 && strlen($r["varenr"])>0 && strlen($r["varetekst"])>0 ){
            $linehandle = $client->QuotationLine_Create(array("quotationHandle"=>array("Id"=>$quoteid)))->QuotationLine_CreateResult;
            $itemhandle = $client->Product_FindByNumber(array("number"=> $r["varenr"]))->Product_FindByNumberResult;
            $update = $client->QuotationLine_SetProduct(array("quotationLineHandle"=>$linehandle,"valueHandle"=>$itemhandle))->QuotationLine_SetProductResponse;        
            $response = $client->QuotationLine_SetDescription(array("quotationLineHandle"=>$linehandle,"value"=>$r["varetekst"]))->QuotationLine_SetDescriptionResponse;
            $response = $client->QuotationLine_SetQuantity(array("quotationLineHandle"=>$linehandle,"value"=>(float)$r["antal"]))->QuotationLine_SetQuantityResponse;
            $response = $client->QuotationLine_SetUnitNetPrice(array("quotationLineHandle"=>$linehandle,"value"=>(float)$r["stykpris"]))->QuotationLine_SetUnitNetPriceResponse;
        }
    }
    // Lad os sætte kommentarerne i
    if( strlen( _gfo($formdata,"kommentarer") ) > 0 ){
        $comments = _gfo($formdata,"kommentarer");
        $response = $client->Quotation_SetTextLine1(array("quotationHandle"=>array("Id"=>$quoteid),"value"=>$comments))->Quotation_SetTextLine1Response;
    }
    // Lad os sætte status på tilbuddet, som om det er sendt!
    $client->Quotation_RegisterAsSent(array("quotationHandle"=>array("Id"=>$quoteid)));

    // Lad os prøve at hente PDF filen...
    ob_clean();
    $filename = "Tilbudnr_". $tilbudnr .".pdf" ;
    @unlink( "pdffiles/".$filename );
    $pdf = $client->Quotation_GetPdf(array("quotationHandle"=>array("Id"=>$quoteid)))->Quotation_GetPdfResult;
    file_put_contents( "pdffiles/".$filename, $pdf );
    sleep(3);
    header('Cache-Control: no-cache, must-revalidate');
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    header('Content-type: application/json');
    echo json_encode(array("succes"=>true,"quoteid"=>$quoteid,"url"=>"getpdf.php?tilbudnr=$tilbudnr"));

    $client->Disconnect();
    die();
}
created Oct 19, 2014 by internetservice
67% Accept Rate
Q 7 A 2 C 5

1 Answer

0
 
Best answer
Hi

You should use QuotationLine_CreateFromDataArray

https://api.e-conomic.com/secure/api1/EconomicWebService.asmx?op=QuotationLine_CreateFromDataArray

Creating lines individually with setters for each property is not optimal.
answered Feb 23, 2015 by olej
Visma e-conomic A/S
...