public function syncExecution($id, $type)
 {
     $model = Mage::getModel('pdfinvoiceplus/template')->load($id);
     if (!$model->getId()) {
         return;
     }
     //datas
     $data = array('company_logo' => $model->getCompanyLogo(), 'company_name' => $model->getCompanyName(), 'company_address' => $model->getCompanyAddress(), 'company_email' => $model->getCompanyEmail(), 'company_telephone' => $model->getCompanyTelephone(), 'company_fax' => $model->getCompanyFax(), 'business_id' => $model->getBusinessId(), 'vat_number' => $model->getVatNumber(), 'vat_office' => $model->getVatOffice(), 'note' => $model->getNote(), 'footer' => $model->getFooter(), 'footer_height' => $model->getFooterHeight(), 'terms_conditions' => $model->getTermsConditions());
     //init dom html
     $html_dom = new SimpleHtmlDoom_SimpleHtmlDoomLoad();
     switch ($type) {
         case 'order':
             $html_dom->load($model->getOrderHtml());
             $outHtml = $this->renderHtml($html_dom, $data);
             if ($outHtml) {
                 $data['order_html'] = $outHtml;
             }
             break;
         case 'invoice':
             $html_dom->load($model->getInvoiceHtml());
             $outHtml = $this->renderHtml($html_dom, $data);
             if ($outHtml) {
                 $data['invoice_html'] = $outHtml;
             }
             break;
         case 'creditmemo':
             $html_dom->load($model->getCreditmemoHtml());
             $outHtml = $this->renderHtml($html_dom, $data);
             if ($outHtml) {
                 $data['creditmemo_html'] = $outHtml;
             }
             break;
         default:
             return;
             //break;
     }
     /********************************* */
     //save data//
     $model->addData($data)->setId($id);
     try {
         $model->save();
     } catch (Exception $e) {
         echo $e->getMessage() . ' ' . PHP_EOL;
     }
     return $this;
 }
 public function getCss($html)
 {
     $html_dom = new SimpleHtmlDoom_SimpleHtmlDoomLoad();
     $html_dom->load($html);
     $style = $html_dom->find('#container-inner', 0)->style;
     $template = Mage::helper('pdfinvoiceplus/pdf')->getUsingTemplate();
     $background = $template->getBackgroundImage();
     if ($background) {
         $css = '
             body{' . $style . '}
             #container-inner{background-image:none !important;
         ';
         return $css;
     }
     return null;
 }
 /**
  * 
  * @param type $html
  * @return array("{{var name}} => array('label'=>'text','value'=>'{{var name}}')")
  */
 protected function _getTotalHtmlVars($html)
 {
     $dom = new SimpleHtmlDoom_SimpleHtmlDoomLoad();
     $dom->load($html);
     //get label array
     $rows_total = $dom->find(".body-total > .total-row");
     //merger key => value
     $arr_mer = array();
     foreach ($rows_total as $rowElement) {
         preg_match('/\\{\\{.*\\}\\}/', $rowElement->find('.total-value', 0)->innertext, $matched);
         $arr_mer[$matched[0]]['value'] = $matched[0];
         $arr_mer[$matched[0]]['label'] = $rowElement->find('.total-label', 0)->innertext;
     }
     return $arr_mer;
 }
 public function htmlDomAction()
 {
     $html = Mage::getModel('pdfinvoiceplus/template')->load(1);
     $dom = new SimpleHtmlDoom_SimpleHtmlDoomLoad();
     $dom->load($html->getInvoiceHtml());
     //$col = $dom->find(".col-total-label");
     $col = $dom->find(".col-total-label");
     $col = $col[0];
     //$col->appendChild($childs[3]);
     //$child[0]->appendChild($child[0]->childNodes[3]);
     //echo print_r($col->childNodes(3)->outertext);
     //echo "============";
     //echo $col->__toString();
     $child = $col->children();
     //$col->appendChild($col->childNodes(3));
     echo $child[0]->__toString();
 }