'contracts', ); function EcmKpkw() { parent :: SugarBean(); $this->setupCustomFields('EcmKpkw'); //parameter is module name $this->disable_row_level_security = false; } function save($check_notify = false) { global $current_user; $db = $GLOBALS ['db']; // global $db; $this->number = $this->generateNumber(); $this->document_no = $this->formatNumber(); if($this->dir==1){ $this->document_no='KW/'.$this->document_no; } else { $this->document_no='KP/'.$this->document_no; } $value = $this->amount; if ($this->dir) { $value = ($this->amount)*-1; } $value = str_replace(",", "", $value); $return_id = parent::save($check_notify); if (isset($_REQUEST['record']) && $_REQUEST['record'] != '') { // edytowanie informacji do listy platnosci // mysql_query("UPDATE `ecmpayments` SET `value`='".($value)."', `parent_name`='".$this->parent_name."', `parent_id`='".$this->parent_id."', `description`='".$this->description."', `created_by`='".$this->created_by."' WHERE `parent_document_id`='".$this->id."'"); } else { // dodawanie informacji do listy platnosci // mysql_query("INSERT INTO `ecmpayments` SET `id`=UUID(), `parent_document_id`='".$return_id."', `name`='".$this->document_no."', `value`='".($value)."', `parent_name`='".$this->parent_name."', `parent_id`='".$this->parent_id."', `description`='".$this->description."', `created_by`='".$this->created_by."'"); } //echo $this->parent_id; exit; // $query = "SELECT // billing_address_street AS `street`, // billing_address_city AS `city`, // billing_address_postalcode AS `postalcode`, // billing_address_country AS `country`, // index_dbf AS `indeks` // FROM `accounts` // WHERE `id` = '".$this->parent_id."';"; // echo $query; exit; // if($row = $db->fetchByAssoc($db->query($query))) // { // $this->parent_name = $row["name"]; // $this->parent_address_street = $row["street"]; // $this->parent_address_city = $row["city"]; // $this->parent_address_postalcode = $row["postalcode"]; // $this->parent_address_country = $row["country"]; // $this->index_dbf = $row["indeks"]; // } // echo "
".var_export($row,true).""; exit; //echo "
".var_export(array($this->ToArray()),true).""; $res_count = $db->query ( "select id from ecmtransactions where record_id='" . $this->id . "' and deleted='0'" ); $count = $res_count->num_rows; $a=$GLOBALS ['db']->query ("SELECT amount from ecmkpkw where id='" . $this->id . "'"); $r = $GLOBALS ['db']->fetchByAssoc ( $a ); if ($count == 0) { //$GLOBALS ['db']->query ("INSERT INTO ecmtransactions(id,name,date_entered,date_modified,modified_user_id,created_by,description,deleted,assigned_user_id,value,parent_name,parent_id,payment_date,type,paid,register_date,record_id,record_type,currency_id,currency_value)VALUES('".create_guid()."','".$this->ecmkpkw_name."','".date("Y-m-d H:i:s")."','".date("Y-m-d H:i:s")."','".$_SESSION['authenticated_user_id']."','".$_SESSION['authenticated_user_id']."','".$this->description."','".$this->deleted"','".$this->assigned_user_id."','".$this->amount."','".$this->parent_name."','".$this->parent_id."','".$this->register_date."','".$this->dir."','1','".$this->date_entered."','".$this->id."','EcmKpkw','".$this->currency_id ."','".$this->currency_value ."')"); } else { //$db->query ( "update ecmtransactions set value=$this->amount where record_id='" . $this->id . "'" ); } return parent :: save($check_notify); } function generateNumber() { $this->setTemplate(); $this->number = isset($this->template) ? $this->template->generateNumber($this->table_name) : ''; return $this->number; } function formatNumber() { $this->setTemplate(); $this->document_no = isset($this->template) ? $this->template->formatNumber($this->number, $this->module_dir) : ''; return $this->document_no; } function setTemplate() { // if (!isset($this->template_id) || $this->template_id == '') // return null; // if (isset($this->template)) // return $this->template; require_once('modules/EcmDocumentTemplates/EcmDocumentTemplate.php'); $this->template = new EcmDocumentTemplate(); $this->template_id = "97700b0d-fbe9-e366-4016-4b260f058a47"; //$this->template->retrieve($this->template_id); $this->template->retrieve($this->template_id, true, false); if (isset($this->template->id) && $this->template->id != '') { $this->template->format_all_fields(); } else $this->template = null; return $this->template; } function get_summary_text() { return "$this->ecmkpkw_name"; } function is_authenticated() { return $this->authenticated; } function fill_in_additional_list_fields() { // $this->modified_user_fullname = get_assigned_user_name($this->modified_user_id); // $this->created_by_fullname = get_assigned_user_name($this->created_by); $this->fill_in_additional_detail_fields(); } function fill_in_additional_detail_fields() { $this->modified_user_fullname = get_assigned_user_name($this->modified_user_id); $this->created_by_fullname = get_assigned_user_name($this->created_by); // echo "
".var_export($this->ToArray(),true).""; // exit; return; global $theme; global $current_language; global $timedate; global $locale; parent::fill_in_additional_detail_fields(); $mod_strings = return_module_language($current_language, 'EcmKpkw'); $query = "SELECT filename,revision,file_ext FROM ecmkpkw_revisions WHERE id='$this->document_revision_id'"; $result = $this->db->query($query); $row = $this->db->fetchByAssoc($result); //popuplate filename if(isset($row['filename']))$this->filename = $row['filename']; //$this->latest_revision = $row['revision']; if(isset($row['revision']))$this->revision = $row['revision']; //populate the file url. //image is selected based on the extension name
".var_export($this->get_list_view_array(),true).""; // exit; return $ecmkpkw_fields; } function mark_relationships_deleted($id) { //do nothing, this call is here to avoid default delete processing since //delete.php handles deletion of ecmkpkw revisions. } function bean_implements($interface) { switch ($interface) { case 'ACL' : return true; } return false; } function createPdfFileName($format = true) { $arr1 = array('\\', '/', ':', '*', '?', '"', '<', '>', '|', ' '); $arr2 = array('', '', '', '', '', '\'', '[', ']', '', '_'); $tmp = $this->document_no; if ($format) { if ($this->type == "normal") $tmp = str_replace($arr1, $arr2, 'Invoice_' . $tmp . '.pdf'); else if ($this->type == "correct") $tmp = str_replace($arr1, $arr2, 'Correct_' . $tmp . '__to_Invoice_' . $this->ecmkpkw->document_no . '.pdf'); } else $tmp = 'Kpkw ' . $tmp . '.pdf'; //$mod = return_module_language($current_language, 'EcmInvoiceOuts'); //return urlencode( // return $mod['LBL_PDF_INVOICE_FILE_NAME'].$tmp.'.pdf';//); return $tmp; //); } //static function. function get_ecmkpkw_name($doc_id){ if (empty($doc_id)) return null; $db = DBManagerFactory::getInstance(); $query="select ecmkpkw_name from ecmkpkw where id='$doc_id'"; $result=$db->query($query); if (!empty($result)) { $row=$db->fetchByAssoc($result); if (!empty($row)) { return $row['ecmkpkw_name']; } } return null; } function DrawMainPDF($pdf, $type = null) { global $mod_strings; // $arr = $this->template->getTemplateFile($_REQUEST['module']); //var_dump($type ? : $this->pdf_type); exit; include($this->template->getTemplateFile('subheader.php')); include($this->template->getTemplateFile('subfooter.php')); //exit; return; } function getPDF($id = null, $method = 'I', $name = null, $type = null) { global $sugar_config; if ($id != null) { $this->retrieve($id); if ($this->id == '') return; } global $mod_strings; // require_once('modules/EcmTexts/EcmText.php'); // if (isset($this->ecmlanguage) && $this->ecmlanguage != '') { // $data = EcmText::LoadText(null, null, "EcmKpkw", $this->ecmlanguage); // if (isset($data[0]) && isset($data[0]['data']) && isset($data[0]['data']['labels'])) { // $data = $data[0]['data']['labels']; // foreach ($data as $key => $value) { // $mod_strings[$value['label']] = $value['translation']; // } // } // } $this->format_all_fields(); $this->setTemplate(); //$type = $_REQUEST['type']; if (isset($this->template->id) && $this->template->id != '') { $this->template->setPDF($this->template_id); $this->template->pdf->SetAutoPageBreak(true, 40); $this->DrawMainPDF($this->template->pdf, $type); $this->template->outputPDF((($name) ? $name : $this->createPdfFileName()), $method); } } } ?>