Source of file SecondHandProductValue.php
Size: 2,313 Bytes - Last Modified: 2021-12-23T10:41:14+00:00
/var/www/docs.ssmods.com/process/src/src/Reports/SecondHandProductValue.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 | <?php namespace Sunnysideup\EcommerceSecondHandProduct\Reports; use SilverStripe\Forms\GridField\GridFieldExportButton; use SilverStripe\ORM\FieldType\DBCurrency; use SilverStripe\Reports\Report; use Sunnysideup\EcommerceSecondHandProduct\SecondHandProduct; class SecondHandProductValue extends Report { /** * The class of object being managed by this report. * Set by overriding in your subclass. */ protected $dataClass = SecondHandProduct::class; /** * @return string */ public function title() { $values = $this->sourceRecords()->column('PurchasePrice'); $sum = array_sum($values); $object = DBCurrency::create('Sum'); $object->setValue($sum); $name = _t( 'EcommerceSideReport.SECOND_HAND_REPORT_TOTAL_STOCK_VALUE', 'Second Hand Products, total stock value' ); return $name . ': ' . $object->Nice(); } /** * not sure if this is used in SS3. * * @return string */ public function group() { return _t('EcommerceSideReport.ECOMMERCEGROUP', 'Ecommerce'); } /** * @return int - for sorting reports */ public function sort() { return 8000; } /** * working out the items. * * @param null|mixed $params * * @return \SilverStripe\ORM\DataList */ public function sourceRecords($params = null) { return SecondHandProduct::get()->filter( [ 'AllowPurchase' => 1, 'SellingOnBehalf' => 0, ] ); } /** * @return array */ public function columns() { return [ 'InternalItemID' => 'ID', 'Title' => [ 'title' => 'Product Name', 'link' => true, ], 'Created' => 'Created Time', 'Price' => 'Selling Price', 'PurchasePrice' => 'Purchase Price', ]; } public function getReportField() { $field = parent::getReportField(); $config = $field->getConfig(); $exportButton = $config->getComponentByType(GridFieldExportButton::class); $exportButton->setExportColumns($field->getColumns()); return $field; } } |