0

I am using cakephp 3.2 csv plugin ,here i got everything what i supposed to need , but i want to make some modifications like want to add price format in the price showing in csv file(0.00).

As it is directly coming from the db ,i am not getting any way to make it. Please suggest me .Any suggestion will be highly appreciated .

Below is the screen short and some code .

$data = $this->Orders->find('all')->where($condition)->contain(['Collections', 'Customers' => ['queryBuilder' => function ($q) {
                                    return $q->select(['id', 'center_name']);
                                }],])->order(['Orders.due_date ASC']);
//$data = $this->Orders->find('all')->toArray();
// pj($data);exit;
$_serialize = 'data';
$_delimiter = ','; //tab
$_enclosure = '"';
$_newline = '\n';
$_eol = '~';
$_bom = false;
$_header = ['Invoice Date', 'Invoice', 'Center Name', 'Total', 'Paid', 'Due', 'Due Date'];

$_extract = ['billing_date', 'invoice_no', 'customer.center_name', 'net_total', 'amount.paid', 'amount.due', 'due_date'];
$this->set(compact('data', '_serialize', '_header', '_extract', '_delimiter'));
$this->viewBuilder()->className('CsvView.Csv');
return;

enter image description here

Here all the price section should be come like this 110.00 , 40.00 and 70.00 and so on.

Thank you .

Dave
  • 3,073
  • 7
  • 20
  • 33
sradha
  • 2,216
  • 1
  • 28
  • 48
  • 1
    You could change the code reading the data from the DB to return the price in the format you want to display. Alternatively, you need to read the data into an array, reformat it the way you like and then export it to csv. – Guenther Sep 15 '16 at 09:01
  • Ok @Guenther Thank you for the suggestion . – sradha Sep 15 '16 at 09:11
  • @Guenther But here it is something different ,i am not getting ,can you please suggest some more in details? – sradha Sep 15 '16 at 09:12
  • While I appreciate your thanks, you are not supposed to post simple thank you comments. Instead mark the comment as helpful. If you have further questions, comments, you can edit the question (or the comments if they are not older than a few minutes) – Guenther Sep 15 '16 at 09:12
  • @Guenther can you please suggest some more? – sradha Sep 15 '16 at 09:27
  • Hard to give you more advice without the complete code. $data contains the content read from the database. Loop through it and format the data the way you want it. See http://php.net/manual/en/function.number-format.php for formatting numbers – Guenther Sep 15 '16 at 09:38
  • :( :( .yes i have given the main code section. @Guenther – sradha Sep 15 '16 at 10:06

0 Answers0