entity = $entity; $this->design = $design->design; $this->input_variables = json_decode(json_encode($input_variables), 1); $this->entity_string = $entity_string; } /** * Returns the design * formatted HTML. * @return string The HTML design built */ public function build():self { $this->setHtml() ->exportVariables() ->setDesign($this->getSection('includes')) ->setDesign($this->getSection('header')) ->setDesign($this->getSection('body')) ->setDesign($this->getSection('footer')); return $this; } public function init() { $this->setHtml() ->exportVariables(); return $this; } public function getIncludes() { return $this->getSection('includes'); } public function getHeader() { return $this->getSection('header'); } public function getFooter() { $div = ' %s
$client.name
', '$client.id_number' => '$client.id_number
', '$client.vat_number' => '$client.vat_number
', '$client.address1' => '$client.address1
', '$client.address2' => '$client.address2
', '$client.city_state_postal' => '$client.city_state_postal
', '$client.postal_city_state' => '$client.postal_city_state
', '$client.country' => '$client.country
', '$contact.email' => '$client.email
', '$client.custom1' => '$client.custom1
', '$client.custom2' => '$client.custom2
', '$client.custom3' => '$client.custom3
', '$client.custom4' => '$client.custom4
', '$contact.contact1' => '$contact.custom1
', '$contact.contact2' => '$contact.custom2
', '$contact.contact3' => '$contact.custom3
', '$contact.contact4' => '$contact.custom4
', ]; return $this->processCustomFields($company, $data); } private function companyDetails(Company $company) { $data = [ '$company.name' => '$company.name', '$company.id_number' => '$company.id_number', '$company.vat_number' => '$company.vat_number', '$company.website' => '$company.website', '$company.email' => '$company.email', '$company.phone' => '$company.phone', '$company.company1' => '$company1', '$company.company2' => '$company2', '$company.company3' => '$company3', '$company.company4' => '$company4', ]; return $this->processCustomFields($company, $data); } private function companyAddress(Company $company) { $data = [ '$company.address1' => '$company.address1', '$company.address2' => '$company.address2', '$company.city_state_postal' => '$company.city_state_postal', '$company.postal_city_state' => '$company.postal_city_state', '$company.country' => '$company.country', '$company.company1' => '$company1', '$company.company2' => '$company2', '$company.company3' => '$company3', '$company.company4' => '$company4', ]; return $this->processCustomFields($company, $data); } private function invoiceDetails(Company $company) { $data = [ '$invoice.number' => '$invoice.number_label: $invoice.number', '$invoice.po_number' => '$invoice.po_number_label: $invoice.po_number', '$invoice.date' => '$invoice.date_label: $invoice.date', '$invoice.due_date' => '$invoice.due_date_label: $invoice.due_date', '$invoice.balance_due' => '$invoice.balance_due_label: $invoice.balance_due', '$invoice.total' => '$invoice.total_label: $invoice.total', '$invoice.partial_due' => '$invoice.partial_due_label: $invoice.partial_due', '$invoice.custom1' => '$invoice1_label: $invoice.custom1', '$invoice.custom2' => '$invoice2_label: $invoice.custom2', '$invoice.custom3' => '$invoice3_label: $invoice.custom3', '$invoice.custom4' => '$invoice4_label: $invoice.custom4', '$surcharge1' => '$surcharge1_label: $surcharge1', '$surcharge2' => '$surcharge2_label: $surcharge2', '$surcharge3' => '$surcharge3_label: $surcharge3', '$surcharge4' => '$surcharge4_label: $surcharge4', ]; return $this->processCustomFields($company, $data); } private function quoteDetails(Company $company) { $data = [ '$quote.quote_number' => '$quote.number_label: $quote.number', '$quote.po_number' => '$quote.po_number_label: $quote.po_number', '$quote.quote_date' => '$quote.date_label: $quote.date', '$quote.valid_until' => '$quote.valid_until_label: $quote.valid_until', '$quote.balance_due' => '$quote.balance_due_label: $quote.balance_due', '$quote.quote_total' => '$quote.total_label: $quote.total', '$quote.partial_due' => '$quote.partial_due_label: $quote.partial_due', '$quote.custom1' => '$quote.custom1_label: $quote.custom1', '$quote.custom2' => '$quote.custom2_label: $quote.custom2', '$quote.custom3' => '$quote.custom3_label: $quote.custom3', '$quote.custom4' => '$quote.custom4_label: $quote.custom4', '$quote.surcharge1' => '$surcharge1_label: $surcharge1', '$quote.surcharge2' => '$surcharge2_label: $surcharge2', '$quote.surcharge3' => '$surcharge3_label: $surcharge3', '$quote.surcharge4' => '$surcharge4_label: $surcharge4', ]; return $this->processCustomFields($company, $data); } private function creditDetails(Company $company) { $data = [ '$credit.number' => '$credit.number_label$credit.number', '$credit.po_number' => '$credit.po_number_label$credit.po_number', '$credit.date' => '$credit.date_label$credit.date', '$credit.balance' => '$credit.balance_label$credit.balance', '$credit.total' => '$credit.total_label$credit.total', '$credit.partial_due' => '$credit.partial_due_label$credit.partial_due', '$credit.custom1' => '$credit.custom1_label$credit.custom1', '$credit.custom2' => '$credit.custom2_label$credit.custom2', '$credit.custom3' => '$credit.custom3_label$credit.custom3', '$credit.custom4' => '$credit.custom4_label$credit.custom4', '$credit.surcharge1' => '$surcharge1_label$surcharge1_label: $surcharge1', '$credit.surcharge2' => '$surcharge2_label$surcharge2_label: $surcharge2', '$credit.surcharge3' => '$surcharge3_label$surcharge3_label: $surcharge3', '$credit.surcharge4' => '$surcharge4_label$surcharge4_label: $surcharge4', ]; return $this->processCustomFields($company, $data); } private function processCustomFields(Company $company, $data) { $custom_fields = $company->custom_fields; if (! $custom_fields) { return $data; } foreach (self::$custom_fields as $cf) { if (! property_exists($custom_fields, $cf) || (strlen($custom_fields->{$cf}) == 0)) { unset($data[$cf]); } } return $data; } // private function processInputVariables($company, $variables) // { // if(is_object($variables)) // $variables = json_decode(json_encode($variables),true); // $custom_fields = $company->custom_fields; // $matches = array_intersect(self::$custom_fields, $variables); // foreach ($matches as $match) { // if (!property_exists($custom_fields, $match) || (strlen($custom_fields->{$match}) == 0)) { // foreach ($variables as $key => $value) { // if ($value == $match) { // unset($variables[$key]); // } // } // } // } // return $variables; // } }