How to foreach model to views on fuelphp - orm

i have Model_User
// Get Exams by User
public static function get_exam_by_user($user_id) {
$query = "SELECT e.exam_id, e.exam_code, e.exam_name, e.description, e.creator, e.password,
e.max_attempt, e.random_order, e.max_time, e.max_score, e.min_score, e.grading,
e.created_at, e.updated_at
FROM exam e, user_exam ue
WHERE ue.exam_id = e.exam_id
AND ue.status = 1
AND ue.user_id = :user_id";
$result = DB::query($query)->bind('user_id', $user_id)->execute();
return $result->as_array();
}
and this controller
public function action_index() {
$data = array();
//$data['user_id'] = \Auth\Auth::get('id');
//$data['username'] = \Auth\Auth::get('username');
$user_id = Auth\Auth::get('id');
//$data['exams'] = Model_Exam::find('all');
$data['exams'] = Model_Exam::get_exam_by_user($user_id);
$this->template->title = "Exams";
$this->template->content = View::forge('admin/exam/index', $data);
}
How to foreach to views ?i try to printr_r
Array ( [0] => Array ( [exam_id] => 2 [exam_code] => SD_K1S1_MAT [exam_name] => Ujian Matematika SD Kelas 1 Sem 1 [description] => [creator] => RF [password] => [max_attempt] => 3 [random_order] => 1 [max_time] => 60 [max_score] => 100 [min_score] => 0 [grading] => [created_at] => 2013 [updated_at] => 2013 ) [1] => Array ( [exam_id] => 2 [exam_code] => SD_K1S1_MAT [exam_name] => Ujian Matematika SD Kelas 1 Sem 1 [description] => [creator] => RF [password] => [max_attempt] => 3 [random_order] => 1 [max_time] => 60 [max_score] => 100 [min_score] => 0 [grading] => [created_at] => 2013 [updated_at] => 2013 ) )
if you can help solve this problem

I think that you can do something like this :
<?php foreach ($exams as $exam):
echo $exam['exam_id'];
echo $exam['exam_code'];
echo $exam['exam_name']; .... and so on....
Hope is what you need.

Related

how to write a linq with multiple join

