I am have trouble converting array to xml here as the CustomerOrderLines are getting repeated, the xml generated gets only the last [CustomerOrderLines] value, how do i generate an xml with all the objects.
public function ProcessOrderAction(){
$subTotal = Mage::getModel('checkout/cart')->getQuote()->getSubtotal();
$grandTotal = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal();
$quoteId = Mage::getSingleton('checkout/session')->getQuoteId();
$quote = Mage::getModel("sales/quote")->load($quoteId);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
$customerData = Mage::getSingleton('customer/session')->getCustomer();
$customerAddress = array();
$_orders = Mage::getModel('sales/order')->getCollection()- >addFieldToFilter('customer_id',$customerData->getId());
$_orderCnt = $_orders->count(); //orders count
if($_orderCnt == 0){
$CustomerOperation="Create";
}else{
$CustomerOperation="Find";
}
$soapClient = new SoapClient("https://api.ongoingsystems.se/Colliflow/service.asmx?wsdl", array('trace' => 1));
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
$store = Mage::app('checkout/session')->getStore();
$ap_param = array(
'GoodsOwnerCode'=>'Test',
'UserName' => 'test',
'Password' => 'test',
'co'=> [
'OrderInfo'=>[
'OrderIdentification' => 'SystemId',
'OrderOperation' => 'Create',
'GoodsOwnerOrderNumber' => '1111',
'OrderId' => '',
'GoodsOwnerOrderId' => '102',
'DeliveryDate' => '2016-05-14T22:16:00',
'OrderType'=> [
'OrderTypeOperation' => 'CreateOrFind',
'OrderTypeIdentification' => 'OrderTypeCode'
]
],
'Customer'=> [
'CustomerOperation' => $CustomerOperation,
'CustomerIdentification' => 'CustomerNumber',
'ExternalCustomerCode' => 'ExternalCustomerCode',
'CustomerNumber' => ''.$customerData->getId(),
'CustomerId' => ''.$customerData->getId(),
'Name' => ''.$customerData->getName(),
'Address' => ''.$customerAddress['region'],
'PostCode' => ''.$customerAddress['postcode'],
'City' => ''.$customerAddress['city'],
'TelePhone' => ''.$customerAddress['telephone'],
'Remark' => 'Remarks',
'IsVisible'=>'true',
'NotifyBySMS'=> 'true',
'NotifyByEmail'=> 'false',
'NotifyByTelephone'=>'false',
'Email' => ''.$customerData->getEmail(),
'MobilePhone' => ''.$customerAddress['telephone'],
'CountryCode' =>'NO',
'CountryStateCode' => '90'
],
'CustomerOrderLines' => [
'CustomerOrderLine'=> [
'OrderLineIdentification' => 'ArticleNumber',
'ArticleIdentification' => 'ArticleNumber',
'OrderLineSystemId' => '123',
'ExternalOrderLineCode' => 'ExternalOrderLineId',
'ArticleSystemId' => '123',
'ArticleNumber' => ''.$item->getSku(),
'ArticleName' => ''.$item->getName(),
'NumberOfItems' => '6',
'ProductCode' => ''.$item->getProductId()
],
'CustomerOrderLine'=> [
'OrderLineIdentification' => 'ArticleNumber',
'ArticleIdentification' => 'ArticleNumber',
'OrderLineSystemId' => '1231',
'ExternalOrderLineCode' => 'ExternalOrderLineId',
'ArticleSystemId' => '1230',
'ArticleNumber' => '0000099',
'ArticleName' => 'test222',
'NumberOfItems' => '6',
'ProductCode' => '6786978'
]
]
]
);
print_r($ap_param);
$error = 0;
try {
$info = $soapClient->__call("ProcessOrder", array($ap_param));
}catch (SoapFault $fault) {
$error = 1;
print("
alert('Sorry, returned the following ERROR: ".$fault->faultcode."-".$fault->faultstring.". We will now take you back to our home page.');
window.location = 'main.php'; ");
}
if ($error == 0) {
$auth_num = $info->ProcessOrderResult;
print_r($auth_num);
}
}
Related
I am trying to determine which elements coincide in 2 arrays. The issue is that only the last element in my second array is selected instead of all 3. What am I missing here?
<?php
$containers = [
0 => ['id'=>'1', 'name'=>'Peta'],
1 => ['id'=>'2', 'name'=>'Epta'],
3 => ['id'=>'3', 'name'=>'Fras'],
4 => ['id'=>'4', 'name'=>'Maxs'],
5 => ['id'=>'5', 'name'=>'Gtay'],
6 => ['id'=>'6', 'name'=>'Prat'],
7 => ['id'=>'7', 'name'=>'Drat'],
];
$invoices = [
0 => ['id'=>'1', 'name'=>'Lebo'],
1 => ['id'=>'3', 'name'=>'Efta'],
2 => ['id'=>'4', 'name'=>'Gadr'],
];
foreach ($containers as $container) {
foreach ($invoices as $invoice) {
if (in_array($container['id'], $invoice)) {
$selected = 'selected';
} else {
$selected = '';
}
}
echo $container['name'].' -> '.$selected.'<br>';
} ?>
Add "break" after found in array.
<?php
$containers = [
0 => ['id' => '1', 'name' => 'Peta'],
1 => ['id' => '2', 'name' => 'Epta'],
3 => ['id' => '3', 'name' => 'Fras'],
4 => ['id' => '4', 'name' => 'Maxs'],
5 => ['id' => '5', 'name' => 'Gtay'],
6 => ['id' => '6', 'name' => 'Prat'],
7 => ['id' => '7', 'name' => 'Drat'],
];
$invoices = [
0 => ['id' => '1', 'name' => 'Lebo'],
1 => ['id' => '3', 'name' => 'Efta'],
2 => ['id' => '4', 'name' => 'Gadr'],
];
foreach ($containers as $container) {
foreach ($invoices as $invoice) {
if (in_array($container['id'], $invoice)) {
$selected = 'selected';
break;
} else {
$selected = '';
}
}
echo $container['name'] . ' -> ' . $selected . '<br>';
} ?>
$containers = [
[ 'id' => '1', 'name' => 'Peta' ],
[ 'id' => '2', 'name' => 'Epta' ],
[ 'id' => '3', 'name' => 'Fras' ],
[ 'id' => '4', 'name' => 'Maxs' ],
[ 'id' => '5', 'name' => 'Gtay' ],
[ 'id' => '6', 'name' => 'Prat' ],
[ 'id' => '7', 'name' => 'Drat' ],
];
$invoices = [
[ 'id' => '1', 'name' => 'Lebo' ],
[ 'id' => '3', 'name' => 'Efta' ],
[ 'id' => '4', 'name' => 'Gadr' ],
];
$result = array_filter(
$containers,
fn($item) => in_array($item['id'], array_column($invoices, 'id'))
);
print_r($result);
Output:
Array
(
[0] => Array
(
[id] => 1
[name] => Peta
)
[2] => Array
(
[id] => 3
[name] => Fras
)
[3] => Array
(
[id] => 4
[name] => Maxs
)
)
Seems the easiest solution was to create a new array:
foreach ($invoices as $invoice) {
$compare_id[] = $invoice['id'];
}
foreach ($containers as $container) {
if (in_array($container['id'], $compare_id)) {
$selected = 'selected';
} else {
$selected = '';
}
echo $container['name'].' -> '.$selected.'<br>';
}
I have data im getting from mongodb to arrays and I want to work on the return data to split it by date and some other value , this is what I got so far and I need some help with the results
<?php
$stats=array(
array("source"=>501,"status"=>"answered","dest"=>"100","date"=>"2022-17-01"),
array("source"=>501,"status"=>"noAnswer","dest"=>"120","date"=>"2022-17-01"),
array("source"=>501,"status"=>"answered","dest"=>"100","date"=>"2022-18-01"),
array("source"=>502,"status"=>"answered","dest"=>"120","date"=>"2022-17-01"),
array("source"=>502,"status"=>"answered","dest"=>"130","date"=>"2022-17-01"),
array("source"=>502,"status"=>"answered","dest"=>"110","date"=>"2022-18-01")
);
$new1 = array();
$answer = 0;
$noanswer = 0;
$lastsrc = '';
$lastdate = '';
$dest=0;
foreach ($stats as $new) {
$src = $new['source'];
$date = $new['date'];
if ( $lastsrc == $src && $lastdate == $date ) {
$dest++;
if($new['status'] == 'answered'){ $answer++; }
if($new['status'] == 'noanswer'){ $noanswer++;}
$new1[] = array('source' => $src,
'date' => $date,
'ans' => $answer,
'nonans' => $noanswer,
'dest' => $dest );
} else if ( $lastsrc == $src && $lastdate != $date ) {
$dest++;
if($new['status'] == 'answered'){ $answer++;}
if($new['status'] == 'noanswer'){ $noanswer++;}
$new1[] = array('source' => $src,
'date' => $date,
'ans' => $answer,
'nonans' => $noanswer,
'dest' => $dest );
} else {
$dest++;
if($new['status'] == 'answered'){ $answer++; }
if($new['status'] == 'noanswer'){ $noanswer++;}
$new1[] = array('source' => $src,
'date' => $date,
'ans' => $answer,
'nonans' => $noanswer,
'dest' => $dest );
$lastsrc = $src;
$lastdate = $date;
}
}
print_r($new1);
?>
what im trying to achieve is splitting the Data by date and by source as well, so if in foreach loop I found same source and same date then I modify the array instead of create new array, if its the opposite then create new array
the result im trying to get is :
array("source"=>501,"ans"=>"1","noans" => 0,"dest"=>1,"date"=>"2022-17-01"),
array("source"=>501,"ans"=>"1","noAnswer" => 1,"dest"=>2,"date"=>"2022-18-01"),
array("source"=>502,"ans"=>"2","noans" => 0,"dest"=>2,"date"=>"2022-17-01"),
array("source"=>502,"ans"=>"1","noans" => 0,"dest"=>1,"date"=>"2022-18-01")
im not sure if its the right way ,any help will be very appreciated thanks
<?php
$stats = [
[ 'source' => 501, 'status' => 'answered', 'dest' => '100', 'date' => '2022-17-01' ],
[ 'source' => 501, 'status' => 'noAnswer', 'dest' => '120', 'date' => '2022-17-01' ],
[ 'source' => 501, 'status' => 'answered', 'dest' => '100', 'date' => '2022-18-01' ],
[ 'source' => 502, 'status' => 'answered', 'dest' => '120', 'date' => '2022-17-01' ],
[ 'source' => 502, 'status' => 'answered', 'dest' => '130', 'date' => '2022-17-01' ],
[ 'source' => 502, 'status' => 'answered', 'dest' => '110', 'date' => '2022-18-01' ]
];
$result = [];
foreach ($stats as $stat) {
$source = $stat['source'];
$date = $stat['date'];
$closure = static fn($item) => $item['source'] === $source && $item['date'] === $date;
$found = array_filter($result, $closure);
if (count($found) === 0) {
$list = array_filter($stats, $closure);
$list = array_map(static fn($item) => [ 'status' => $item['status'], 'dest' => $item['dest'] ], $list);
$result[] = [
'source' => $source,
'date' => $date,
'answered' => count(array_filter(array_column($list, 'status'), static fn($item) => $item === 'answered')),
'noAnswer' => count(array_filter(array_column($list, 'status'), static fn($item) => $item === 'noAnswer')),
'dest' => count(array_column($list, 'dest')),
];
}
}
print_r($result);
Create a composite key from the fields you want to sort by and use an associative array. (A single level in the array makes sorting/merging as well as extracting the values(array_values()) afterwards easy) Then you only need to iterate over $stats and $result once each.
$result = [];
foreach($stats as $stat) {
$key = $stat['source'].'_'.$stat['date'];
if (!array_key_exists($key, $result)) {
$result[$key] = ['answered' => 0, 'noAnswer' => 0] + $stat;
}
$result[$key][$stat['status']]++;
$result[$key]['dest'][$stat['dest']] = 1;
}
$result = array_map( // Transform "destinations key store" to count
function($item) {
$item['dest'] = count($item['dest']); return $item;
},
$result
);
print_r(array_values($result));
['source' => 501, 'status' => answered, 'dest' => 2, 'date' => 2022-17-01, 'answered' => 1, 'noAnswer' => 1],
['source' => 501, 'status' => answered, 'dest' => 1, 'date' => 2022-18-01, 'answered' => 1, 'noAnswer' => 0],
['source' => 502, 'status' => answered, 'dest' => 2, 'date' => 2022-17-01, 'answered' => 2, 'noAnswer' => 0],
['source' => 502, 'status' => answered, 'dest' => 1, 'date' => 2022-18-01, 'answered' => 1, 'noAnswer' => 0]
Screenshot
As you see my data are loaded inside extra SNHISTORY array and I need to remove that extra array.
Code
Lines regarding to screenshot results are commented.
$array = [];
foreach($internalTransits as $key => $item) {
foreach($item->barcodes as $barcode){}
$a = $item->barcodes;
$grouped = $a->mapToGroups(function ($item, $key) {
return [
'SNHISTORY' => [ // my arrays to move out
'_attributes' => [
'operation' => 'Ret'
],
'SERIALNUMBER' => $item['serial_number'] ? $item['serial_number'] : $item['u_serial_number'],
'EXPIREDDATE' => $item['created_at']->format('Y-m-d'),
'QUANTITY' => '1',
'SNSIGN' => '-1',
],
'ITEMUNIT' => $item['product']['unit'],
'UNITPRICE' => $item['product']['price'],
];
});
$year = Carbon::createFromFormat('Y-m-d H:i:s', $item['created_at'])->year;
$month = Carbon::createFromFormat('Y-m-d H:i:s', $item['created_at'])->month;
$timeline[$key][] = [
'_attributes' => [
'operation' => 'Add'
],
'KeyID' => $barcode['product']['id'],
'ITEMNO' => $barcode['product']['sku'],
'QUANTITY' => '1',
'ITEMUNIT' => $barcode['product']['unit'],
'UNITRATIO' => '1',
'ITEMRESERVED1' => '',
'ITEMRESERVED2' => '',
'ITEMRESERVED3' => '',
'ITEMRESERVED4' => '',
'ITEMRESERVED5' => '',
'ITEMRESERVED6' => '',
'ITEMRESERVED7' => '',
'ITEMRESERVED8' => '',
'ITEMRESERVED9' => '',
'ITEMRESERVED10' => '',
'UNITPRICE' => $barcode['product']['price'],
'QTYCONTROL' => '0',
'SNHISTORY' => $grouped->toArray(), // this has extra array where my actual arrays are loaded inside of it
];
$array['TRANSACTIONS'] = [
'_attributes' => [
'OnError' => 'CONTINUE'
],
];
$array['TRANSACTIONS']['WTRAN'] = [
'_attributes' => [
'operation' => 'Add',
'REQUESTID' => '1',
],
'TRANSFERID' => $item['id'],
'TRANSACTIONID' => '',
'TRANSFERNO' => $item['transNu'],
'TRANSFERDATE' => $item['created_at']->format('Y-m-d'),
'DESCRIPTION' => $item['description'],
'FROMWHID' => $barcode['outlet'][0]['name'],
'TOWHID' => $item->toOutlet->name,
'FROMWHADDRESS' => '',
'TOWHADDRESS' => '',
];
$array['TRANSACTIONS']['WTRAN']['ITEMLINE'] = $timeline;
}
What I've tried
I cannot change 'SNHISTORY' => $grouped->toArray(), to something like $grouped->toArray(), under $timeline[$key][] = [ it will return error
I cannot add $array['TRANSACTIONS']['WTRAN']['ITEMLINE']['SNHISTORY'] = $grouped->toArray(); and remove 'SNHISTORY' => $grouped->toArray(), it will return error known bug
Question
How can I remove extra SNHISTORY around my data?
As mentioned in the comments section, you probably want to merge both arrays together:
$timeline[$key][] = [
'_attributes' => [
'operation' => 'Add'
],
'KeyID' => $barcode['product']['id'],
'ITEMNO' => $barcode['product']['sku'],
'QUANTITY' => '1',
'ITEMUNIT' => $barcode['product']['unit'],
'UNITRATIO' => '1',
'ITEMRESERVED1' => '',
'ITEMRESERVED2' => '',
'ITEMRESERVED3' => '',
'ITEMRESERVED4' => '',
'ITEMRESERVED5' => '',
'ITEMRESERVED6' => '',
'ITEMRESERVED7' => '',
'ITEMRESERVED8' => '',
'ITEMRESERVED9' => '',
'ITEMRESERVED10' => '',
'UNITPRICE' => $barcode['product']['price'],
'QTYCONTROL' => '0',
] + $grouped->toArray();
as i can see in your screen shot data
you are getting xml data you need to convert that into array
function xmlToArray($xml_string)
{
$doc = #simplexml_load_string($xml_string);
if ($doc) {
$xml = simplexml_load_string($xml_string);
$json = json_encode($xml);
return json_decode($json, true);
}
}
then u will get real array then u don't need to remove that as that is a parent key
I have an application I am trying to update from legacy to new driver. I am having a problem with collections being damaged when the below code is triggered. I think I have narrowed it down here.
function update($collection,$criteria,$data,$insertIfNotExists = false)
{
if(!empty($collection) && !empty($criteria) && !empty($data)) {
if (!isset($this->collection[$collection])) {
$this->collection[$collection] = (new MongoDB\Client)->hebe->{$collection};
}
if ($insertIfNotExists) {
$oldData = $this->collection[$collection]->findOne($criteria);
if ($oldData == NULL) {
$data['createdDate'] = date("Y-m-d H:i:s");
$data['modifiedDate'] = (isset($data['modifiedDate'])) ? $data['modifiedDate']:date("Y-m-d H:i:s");
/*
return ($this->collection[$collection]->insertOne($data)) ? array('status'=>'ok'):array('status'=>'error','error'=>'unknown_error');
*/
} else {
$newData = $oldData;
foreach($data as $n=>$v) {
$newData[$n] = $v;
}
$newData['modifiedDate'] = (isset($newData['modifiedDate'])) ? $newData['modifiedDate']:date("Y-m-d H:i:s");
/*
return ($this->collection[$collection]->updateOne($criteria,['$set' => $newData])) ? array('status'=>'ok'):array('status'=>'error','error'=>'unknown_error');
*/
}
} else {
/*
return ($this->collection[$collection]->updateOne($criteria,['$set' => $data])) ? array('status'=>'ok'):array('status'=>'error','error'=>'unknown_error');
*/
}
}
}
example variables are
$collection = 'customer'
$criteria = array ( 'number' => '9999',)
$data = array (
'number' => '9999',
'name' => 'Testing Account',
'reference' => 'Peter Smith',
'defaultDeliveryAddress' => 1,
'visitAddress' => '',
'address' => '',
'district' => 'Marknad',
'postAddress' => '',
'orgNumber' => '5562041771',
'phone' => '031-7802700',
'fax' => '031-193328',
'groupCode' => 'int',
'creditCustomer' => '',
'typeOfDelivery' => 'Bil',
'typeOfPayment' => '10',
'emailAddresses' =>
array (
'invoice' => 'email1#domain.com',
'order' => 'email2#domain.com',
'deliveryNote' => 'email3#domain.com',
'packingSlip' => 'email4#domain.com',
),
'orderType' => NULL,
'termsOfDelivery' => 'RC',
'creditLimit' => 100000.0,
'pricelist' => 4,
'pricelist1' => '',
'pricelist2' => '9998',
'pricelist3' => '104',
'discount' => NULL,
'countryCode' => 'SE',
'currencyCode' => 'SEK',
'blocked' => 0,
'deliveryCost' => 0,
'vatCode' => '2',
'email' => 'peremail#domain.com',
'password' => 'password',
'modifiedDate' => '2019-06-25 00:00:00',
'deliveryAddresses' =>
array (
0 =>
array (
'row' => 1,
'name' => 'Test Address',
'address' => 'Box 12345',
'postAddress' => '42246',
'default' => true,
),
1 =>
array (
'number' => '9999',
'name' => 'Testing Address',
'reference' => '13232',
'address' => 'Box 12245',
'postAddress' => '42246',
),
),
'references' =>
array (
0 =>
array (
'number' => '9999',
'name' => 'Testing',
'email' => '',
'password' => '',
),
1 =>
array (
'number' => '9999',
'name' => 'Testing2',
'email' => '',
'password' => 'password',
),
2 =>
array (
'number' => '9999',
'name' => 'Peter Smith',
'email' => '',
'password' => 'password',
),
),
)
Can someone point me in the right direction on what I am doing wrong with updateOne and insertOne. From what I understand by the docs is it supports array.
EDIT: a little background is I upgraded this system and MongoDB from 2.6 to 3.6. I also upgraded mongodb driver from legacy mongo.
The problem was the old data in the collection had quotations and the updateOne/insertOne data did not. Correcting this seem to solve the problem.
Well Im new to YII 1.1 framework and I have to debug a code.Here the widget CGridView sorts date as number rather than date. That is 01-02-2017,10-01-2017,15-01-2017,21-12-2016.
It should sort with month and year that is 21-12-2016,10-01-2017,15-01-2017,01-02-2017.
My code for view is following :-
<article class="listBox list-view">
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'child-invoice-payments-grid',
'htmlOptions' => array('class' => 'table-responsive'),
'itemsCssClass' => 'table invoiceTable',
'summaryText' => '',
'dataProvider' => new CArrayDataProvider($response, array(
'id' => 'id',
'sort' => array(
//'defaultOrder'=>'date_of_payment ASC',
'attributes' => array(
'date_of_payment','id', 'payment_mode','type','amount'
)
),
'pagination' => array(
'pageSize' => 10
)
)),
'enablePagination' => true,
'pagerCssClass' => 'text-center',
'pager' => array(
'header' => '',
'maxButtonCount' => 4,
'firstPageLabel' => '<<',
'prevPageLabel' => '<',
'nextPageLabel' => '>',
'lastPageLabel' => '>>',
'pageSize' => 5,
'htmlOptions' => array(
'class' => 'pagination',
)
),
'columns' => array(
array(
'name' => 'id',
'type' => 'raw',
'header' => 'Transaction ID',
'value' => 'CHtml::link($data["id"], $data["url"])'
),
**array(
'name' => 'date_of_payment',
'type' => 'raw',
'header' => 'Payment Date',
'value' => 'CHtml::link($data["date_of_payment"], $data["url"])'
)**,
array(
'name' => 'payment_mode',
'type' => 'raw',
'header' => 'Payment Mode',
'value' => 'CHtml::link($data["payment_mode"], $data["url"])'
),
array(
'name' => 'type',
'type' => 'raw',
'header' => 'Payment Type',
'value' => 'CHtml::link($data["type"], $data["url"])'
),
array(
'name' => 'amount',
'type' => 'raw',
'header' => 'Amount',
'value' => 'CHtml::link($data["amount"], $data["url"])'
)
)
));
?>
</article>
and the code for the controller is as follows :-
public function actionPayments($child_id) {
$response = array();
$criteria = new CDbCriteria();
$criteria->condition = "child_id = :child_id AND (invoice_type = 0 OR invoice_type = 1)";
$criteria->params = array(':child_id' => $child_id);
$invoiceModel = ChildInvoice::model()->findAll($criteria);
if (!empty($invoiceModel)) {
foreach ($invoiceModel as $invoice) {
$transactionModel = ChildInvoiceTransactions::model()->findAllByAttributes(array(
'invoice_id' => $invoice->id, 'credit_note_id' => NULL, 'payment_id' => NULL));
if (!empty($transactionModel)) {
foreach ($transactionModel as $transaction) {
$temp = array();
$temp['id'] = "Invoice Payment-" . $transaction->id;
$temp['amount'] = $transaction->paid_amount;
$temp['date_of_payment'] = $transaction->date_of_payment;
$temp['payment_mode'] = customFunctions::getPaymentOptionName($transaction->payment_mode);
$temp['type'] = "Invoice Payment";
$temp['url'] = Yii::app()->createUrl('childInvoice/view', array('child_id' => $invoice->child_id,
'invoice_id' => $invoice->id));
$response[] = $temp;
}
}
}
}
$creditNotesModel = ChildInvoice::model()->findAllByAttributes(array('child_id' => $child_id,
'invoice_type' => 3, 'is_deposit' => 1), array('order' => 'invoice_date'));
if (!empty($creditNotesModel)) {
foreach ($creditNotesModel as $creditNote) {
$temp = array();
$temp['id'] = "Credit Note-" . $creditNote->invoiceUrn;
$temp['amount'] = sprintf("%0.2f", -$creditNote->total);
$temp['date_of_payment'] = $creditNote->invoice_date;
$temp['payment_mode'] = $creditNote->description;
$temp['type'] = "Deposit";
$temp['url'] = Yii::app()->createUrl('childInvoice/updateCreditNote', array(
'id' => $creditNote->id, 'child_id' => $creditNote->child_id));
$response[] = $temp;
}
}
$paymentsModel = Payments::model()->findAllByAttributes(array('branch_id' => Yii::app()->session['branch_id']), array(
'order' => 'date_of_payment'));
if (!empty($paymentsModel)) {
foreach ($paymentsModel as $payments) {
if (in_array($child_id, explode(",", $payments->child_id))) {
$temp = array();
$temp['id'] = "Payment-" . $payments->id;
$temp['amount'] = sprintf("%0.2f", $payments->amount);
$temp['date_of_payment'] = $payments->date_of_payment;
$temp['payment_mode'] = customFunctions::getPaymentOptionName($payments->payment_mode);
$temp['type'] = "Payments";
$temp['url'] = Yii::app()->createUrl('payments/view', array('id' => $payments->id));
$response[] = $temp;
}
}
}
usort($response, function($i, $j) {
$a = strtotime(date("Y-m-d", strtotime($i['date_of_payment'])));
$b = strtotime(date("Y-m-d", strtotime($j['date_of_payment'])));
if ($a == $b)
return 0;
elseif ($a > $b)
return 1;
else
return -1;
});
$this->render('payments', array(
'**response**' => $response,
));
}
So the response array which looks like this will have to be formated :-
[0] => Array
(
[id] => Payment-8
[amount] => 100.00
[date_of_payment] => 06-03-2017
[payment_mode] => Cash
[type] => Payments
[url] => /new_management/index.php/payments/8
)
[1] => Array
(
[id] => Payment-12
[amount] => 1500.00
[date_of_payment] => 22-03-2017
[payment_mode] => Bank/Standing Order
[type] => Payments
[url] => /new_management/index.php/payments/12
)
[2] => Array
(
[id] => Payment-14
[amount] => 150.00
[date_of_payment] => 27-03-2017
[payment_mode] => Cheque
[type] => Payments
[url] => /new_management/index.php/payments/14
)
Below is screenshot of the page and the problem :-
enter image description here