Source of file CustomerOrdersItem.php
Size: 4,026 Bytes - Last Modified: 2021-12-23T10:24:40+00:00
/var/www/docs.ssmods.com/process/src/src/Items/CustomerOrdersItem.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 | <?php namespace SilverCommerce\Reports\Items; use DateTime; use SilverStripe\ORM\DB; use SilverStripe\View\ViewableData; use SilverCommerce\ContactAdmin\Model\Contact; class CustomerOrdersItem extends ViewableData { /** * Customer object assigned to this item * * @var \SilverCommerce\ContactAdmin\Model\Contact */ private $contact; /** * Start date for this item * * @var DateTime */ private $start_date; /** * End date for this item * * @var DateTime */ private $end_date; private static $casting = [ 'FirstName' => 'Varchar', 'Surname' => 'Varchar', 'Email' => 'Varchar', 'InvoiceCount' => 'Int', 'InvoiceTotal' => 'Currency', 'InvoiceTax' => 'Curency' ]; public function getFirstName() { return $this->getContact()->FirstName; } public function getSurname() { return $this->getContact()->Surname; } public function getEmail() { return $this->getContact()->Email; } /** * Get the total number of invoices applicable for this report * * @return int */ public function getInvoiceCount() { return $this->getInvoices()->count(); } /** * Get the total number of invoices applicable for this report * * @return int */ public function getInvoiceTotal() { $invoices = $this->getInvoices(); $total = 0; foreach ($invoices as $invoice) { $total += $invoice->Total; } return $total; } /** * Get the total number of invoices applicable for this report * * @return int */ public function getInvoiceTax() { $invoices = $this->getInvoices(); $total = 0; foreach ($invoices as $invoice) { $total += $invoice->TaxTotal; } return $total; } /** * Get the invoices for this contact (within the set timeframe) * * @return \SilverStripe\ORM\DataList */ protected function getInvoices() { $db = DB::get_conn(); $start = $this->getStartDate(); $end = $this->getEndDate(); $format = "%Y-%m-%d"; $contact = $this->getContact(); $field = $db->formattedDatetimeClause( '"Estimate"."StartDate"', $format ); $date_filter = [ $field . ' <= ?' => $end->format("Y-m-d"), $field . ' >= ?' => $start->format("Y-m-d") ]; return $contact->Invoices()->where($date_filter); } public function canView($member = null) { return true; } /** * Get customer object assigned to this item * * @return Contact */ public function getContact() { return $this->contact; } /** * Set customer object assigned to this item * * @param Contact $contact Customer object assigned to this item * * @return self */ public function setContact(Contact $contact) { $this->contact = $contact; return $this; } /** * Get start date for this item * * @return DateTime */ public function getStartDate() { return $this->start_date; } /** * Set start date for this item * * @param DateTime $date Start date for this item * * @return self */ public function setStartDate(DateTime $date) { $this->start_date = $date; return $this; } /** * Get end date for this item * * @return DateTime */ public function getEndDate() { return $this->end_date; } /** * Set end date for this item * * @param DateTime $end_date End date for this item * * @return self */ public function setEndDate(DateTime $date) { $this->end_date = $date; return $this; } } |