as am a beginner,i want to get the following set of query as linq with a detailed explanation
//my sql
select COL.title as organizationtitle,CL.[title] as
cousestitle,sum(FD.feathers) as totalfeathers,sum(FD.amount) as
totalamount
from [dbo].[FeathersDonated] FD
join [dbo].[Couses] C on FD.corpid=3 and FD.[cousesid]=C.id
join [dbo].[Couses_lang] CL on FD.[cousesid]=CL.cousesid and
CL.language='en-US'
JOIN [dbo].[Organization_lang] COL on COL.orgid=2 and COL.language='en
US'
group by FD.cousesid,CL.[title],CL.[description],COL.title
i have tried the following set of code. please do help
var featherDonated = _GoUoW.FeathersDonated.FindBy(x => x.corpid ==
param.corpid)
.GroupBy(x => x.cousesid).Select(x => new { cousesid = x.Key, amount =
x.Select(a => a.amount).DefaultIfEmpty(0).Sum(), feathers = x.Select(a =>
a.feathers).DefaultIfEmpty(0).Sum() })
.Join(_GoUoW.Couses.GetAll(), feather => feather.cousesid, couse =>
couse.id, (feather, couse) => new { feather, couse })
.Join(_GoUoW.Organization_lang.FindBy(orglang => orglang.language == "en-
US"), couses => couses.couse.orgid, orgid => (param.organizationid > 0 ?
param.organizationid : orgid.orgid), (couses, orgid) => new { couses,
orgid
})
.Join(_GoUoW.Couses_lang.FindBy(couselang => couselang.language == "en-
US"),
organization => organization.orgid.orgid, couselang => couselang.cousesid,
(organization, couselang) => new { organization, couselang })
.Select(x => new
{
x.organization.couses.feather.amount,
x.organization.couses.feather.feathers,
x.couselang.title
//x.organization.orgid.title,
}).ToList();

When submitting a place order button to order page that time generate this message

When submitting a place order button to order page that time generate this message.
How to resolve this error. Please help any one.
Order Object ( [id_address_delivery] => 88641 [id_address_invoice] => 88641 [id_shop_group] => 5 [id_shop] => 1 [id_cart] => 31973 [id_currency] => 1 [id_lang] => 1 [id_customer] => 27026 [id_carrier] => 73 [current_state] => [secure_key] => 353b960ec14efca0bf8145f79908794a [payment] => Authorize.net AIM (Advanced Integration Method) [module] => authorizeaim [conversion_rate] => 1.000000 [recyclable] => 0 [gift] => 0 [gift_message] => [mobile_theme] => 0 [shipping_number] => [total_discounts] => 0 [total_discounts_tax_incl] => 0 [total_discounts_tax_excl] => 0 [total_paid] => 6.5 [total_paid_tax_incl] => 6.5 [total_paid_tax_excl] => 6.5 [total_paid_real] => 0 [total_products] => 6.5 [total_products_wt] => 6.5 [total_shipping] => 0 [total_shipping_tax_incl] => 0 [total_shipping_tax_excl] => 0 [carrier_tax_rate] => 0 [hazmat_fees] => 0 [poison_fees] => 0 [refrigerated_fees] => 0 [ponumber] => [total_wrapping] => 0 [total_wrapping_tax_incl] => 0 [total_wrapping_tax_excl] => 0 [invoice_number] => [delivery_number] => [invoice_date] => 0000-00-00 00:00:00 [delivery_date] => 0000-00-00 00:00:00 [valid] => [date_add] => [date_upd] => [reference] => JYADOFQPY [webserviceParameters:protected] => Array ( [objectMethods] => Array ( [add] => addWs ) [objectNodeName] => order [objectsNodeName] => orders [fields] => Array ( [id_address_delivery] => Array ( [xlink_resource] => addresses ) [id_address_invoice] => Array ( [xlink_resource] => addresses ) [id_cart] => Array ( [xlink_resource] => carts ) [id_currency] => Array ( [xlink_resource] => currencies ) [id_lang] => Array ( [xlink_resource] => languages ) [id_customer] => Array ( [xlink_resource] => customers ) [id_carrier] => Array ( [xlink_resource] => carriers ) [current_state] => Array ( [xlink_resource] => order_states ) [module] => Array ( [required] => 1 ) [invoice_number] => Array ( ) [invoice_date] => Array ( ) [delivery_number] => Array ( ) [delivery_date] => Array ( ) [valid] => Array ( ) [date_add] => Array ( ) [date_upd] => Array ( ) ) [associations] => Array ( [order_rows] => Array ( [resource] => order_row [setter] => [virtual_entity] => 1 [fields] => Array ( [id] => Array ( ) [product_id] => Array ( [required] => 1 ) [product_attribute_id] => Array ( [required] => 1 ) [product_quantity] => Array ( [required] => 1 ) [product_name] => Array ( [setter] => ) [product_price] => Array ( [setter] => ) [unit_price_tax_incl] => Array ( [setter] => ) [unit_price_tax_excl] => Array ( [setter] => ) ) ) ) ) [_taxCalculationMethod:protected] => 1 [id] => [id_shop_list] => [get_shop_from_context:protected] => 1 [table:protected] => orders [identifier:protected] => id_order [fieldsRequired:protected] => Array ( [0] => id_address_delivery [1] => id_address_invoice [2] => id_cart [3] => id_currency [4] => id_lang [5] => id_customer [6] => id_carrier [7] => payment [8] => module [9] => total_paid [10] => total_paid_real [11] => total_products [12] => total_products_wt [13] => conversion_rate ) [fieldsSize:protected] => Array ( ) [fieldsValidate:protected] => Array ( [id_address_delivery] => isUnsignedId [id_address_invoice] => isUnsignedId [id_cart] => isUnsignedId [id_currency] => isUnsignedId [id_shop_group] => isUnsignedId [id_shop] => isUnsignedId [id_lang] => isUnsignedId [id_customer] => isUnsignedId [id_carrier] => isUnsignedId [current_state] => isUnsignedId [secure_key] => isMd5 [payment] => isGenericName [module] => isModuleName [recyclable] => isBool [gift] => isBool [gift_message] => isMessage [mobile_theme] => isBool [total_discounts] => isPrice [total_discounts_tax_incl] => isPrice [total_discounts_tax_excl] => isPrice [total_paid] => isPrice [total_paid_tax_incl] => isPrice [total_paid_tax_excl] => isPrice [total_paid_real] => isPrice [total_products] => isPrice [total_products_wt] => isPrice [total_shipping] => isPrice [total_shipping_tax_incl] => isPrice [total_shipping_tax_excl] => isPrice [carrier_tax_rate] => isFloat [hazmat_fees] => isPrice [poison_fees] => isPrice [refrigerated_fees] => isPrice [total_wrapping] => isPrice [total_wrapping_tax_incl] => isPrice [total_wrapping_tax_excl] => isPrice [shipping_number] => isTrackingNumber [conversion_rate] => isFloat [date_add] => isDate [date_upd] => isDate ) [fieldsRequiredLang:protected] => Array ( ) [fieldsSizeLang:protected] => Array ( ) [fieldsValidateLang:protected] => Array ( ) [tables:protected] => Array ( ) [image_dir:protected] => [image_format:protected] => jpg [def:protected] => Array ( [table] => orders [primary] => id_order [fields] => Array ( [id_address_delivery] => Array ( [type] => 1 [validate] => isUnsignedId [required] => 1 ) [id_address_invoice] => Array ( [type] => 1 [validate] => isUnsignedId [required] => 1 ) [id_cart] => Array ( [type] => 1 [validate] => isUnsignedId [required] => 1 ) [id_currency] => Array ( [type] => 1 [validate] => isUnsignedId [required] => 1 ) [id_shop_group] => Array ( [type] => 1 [validate] => isUnsignedId ) [id_shop] => Array ( [type] => 1 [validate] => isUnsignedId ) [id_lang] => Array ( [type] => 1 [validate] => isUnsignedId [required] => 1 ) [id_customer] => Array ( [type] => 1 [validate] => isUnsignedId [required] => 1 ) [id_carrier] => Array ( [type] => 1 [validate] => isUnsignedId [required] => 1 ) [current_state] => Array ( [type] => 1 [validate] => isUnsignedId ) [secure_key] => Array ( [type] => 3 [validate] => isMd5 ) [payment] => Array ( [type] => 3 [validate] => isGenericName [required] => 1 ) [module] => Array ( [type] => 3 [validate] => isModuleName [required] => 1 ) [recyclable] => Array ( [type] => 2 [validate] => isBool ) [gift] => Array ( [type] => 2 [validate] => isBool ) [gift_message] => Array ( [type] => 3 [validate] => isMessage ) [mobile_theme] => Array ( [type] => 2 [validate] => isBool ) [total_discounts] => Array ( [type] => 4 [validate] => isPrice ) [total_discounts_tax_incl] => Array ( [type] => 4 [validate] => isPrice ) [total_discounts_tax_excl] => Array ( [type] => 4 [validate] => isPrice ) [total_paid] => Array ( [type] => 4 [validate] => isPrice [required] => 1 ) [total_paid_tax_incl] => Array ( [type] => 4 [validate] => isPrice ) [total_paid_tax_excl] => Array ( [type] => 4 [validate] => isPrice ) [total_paid_real] => Array ( [type] => 4 [validate] => isPrice [required] => 1 ) [total_products] => Array ( [type] => 4 [validate] => isPrice [required] => 1 ) [total_products_wt] => Array ( [type] => 4 [validate] => isPrice [required] => 1 ) [total_shipping] => Array ( [type] => 4 [validate] => isPrice ) [total_shipping_tax_incl] => Array ( [type] => 4 [validate] => isPrice ) [total_shipping_tax_excl] => Array ( [type] => 4 [validate] => isPrice ) [carrier_tax_rate] => Array ( [type] => 4 [validate] => isFloat ) [hazmat_fees] => Array ( [type] => 4 [validate] => isPrice ) [poison_fees] => Array ( [type] => 4 [validate] => isPrice ) [refrigerated_fees] => Array ( [type] => 4 [validate] => isPrice ) [ponumber] => Array ( [type] => 3 ) [total_wrapping] => Array ( [type] => 4 [validate] => isPrice ) [total_wrapping_tax_incl] => Array ( [type] => 4 [validate] => isPrice ) [total_wrapping_tax_excl] => Array ( [type] => 4 [validate] => isPrice ) [shipping_number] => Array ( [type] => 3 [validate] => isTrackingNumber ) [conversion_rate] => Array ( [type] => 4 [validate] => isFloat [required] => 1 ) [invoice_number] => Array ( [type] => 1 ) [delivery_number] => Array ( [type] => 1 ) [invoice_date] => Array ( [type] => 5 ) [delivery_date] => Array ( [type] => 5 ) [valid] => Array ( [type] => 2 ) [reference] => Array ( [type] => 3 ) [date_add] => Array ( [type] => 5 [validate] => isDate ) [date_upd] => Array ( [type] => 5 [validate] => isDate ) ) [classname] => Order ) [update_fields:protected] => [product_list] => Array ( [0] => Array ( [hazmat_fees] => 0 [poison_pack] => 0 [refrigerated_fees] => 0 [drop_shipping] => 0 [id_product_attribute] => 0 [id_product] => 21930 [cart_quantity] => 1 [id_shop] => 1 [name] => Hot/cold Protective Mitt, 17" Length [is_virtual] => 0 [description_short] =>
• For extreme hot or cold applications
• Cotton coated with aluminized silicones
• Withstands 450°F in short int
[available_now] => [available_later] => [id_category_default] => 1181 [id_supplier] => 0 [id_manufacturer] => 0 [on_sale] => 0 [ecotax] => 0.000000 [additional_shipping_cost] => 0.00 [available_for_order] => 1 [price] => 6.5 [active] => 1 [unity] => [unit_price_ratio] => 0.000000 [quantity_available] => 106 [width] => 8.000000 [height] => 8.000000 [depth] => 8.000000 [out_of_stock] => 2 [weight] => 1.000000 [date_add] => 0000-00-00 00:00:00 [date_upd] => 2016-09-01 08:00:39 [quantity] => 1 [link_rewrite] => HOTCOLD-PROTECTIVE-MITT-17-LENGTH [category] => chemical-and-heat-gloves [unique_id] => 0000021930000000000088641 [id_address_delivery] => 88641 [wholesale_price] => 4.214648 [advanced_stock_management] => 0 [supplier_reference] => [id_customization] => [customization_quantity] => [reference] => 180-50591 [ean13] => [upc] => [minimal_quantity] => 1 [stock_quantity] => 106 [price_wt] => 6.5 [total_wt] => 6.5 [total] => 6.5 [id_image] => 21930-71813 [legend] => [reduction_applies] => [quantity_discount_applies] => [allow_oosp] => 1 [features] => Array ( ) [rate] => 0 [tax_name] => [warehouse_list] => Array ( [0] => ) [in_stock] => 1 [carrier_list] => Array ( [0] => 73 ) ) ) )
This is the ggetto order, this message appears in the presence of a:
var_dump ($ order);
in any file should appear that function.

how to execute stored procedure in cakephp 3?

This is my function for login i call a stored procedure login for match user name and password, but it doesn't work for me it give me all the rows:
public function login($email,$password)
{
$consumers = TableRegistry::get('Consumers');
$result=$consumers->query("Call login('".$email."','".$password."')");
pr($result->toArray());die;
}
My stored procedure in phpmyadmin is below:
BEGIN
SELECT * FROM consumers WHERE email = email_id AND password = md_password;
END
When i am executing query it give me object but after converting this object into array it give me all the row of table.output is:
<pre class="pr">Array
(
[0] => Cake\ORM\Entity Object
(
[_properties:protected] => Array
(
[id] => 1
[name] => jeevan
[email] => j#gmail.com
[password] => asdf
[phone_no] => 8447726137
[ota] => cde
[status] => 0
[created_on] => Cake\I18n\FrozenTime Object
(
[date] => 2016-07-08 17:28:52
[timezone_type] => 3
[timezone] => UTC
)
[token_access] =>
[device_type] => 1
[push_id] => abc
[want_news] => 1
[postal_code] => 263136
[registration_type] => 1
)
[_original:protected] => Array
(
)
[_hidden:protected] => Array
(
)
[_virtual:protected] => Array
(
)
[_className:protected] =>
[_dirty:protected] => Array
(
)
[_new:protected] =>
[_errors:protected] => Array
(
)
[_invalid:protected] => Array
(
)
[_accessible:protected] => Array
(
[*] => 1
)
[_registryAlias:protected] => Consumers
)
[1] => Cake\ORM\Entity Object
(
[_properties:protected] => Array
(
[id] => 2
[name] => jack
[email] => jack#gmail.com
[password] => 123
[phone_no] => 7409757656
[ota] => chb
[status] => 1
[created_on] => Cake\I18n\FrozenTime Object
(
[date] => 2016-07-20 06:10:14
[timezone_type] => 3
[timezone] => UTC
)
[token_access] => ghcvhgv
[device_type] => 0
[push_id] => hgnjh
[want_news] => 1
[postal_code] => 263136
[registration_type] => 1
)
[_original:protected] => Array
(
)
[_hidden:protected] => Array
(
)
[_virtual:protected] => Array
(
)
[_className:protected] =>
[_dirty:protected] => Array
(
)
[_new:protected] =>
[_errors:protected] => Array
(
)
[_invalid:protected] => Array
(
)
[_accessible:protected] => Array
(
[*] => 1
)
[_registryAlias:protected] => Consumers
)
)</pre>
that mean the stored procedure not working, any idea really help me, thanks in advance!
You can call a stored procedure using the ConnectionManager's execute() method. It's important to remember to prepare the query so that you remove the risk of SQL injection:-
$this->connection = ConnectionManager::get('default');
$results = $this->connection->execute(
'CALL login(?, ?)',
[$email, md5($password)]
)->fetchAll('assoc');
When CakePHP runs execute() it will substitute the ? with the escaped and quoted values of $email and md5($password). For further details check out the official docs on Preparing a statement.
step 1:use the class as use Cake\Datasource\ConnectionManager;
step 2: then execute the procedure-
$this->connection = ConnectionManager::get('default');
$consumer = $this->connection->execute("CALL login('".$email."','".md5($password)."')")->fetchAll('assoc');
now it will give an array.
finally i got this answer in cakephp cookbook.

How to create refund and register payment XML-RPC odoo

How can i create a refund and register payment for that refund in odoo via xml-rpc. The code that i have so far it creates the invoice for refund but it doesn't register any payment for that invoice, so the costumer refund invoice stays in open state even though a voucher is created and posted.
$invoiceData = $OERP->searchread(array(array('id','=',$invoiceId )), 'account.invoice');
$invoiceDatas = array();
foreach($invoiceData as $data)
{
$invoiceDatas["amount_total"] = $data["amount_total"];
$invoiceDatas["partner_id"] = $data["partner_id"];
$invoiceDatas["account_id"] = $data["account_id"];
$invoiceDatas["invoice_line"] = $data["invoice_line"];
$invoiceDatas["reference"] = $data["reference"];
$invoiceDatas["period_id"] = $data["period_id"];
}
$invoiceLineData = $OERP->searchread(array(array('invoice_id','=', intval($invoiceId) )), 'account.invoice.line');
foreach($invoiceLineData as $data)
{
$invoiceLine["product_id"] = $data["product_id"];
$invoiceLine["price_unit"] = $data["price_unit"];
}
$createRefundParams = array(
'date_invoice' => date('Y/m/d'),
'partner_id' => $invoiceDatas["partner_id"][0],
'journal_id' => 3,// $journalId,
'account_id' => $invoiceDatas["account_id"][0],
'name'=>'front end refundi',
'type'=>'out_refund' // dallon invoicen nga refund
);
$createRefund = $OERP->create($createRefundParams, 'account.invoice');
$invoiceProduct = array(
'invoice_id'=>$createRefund,
'product_id'=>$invoiceLine["product_id"][0],
'name'=>'refund',
'price_unit'=>$invoiceLine["price_unit"],
);
$createRefundLines = $OERP->create($invoiceProduct,"account.invoice.line");
$validateRefund = $OERP->workflow('account.invoice', 'invoice_open', $createRefund);
$amount_total = -$invoiceDatas['amount_total'];
$newInvoice = $OERP -> searchread(array(array('id','=',$createRefund)),'account.invoice' );
$moveId = array();
foreach($newInvoice as $data)
{
$moveId["move_id"] = $data["move_id"];
}
$createVoucher = array(
'date' => date('Y/m/d'),
'partner_id' => $invoiceDatas['partner_id'][0],
'amount' =>$amount_total ,
'journal_id' => 7,// $journalId,
'account_id' => 25,
'period_id' => $invoiceDatas['period_id'][0],
'type' => 'receipt'
);
$voucherResult = $OERP->create($createVoucher, 'account.voucher');
$invoice_object_line = $OERP->searchread(array(array('move_id', '=', $moveId["move_id"][0])), 'account.move.line');
$voucherLineItems = array(
'journal_id' => 7,// $journalId,
'period_id' => $invoiceDatas['period_id'][0],
'date' => date('Y/m/d'),
'date_due' => date('Y/m/d'),
'name' => 'Payment for refund',
'payment_option' => 'without_writeoff',
'amount_original' => -$amount_total,
// 'amount'=>-$amount_total,
'amount_unreconciled' => -$amount_total,
'voucher_id' => $voucherResult,//$voucher_id,
'partner_id' => $invoiceDatas['partner_id'][0],
'account_id' => $invoiceDatas['account_id'][0],
'move_line_id' => $invoice_object_line[0]["id"],
'type' => 'cr'
);
$createVoucherLine = $OERP->create($voucherLineItems, 'account.voucher.line');
$performa_voucher_result = $OERP->workflow('account.voucher', 'proforma_voucher', intval($voucherResult));
$invoiceMovId = $OERP->searchread(array(array('id','=',$createRefund)),'account.invoice' );
$button_validate_result = $OERP->button_click('account.move', 'button_validate', $invoiceMovId[0]["move_id"][0]);
I figured it out the answer to create an invoice refund here is the code if it helps anyone
$invoiceId = $_REQUEST["invoiceID"];
$OERP = new OpenERP();
$OERPUserID = $OERP->login($_SESSION['OERP-username'], $_SESSION['OERP-password']);
$invoiceData = $OERP->searchread(array(array('id','=',$invoiceId )), 'account.invoice');
$invoiceDatas = array();
foreach($invoiceData as $data)
{
$invoiceDatas["amount_total"] = $data["amount_total"];
$invoiceDatas["partner_id"] = $data["partner_id"];
$invoiceDatas["account_id"] = $data["account_id"];
$invoiceDatas["invoice_line"] = $data["invoice_line"];
$invoiceDatas["reference"] = $data["reference"];
$invoiceDatas["period_id"] = $data["period_id"];
}
$invoiceLineData = $OERP->searchread(array(array('invoice_id','=', intval($invoiceId) )), 'account.invoice.line');
foreach($invoiceLineData as $data)
{
$invoiceLine["product_id"] = $data["product_id"];
$invoiceLine["price_unit"] = $data["price_unit"];
}
//create Refund
$createRefundParams = array(
'date_invoice' => date('Y/m/d'),
'partner_id' => $invoiceDatas["partner_id"][0],
'journal_id' => 3,// $journalId,
'account_id' => $invoiceDatas["account_id"][0],
// 'reference'=>$invoiceDatas["reference"],
'name'=>'front end refundi',
'type'=>'out_refund' // dallon invoicen nga refund
);
$createRefund = $OERP->create($createRefundParams, 'account.invoice');
$invoiceProduct = array(
'invoice_id'=>$createRefund,
'product_id'=>$invoiceLine["product_id"][0],
'name'=>'refund',//$invoiceLine["product_id"][1],
'account_id'=>19,
'price_unit'=>$invoiceLine["price_unit"]
);
$createRefundLines = $OERP->create($invoiceProduct,"account.invoice.line");
$validateRefund = $OERP->workflow('account.invoice', 'invoice_open', $createRefund);
//================ Payments ===========================
$amount_total = -$invoiceDatas['amount_total'];
$newInvoice = $OERP -> searchread(array(array('id','=',$createRefund)),'account.invoice' );
$moveId = array();
foreach($newInvoice as $data)
{
$moveId["move_id"] = $data["move_id"];
}
$createVoucher = array(
'date' => date('Y/m/d'),
'partner_id' => $invoiceDatas['partner_id'][0],
'amount' =>$amount_total ,
'journal_id' => 7,// $journalId,
'account_id' => 25,
'period_id' => $invoiceDatas['period_id'][0],
'type' => 'receipt'
);
// $createRefund
$voucherResult = $OERP->create($createVoucher, 'account.voucher');
$invoice_object_line = $OERP->searchread(array(array('move_id', '=', $moveId["move_id"][0])), 'account.move.line');
$voucherLineItems = array(
//notice that amount values are positive since there is an extra minus in variable intialization
'journal_id' => 7,// $journalId,
'period_id' => $invoiceDatas['period_id'][0],
'date' => date('Y/m/d'),
'date_due' => date('Y/m/d'),
'name' => 'Payment for refund',
'payment_option' => 'without_writeoff',
'amount_original' => -$amount_total,
'amount'=>-$amount_total,
'amount_unreconciled' => -$amount_total,
'voucher_id' => $voucherResult,//$voucher_id,
'partner_id' => $invoiceDatas['partner_id'][0],
'account_id' => $invoiceDatas['account_id'][0],
'move_line_id' => $invoice_object_line[0]["id"],
'type' => 'dr'
);
$createVoucherLine = $OERP->create($voucherLineItems, 'account.voucher.line');
$performa_voucher_result = $OERP->workflow('account.voucher', 'proforma_voucher', intval($voucherResult));
$invoiceMovId = $OERP->searchread(array(array('id','=',$createRefund)),'account.invoice' );
$button_validate_result = $OERP->button_click('account.move', 'button_validate', $invoiceMovId[0]["move_id"][0]);

Cannot return the correct order with GetSellingManagerSaleRecord

I am using the eBay SDK for PHP at devbay.net.
First I am loading GetSellingManagerSoldListings, searching for SaleRecordID=129317:
$service = new TradingService();
$request = new Types\GetSellingManagerSoldListingsRequestType();
$request->Search = new Types\SellingManagerSearchType();
$request->Search->SearchType = 'SaleRecordID';
$request->Search->SearchValue = '129317';
$result = $service->GetSellingManagerSoldListings($request);
print_r($result->SaleRecord[0]);
Which gives the following response:
DTS\eBaySDK\Trading\Types\SellingManagerSoldOrderType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[SellingManagerSoldTransaction] => DTS\eBaySDK\Types\UnboundType Object
(
[data:DTS\eBaySDK\Types\UnboundType:private] => Array
(
[0] => DTS\eBaySDK\Trading\Types\SellingManagerSoldTransactionType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[TransactionID] => *removed*
[SaleRecordID] => 129242
[ItemID] => *removed*
[QuantitySold] => 1
[ItemTitle] => *removed*
[ListingType] => FixedPriceItem
[Relisted] =>
[SecondChanceOfferSent] =>
[CustomLabel] => *removed*
[SoldOn] => eBay
[ListedOn] => DTS\eBaySDK\Types\UnboundType Object
(
[data:DTS\eBaySDK\Types\UnboundType:private] => Array
(
[0] => eBay
)
[position:DTS\eBaySDK\Types\UnboundType:private] => 0
[class:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Trading\Types\SellingManagerSoldTransactionType
[property:DTS\eBaySDK\Types\UnboundType:private] => ListedOn
[expectedType:DTS\eBaySDK\Types\UnboundType:private] => string
)
[CharityListing] =>
[OrderLineItemID] => *removed*
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
[1] => DTS\eBaySDK\Trading\Types\SellingManagerSoldTransactionType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[TransactionID] => *removed*
[SaleRecordID] => 129243
[ItemID] => *removed*
[QuantitySold] => 1
[ItemTitle] => *removed*
[ListingType] => FixedPriceItem
[Relisted] =>
[SecondChanceOfferSent] =>
[CustomLabel] => *removed*
[SoldOn] => eBay
[ListedOn] => DTS\eBaySDK\Types\UnboundType Object
(
[data:DTS\eBaySDK\Types\UnboundType:private] => Array
(
[0] => eBay
)
[position:DTS\eBaySDK\Types\UnboundType:private] => 0
[class:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Trading\Types\SellingManagerSoldTransactionType
[property:DTS\eBaySDK\Types\UnboundType:private] => ListedOn
[expectedType:DTS\eBaySDK\Types\UnboundType:private] => string
)
[CharityListing] =>
[OrderLineItemID] => *removed*
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
)
[position:DTS\eBaySDK\Types\UnboundType:private] => 0
[class:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Trading\Types\SellingManagerSoldOrderType
[property:DTS\eBaySDK\Types\UnboundType:private] => SellingManagerSoldTransaction
[expectedType:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Trading\Types\SellingManagerSoldTransactionType
)
[ShippingAddress] => DTS\eBaySDK\Trading\Types\AddressType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[Name] => *removed*
[PostalCode] => 2761
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
[ShippingDetails] => DTS\eBaySDK\Trading\Types\ShippingDetailsType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[ShippingType] => NotSpecified
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
[TotalAmount] => DTS\eBaySDK\Trading\Types\AmountType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[currencyID] => AUD
[value] => 294.95
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
[TotalQuantity] => 2
[ActualShippingCost] => DTS\eBaySDK\Trading\Types\AmountType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[currencyID] => AUD
[value] => 0
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
[OrderStatus] => DTS\eBaySDK\Trading\Types\SellingManagerOrderStatusType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[CheckoutStatus] => CheckoutComplete
[PaidStatus] => PartiallyPaid
[ShippedStatus] => Shipped
[PaymentMethodUsed] => PayPal
[FeedbackSent] => 1
[TotalEmailsSent] => 3
[ShippedTime] => DateTime Object
(
[date] => 2015-04-06 21:10:09
[timezone_type] => 2
[timezone] => Z
)
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
[SalePrice] => DTS\eBaySDK\Trading\Types\AmountType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[currencyID] => AUD
[value] => 589.9
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
[DaysSinceSale] => 5
[BuyerID] => *removed*
[BuyerEmail] => *removed*
[SaleRecordID] => 129317
[CreationTime] => DateTime Object
(
[date] => 2015-04-03 10:19:48
[timezone_type] => 2
[timezone] => Z
)
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
Next I want to load the related GetSellingManagerSaleRecord. The problem is I cannot find a combination of IDs that will load the correct record. Here are my attempts:
loads wrong result, SalesRecordID=129242 .. I need 129317:
$service = new TradingService();
$request = new Types\GetSellingManagerSaleRecordRequestType();
$request->OrderLineItemID = $result->SaleRecord[0]->SellingManagerSoldTransaction[0]->OrderLineItemID;
$result2 = $service->GetSellingManagerSaleRecord($request);
loads wrong result, SalesRecordID=129243 .. I need 129317:
$service = new TradingService();
$request = new Types\GetSellingManagerSaleRecordRequestType();
$request->OrderLineItemID = $result->SaleRecord[0]->SellingManagerSoldTransaction[1]->OrderLineItemID;
$result2 = $service->GetSellingManagerSaleRecord($request);
ErrorCode 21916340, Sale record doesnt exist:
$service = new TradingService();
$request = new Types\GetSellingManagerSaleRecordRequestType();
$transaction = $result->SaleRecord[0]->SellingManagerSoldTransaction[0];
$request->OrderLineItemID = $transaction->ItemID . '-' . $transaction->TransactionID;
$result2 = $service->GetSellingManagerSaleRecord($request);
ErrorCode 21916340, Sale record doesnt exist:
$service = new TradingService();
$request = new Types\GetSellingManagerSaleRecordRequestType();
$request->OrderID = $result->SaleRecord[0]->SaleRecordID;
$result2 = $service->GetSellingManagerSaleRecord($request);
ErrorCode 21916340, Sale record doesnt exist:
$service = new TradingService();
$request = new Types\GetSellingManagerSaleRecordRequestType();
$transaction = $result->SaleRecord[0]->SellingManagerSoldTransaction[0];
$request->ItemID = $transaction->ItemID;
$request->TransactionID = $transaction->TransactionID;
$result2 = $service->GetSellingManagerSaleRecord($request);
I'm not to familiar with the after sales side of the eBay API but depending on what you are trying to achieve the following may work.
Since GetSellingManagerSaleRecord won't allow you to pass a known SaleRecordID you can send it an OrderID instead. As each SaleRecord has an associated Order you can get it's ID by using GetOrders.
$service = new TradingService();
$request = new Types\GetSellingManagerSoldListingsRequestType();
$request->Search = new Types\SellingManagerSearchType();
$request->Search->SearchType = 'SaleRecordID';
$request->Search->SearchValue = '129317';
$response = $service->GetSellingManagerSoldListings($request);
/**
* Get the OrderLineItemID of the first transaction in the Sale Record.
* This would work as well as all the transactions will come from the same order.
* $orderLineItemID = $response->SaleRecord[0]->SellingManagerSoldTransaction[1]->OrderLineItemID;
*/
$orderLineItemID = $response->SaleRecord[0]->SellingManagerSoldTransaction[0]->OrderLineItemID;
/**
* Now look up the order.
*/
$request = new Types\GetOrdersRequestType();
$request->OrderIDArray = new Types\OrderIDArrayType();
$request->OrderIDArray->OrderID[] = $orderLineItemID;
$response = $service->getOrders($request);
$orderID = $response->OrderArray->Order[0]->OrderID;
/**
* Now use the OrderID to call GetSellingManagerSaleRecord.
*/
$request = new Types\GetSellingManagerSaleRecordRequestType();
$request->OrderID = $orderID;
$response = $service->getSellingManagerSaleRecord($request);
/**
* Check we got the correct SaleRecord.
*/
$saleRecordID = $response->SellingManagerSoldOrder->SaleRecordID;
assert('$saleRecordID === 129317');
In addition to calling GetSellingManagerSoldListings you can also call GetOrders to obtain a list of SaleRecordIDs. For example:
$request = new Types\GetOrdersRequestType();
$request->NumberOfDays = 30;
$response = $service->getOrders($request);
foreach ($response->OrderArray->Order as $order) {
printf("SaleRecordID %s\n", $order->ShippingDetails->SellingManagerSalesRecordNumber);
}