/** * Number format by market with currency code * * @param $market_id * @param $number * @param bool $no_symbol * @return string */ public function numberCurrency($market_id, $number, $no_symbol = false) { if ($market_id == 5) { $currency = 'GBP'; } elseif ($market_id == 7 || $market_id == 8 || $market_id == 9) { $currency = 'EUR'; } else { $currency = 'USD'; } if ($no_symbol) { $options = ['before' => false, 'after' => false, 'places' => 2]; } else { $options = ['places' => 2]; } return CakeNumber::currency($number, $currency, $options); }
function word($id = NULL) { $this->autoRender = false; $delivery_data = $this->Proforma->find('all', array('order' => array('Proforma.id' => 'DESC'), 'recursive' => 5)); //pr($delivery_data);exit; //$this->set('proforma', $delivery_data); $file_type = 'doc'; $filename = $id; $html = '<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>PDF</title> <style> body { background-color:#fff; font-family:"Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; color:#394263; font-size:14px; } * { text-decoration: none; font-size: 1em; outline: none; padding: 0; margin: 0; } .group:before, .group:after { content: ""; display: table; } .group:after { clear: both; } .group { zoom: 1; /* For IE 6/7 (trigger hasLayout) */ } .pdf_container { margin: 0 auto; min-height: 800px; padding: 10px; width: 900px; } .header_id { padding:10px 0; width:100%; display:block; } .logo { margin-top:10px;display:inline-block;width:50%; } .address_details { width:46%; line-height:20px; text-align:right;display:inline-block; } .address_details p { float:left; width:100%; } .address_details a { color: #1bbae1; float:left; width:100%; } .cmpny_reg { background:#FF8E00; padding:5px; color:#fff; text-transform:uppercase; width:100%; float:left; margin:10px 0 0 -8px; } .address_box { border: 1px solid #ccc; margin-top: 20px; padding: 10px; width: 47%; min-height: 185px;display:inline-block; } .address_box h2 { width:100%; padding:5px 0; font-size:23px; font-weight:bold; text-align:center; display:inline-block;} .address_box p { display:inline-block;} .invoice_address_blog { margin-top:20px; display:inline-block;width:100%;} .invoice_add { margin:3px 0; display:inline-block;width:100%;} .invoice_add h5 { display:inline-block; width:30%; } .invoice_add span { margin-right:15px;display:inline-block; } .invoice_add abbr { font-style: italic;display:inline-block; } .services_details { margin-top:20px; width:100%; } .services_details h4 { width:100%; margin-top:20px; font-size:15px; font-weight:bold; } .services_details h4 abbr { width: 22%; display:inline-block;} .services_details h4 span { color:#fff; background-color:#1BBAE1; padding: 0 10px; } .invoice_table { width:100%; margin-top:20px;margin-bottom:30px; } .invoice_table table { width:100%; border:1px solid #ccc; border-bottom:none; border-left:none; } .invoice_table table th, td { padding: 10px; text-align: center; text-transform:uppercase; border:1px solid #ccc; border-top:none; border-right:none; } .invoice_table table thead { background-color: #f1f1f1; } .instrument h4 { font-weight:normal; } .instrument span { font-size: 13px; color: #2980b9; font-style: italic; margin: 0 10px; } </style> </head>'; foreach ($delivery_data as $delivery_data_list) { $customername = $delivery_data_list['Customer']['customername']; $billing_address = $delivery_data_list['Customer']['Address'][1]['address']; $phone = $delivery_data_list['Salesorder']['phone']; $fax = $delivery_data_list['Salesorder']['fax']; $email = $delivery_data_list['Salesorder']['email']; $our_ref_no = $delivery_data_list['Salesorder']['our_ref_no']; $ref_no = $delivery_data_list['Salesorder']['ref_no']; $reg_date = $delivery_data_list['Proforma']['reg_date']; $contact = $delivery_data_list['Quotation']['Customer']['Contactpersoninfo'][0]['name']; $payment_term = $delivery_data_list['Customer']['Paymentterm']['paymentterm'] . ' ' . $delivery_data_list['Customer']['Paymentterm']['paymenttype']; $salesorderno = $delivery_data_list['Proforma']['salesorderno']; foreach ($delivery_data_list['Salesorder']['Description'] as $device) { $device_name[] = $device; //$device_price[]= $device; } } //pr($device_name);exit; $html .= '<body> <div class="pdf_container group"> <!-- header part--> <div class="header_id"> <div class="f_left logo"><img src="img/logoBs.png" width="273" height="50" alt="" /></div> <div class="address_details f_right"> <p>41 SENOKO DRIVE</p> <p>SINGAPORE</p> <p>758249</p> <p> 6458 4411</p> <a href="#" title="">invoice@bestandards.com</a> <div class="cmpny_reg">GST REG NO. M200510697 / COMPANY REG NO. 200510697M</div> </div> </div> <div class="address_box"> <p> ' . $customername . ' </p> <p> ' . $billing_address . ' </p> <p> Singapore 758301 </p> <div class="invoice_address_blog"> <div class="invoice_add"> <h5>ATTN </h5> <span>:</span><abbr>' . $contact . '</abbr></div> <div class="invoice_add"> <h5>TEL </h5> <span>:</span><abbr> ' . $phone . ' </abbr></div> <div class="invoice_add"> <h5>FAX </h5> <span>:</span><abbr>' . $fax . '</abbr></div> <div class="invoice_add"> <h5>EMAIL </h5> <span>:</span><abbr>' . $email . '</abbr></div> </div> </div> <div class="address_box"> <h2 class=""> ' . $id . ' </h2> <div class="invoice_address_blog f_left"> <div class="invoice_add f_left"> <h5> TRACK ID </h5> <span>:</span><abbr>' . $our_ref_no . '</abbr></div> <div class="invoice_add f_left"> <h5>PURCHASE ORDER NUMBER </h5> <span>:</span><abbr>' . $ref_no . '</abbr></div> <div class="invoice_add f_left"> <h5>DATE </h5> <span>:</span><abbr>' . $reg_date . '</abbr></div> <div class="invoice_add f_left"> <h5> PAYMENT TERMS </h5> <span>:</span><abbr>' . $payment_term . '</abbr></div> </div> </div> <div class="services_details f_left"> <p>Being provided calibration service of the following(s) :</p> <h4 class="f_left"><abbr>SALES ORDER NO</abbr><span> ' . $salesorderno . '</span></h4> </div> <div class="invoice_table f_left"> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th>Instrument</th> <th>Brand</th> <th>Model</th> <th>Serial No</th> <th>Quantity</th> <th>Unit Price $(SGD)</th> <th>Total Price $(SGD)</th> </tr> </thead> <tbody>'; $subtotal = 0; foreach ($device_name as $device) { $html .= ' <tr> <td class="instrument"><h4>' . $device['Instrument']['name'] . '</h4> <span>Faulty</span> <span>(9~10)/mm</span></td> <td>' . $device['Instrument']['InstrumentBrand']['Brand']['brandname'] . '</td> <td>' . $device['model_no'] . '</td> <td>53254324</td> <td>1</td> <td> $' . $device['sales_unitprice'] . '</td> <td> $' . $device['sales_unitprice'] . '</td> </tr>'; $subtotal = $subtotal + $device['sales_unitprice']; } $gst = $subtotal * 0.07000000000000001; //setlocale(LC_MONETARY, 'en_SG'); //$subtotal = money_format('%i', $subtotal); //$gst = money_format('%i', $gst); $total_due = $gst + $subtotal; App::uses('CakeNumber', 'Utility'); $currency = 'USD'; $total_due = CakeNumber::currency($total_due, $currency); $gst = CakeNumber::currency($gst, $currency); $subtotal = CakeNumber::currency($subtotal, $currency); //$total_due = $this->Number->currency($total_due, $currency); //$total_due = money_format('%i', $total_due); //echo $a; //exit; $html .= '<tr> <td colspan="6">SUBTOTAL</td> <td>' . $subtotal . '</td> </tr> <tr> <td colspan="6">GST ( 7.00% )</td> <td>' . $gst . '</td> </tr> <tr> <td colspan="6"><h4>TOTAL DUE</h4></td> <td><h4>' . $total_due . '</h4></td> </tr> </tbody> </table> </div> </div> </body> </html>'; $this->export_report_all_format($file_type, $filename, $html); }
/** * Correct the default for European countries * * @param mixed $number * @param string $currency * @param array $formatOptions * @return string */ public static function currency($number, $currency = null, $formatOptions = []) { if ($currency === null) { $currency = static::$_currency; } $defaults = []; if ($currency !== 'EUR' && isset(static::$_currencies[$currency])) { $defaults = static::$_currencies[$currency]; } elseif ($currency !== 'EUR' && is_string($currency)) { $defaults['wholeSymbol'] = $currency; $defaults['wholePosition'] = 'before'; $defaults['spacer'] = true; } $defaults += ['wholeSymbol' => '€', 'wholePosition' => 'after', 'negative' => '-', 'positive' => '+', 'escape' => true, 'decimals' => ',', 'thousands' => '.', 'spacer' => $currency === 'EUR' ? true : false]; $options = $formatOptions + $defaults; if (!empty($options['spacer'])) { $spacer = is_string($options['spacer']) ? $options['spacer'] : ' '; if ($options['wholePosition'] === 'after') { $options['wholeSymbol'] = $spacer . $options['wholeSymbol']; } elseif ($options['wholePosition'] === 'before') { $options['wholeSymbol'] .= $spacer; } } $sign = ''; if ($number > 0 && !empty($options['signed'])) { $sign = $options['positive']; } $options['signed'] = false; return $sign . parent::currency($number, null, $options); }
/** * Formats a number into a currency format. * * @param float $number Number to format. * @param string $currency Shortcut to default options. Valid values are 'USD', 'EUR', 'GBP', otherwise * set at least 'before' and 'after' options. * 'USD' is the default currency, use CakeNumber::defaultCurrency() to change this default. * @param array $options Options list. * @return string Number formatted as a currency. * @see CakeNumber::currency() * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::currency */ public function currency($number, $currency = null, $options = array()) { return $this->_engine->currency($number, $currency, $options); }
function currency($number, $currency = null, $options = array()) { // App::uses('BakewellNumber', 'Utility'); // return BakewellNumber::currency($number, $currency, $options); App::uses('CakeNumber', 'Utility'); return CakeNumber::currency($number, $currency, $options); }
/** * Correct the default for European countries * 2012-04-08 ms */ public static function currency($number, $currency = null, $formatOptions = array()) { if ($currency === null) { $currency = self::$_currency; } $options = array('wholeSymbol' => self::$_symbolRight, 'wholePosition' => 'after', 'negative' => '-', 'positive' => '+', 'escape' => true); $options = am($options, $formatOptions); if (!empty($options['wholeSymbol'])) { if ($options['wholePosition'] == 'after') { $options['wholeSymbol'] = ' ' . self::$_symbolRight; } elseif ($options['wholePosition'] == 'before') { $options['wholeSymbol'] = self::$_symbolLeft . ' '; } } $sign = ''; if ($number > 0 && !empty($options['signed'])) { $sign = $options['positive']; } return $sign . parent::currency($number, $currency, $options); }
public function exportToExcel($data = array(), $filename = null) { /* * Export to excel - php */ //http://w3lessons.info/2015/07/13/export-html-table-to-excel-csv-json-pdf-png-using-jquery/ //html contain export in excel(upper link) // http://www.codexworld.com/export-data-to-excel-in-php/ $preparedArray = array(); if (!empty($data)) { $payment_total = 0; $receipt_total = 0; foreach ($data as $signleTransaction) { $recordArray = array(); if ($signleTransaction["Transaction"]["transaction_type"] == "Payment") { $amount = $signleTransaction["Transaction"]["amount"]; $recordArray["Payment Amount"] = CakeNumber::currency($amount, ""); $recordArray["Payment Particulars"] = $this->getParticulars($signleTransaction); $payment_total += $amount; } else { $recordArray["Payment Amount"] = null; $recordArray["Payment Particulars"] = null; } if ($signleTransaction["Transaction"]["transaction_type"] == "Receipt") { $amount = $signleTransaction["Transaction"]["amount"]; $recordArray["Receipt Amount"] = CakeNumber::currency($amount, ""); $recordArray["Receipt Particulars"] = $this->getParticulars($signleTransaction); $receipt_total += $amount; } else { $recordArray["Receipt Amount"] = null; $recordArray["Receipt Particulars"] = null; } $preparedArray[] = $recordArray; } $recordArray = array(); $recordArray["Payment Amount"] = null; $recordArray["Payment Particulars"] = null; $recordArray["Receipt Amount"] = null; $recordArray["Receipt Particulars"] = null; $preparedArray[] = $recordArray; $recordArray = array(); $recordArray["Payment Amount"] = "Total Payment"; $recordArray["Payment Particulars"] = null; $recordArray["Receipt Amount"] = "Total Receipt"; $recordArray["Receipt Particulars"] = null; $preparedArray[] = $recordArray; $recordArray["Payment Amount"] = CakeNumber::currency($payment_total, ""); $recordArray["Payment Particulars"] = null; $recordArray["Receipt Amount"] = CakeNumber::currency($receipt_total, ""); $recordArray["Receipt Particulars"] = null; $preparedArray[] = $recordArray; } // $preparedArray = array(); // if (!empty($data)) { // foreach ($data as $signleTransaction) { // $recordArray = array(); // $recordArray["Amount"] = $signleTransaction["Transaction"]["amount"]; // $recordArray["Transaction Type"] = $signleTransaction["Transaction"]["transaction_type"]; // $recordArray["Is Interest Entry"] = $signleTransaction["Transaction"]["is_interest"]; // $recordArray["Remarks"] = $signleTransaction["Transaction"]["remarks"]; // $recordArray["Transaction Date"] = $signleTransaction["Transaction"]["transaction_date"]; // $recordArray["Created Date"] = $signleTransaction["Transaction"]["created"]; // $recordArray["Modified Date"] = $signleTransaction["Transaction"]["modified"]; // $preparedArray[] = $recordArray; // } // } if (empty($filename)) { // file name for download $filename = "export_data" . date('Ymd') . ".xls"; } $columnHeadings = array("Amount", "Particulars(Payment)", "Amount", "Particulars(Receipt)"); // headers for download header("Content-Disposition: attachment; filename=\"{$filename}\""); header("Content-Type: application/vnd.ms-excel"); $flag = false; foreach ($preparedArray as $row) { if (!$flag) { // display column names as first row //echo implode("\t", array_keys($row)) . "\n"; echo implode("\t", $columnHeadings) . "\n"; $flag = true; } // filter data array_walk($row, array($this, 'filterData')); echo implode("\t", array_values($row)) . "\n"; } exit; }
/** * Replace by formatted currency string. * * Examples: * - [currency]50[/currency] * - [currency zero="$0.00"]0[/currency] * * @param string $str String to check and modify. * @return string Modified string. */ protected function _replaceCurrency($str) { if (!preg_match_all('/\\[currency(.*?)\\](.*)\\[\\/currency\\]/i', $str, $matches)) { // Fallback regex for when no options are passed. if (!preg_match_all('/\\[currency(.*?)\\](.[^\\[]*)\\[\\/currency\\]/i', $str, $matches)) { return $str; } } foreach ($matches[0] as $i => $find) { $opts = $this->_extractAttributes(trim($matches[1][$i])); $currency = CakeNumber::defaultCurrency(); if (isset($opts['currency'])) { $currency = $opts['currency']; unset($opts['currency']); } $replace = empty($matches[2][$i]) || !is_numeric($matches[2][$i]) ? '' : CakeNumber::currency($matches[2][$i], $currency, $opts); $str = str_replace($find, $replace, $str); } return $str; }
/** * Add product names from drupal for items * * @param $items * @param $market_id * @return array */ private function processItems($items, $market_id) { $ret = []; $parents = []; $children = []; foreach ($items as $i) { $name = ''; /** * Optionally add variant master name */ if (!empty($i['Item']['ParentItems']) && $i['Item']['ParentItems'][0]['item_type_id'] == 2) { $name = $this->drupalName($i['Item']['ParentItems'][0]) . ' - '; $variant = true; } else { $variant = false; } $name .= $this->drupalName($i); $child = !empty($i['parent_id']); $cur = $this->currencyByMarket($market_id); $dec = ['places' => 2]; if ($child) { $price = CakeNumber::currency($i['price'], $cur, $dec); $suppl = CakeNumber::currency($i['price'], $cur, $dec); } else { if ($variant == true) { $price = CakeNumber::currency($i['Item']['ParentItems'][0]['ItemPrice']['price'], $cur, $dec); $suppl = CakeNumber::currency($i['Item']['ParentItems'][0]['ItemPrice']['price_supplement'], $cur, $dec); } else { $price = CakeNumber::currency($i['Item']['ItemPrice']['price'], $cur, $dec); $suppl = CakeNumber::currency($i['Item']['ItemPrice']['price_supplement'], $cur, $dec); } } $sub = CakeNumber::currency($i['price'] * $i['quantity'], $cur, $dec); $total = CakeNumber::currency($i['extended_price'], $cur, $dec); $status = $i['order_item_hold_code_id']; if (!$child) { $class = 'success'; } else { $class = 'warning'; } if ($status == 1) { $class = 'danger'; } $object = ['id' => $i['id'], 'item_id' => $i['Item']['id'], 'shipment_id' => $i['order_shipment_id'], 'hold_code' => $i['order_item_hold_code_id'], 'ns_warehouse_id' => $i['ns_warehouse_id'], 'parent_id' => $i['parent_id'], 'sku' => $i['Item']['sku'], 'display_name' => $name, 'quantity' => $i['quantity'], 'price' => $price, 'price_supplement' => $suppl, 'total' => $total, 'subtotal' => $sub, 'backorder' => $status == 1, 'class' => $class]; if (!empty($i['OrderItemRestock'])) { $object['restock_date'] = $i['OrderItemRestock'][0]['restock_date']; } if ($child) { $children[$i['parent_id']][] = $object; } else { $parents[] = $object; } } foreach ($parents as $obj) { $ret[] = $obj; $child_items = $children[$obj['id']]; if (!empty($child_items)) { foreach ($child_items as $c) { $ret[] = $c; } } } return $ret; }