0

I am using the "langleyfoxall/xero-laravel" package version 3.0.0 in my Laravel project and I'm having difficulty passing an attachment to Xero. Here is the code I have so far:

$this->xero->PurcheseOrder([
    'lead' => $user,
    //'description' => isset($value['description']) ? $value['description'] :'',
    //'discount' => isset($value['discount']) ? $value['discount'] :'',
    //'tax_rate' => isset($value['tax_rate']) ? $value['tax_rate'] :'',
    'lead' => $user,
    'orders' => $updated_medicine,
    'delivery_date' => isset($input['delivery_date']) ? \Carbon\Carbon::parse($input['delivery_date'])  : null,
    'created_at' => $purchase_order->created_at,
    'purchase_order_id' => $purchase_order->id,
    'referance' => $purchase_order->referance ,    
    'note' => $purchase_order->note,    
]);

And here is the function that I'm using: when I try to send it is giving a error, Is there any way to send attachment using this package

Copy code
public function PurcheseOrder($order)
{
    if(empty($order['lead']->xero_id)){
        $lead = $this->saveUserXero($order['lead']);
        $contact = $this->xero->loadByGUID(\XeroPHP\Models\Accounting\Contact::class,$lead->xero_id);
    }
    else{
        $contact = $this->xero->loadByGUID(\XeroPHP\Models\Accounting\Contact::class,$order['lead']->xero_id);
    }
    $purchese_order = new PurchaseOrder($this->xero);
    
    $purchese_order->setContact($contact);
    $purchese_order->setStatus(\XeroPHP\Models\Accounting\Invoice::INVOICE_STATUS_SUBMITTED);
    $purchese_order->setReference($order['referance']);

    $trackingCategory = new \XeroPHP\Models\Accounting\TrackingCategory($this->xero);
    $trackingCategory->setName('Deals');

    if(isset($order['note'])){
        $purchese_order->setDeliveryAddress($order['note']);
    }

    if($order['delivery_date'] != null){
        $purchese_order->setDeliveryDate($order['delivery_date']);
    }
    foreach ($order['orders'] as $ord) {
        
        $lineItem = new \XeroPHP\Models\Accounting\LineItem($this->xero);
        if(isset($ord['item_code'])){
            $lineItem->setItemCode($ord['item_code']);
        }
        $lineItem->setDescription($ord['description']);
        $lineItem->setQuantity($ord['quantity'] + $ord['free_of_goods']);
        $lineItem->setUnitAmount(($ord['amount'] * ((100 -$ord['discount'])/100)) /($ord['quantity'] + $ord['free_of_goods']));
        $lineItem->setAccountCode($ord['account']);
        if(isset($ord['item_code']) && $ord['discount'] != 0){
            //$lineItem->setDiscountAmount($ord['discount']);
        }
            if(isset($ord['deals'])){
                $trackingCategory->setOption($ord['deals']);
            }
            $lineItem->addTracking($trackingCategory);
            $purchese_order->addLineItem($lineItem);
        }

        $purchese_order->save();
        $pur_ord = AppPurchaseOrder::find($order['purchase_order_id']);
        $pur_ord->xero_id = $purchese_order->PurchaseOrderID;
        $pur_ord->order_status = 2;
        $pur_ord->po_number = $purchese_order->PurchaseOrderNumber;
        $pur_ord->save();
    }
    ```

1 Answers1

0

This is a two step process. First you need to create the purchase order and then you make a second call to attach the file.

There is an SDK and sample app on Github for php if you want to see working examples.

https://github.com/XeroAPI/xero-php-oauth2

sallyhornet
  • 364
  • 2