'notes', 'email_id' => 'emails' // 'account_id' => 'account', // 'contact_id' => 'contact', ); function EcmAgreement() { parent::SugarBean (); $this->setupCustomFields ( 'EcmAgreements' ); foreach ( $this->field_defs as $field ) { $this->field_name_map [$field ['name']] = $field; } } var $new_schema = true; function get_summary_text() { return "$this->name"; } function create_list_query($order_by, $where, $show_deleted = 0) { // Fill in the assigned_user_name $custom_join = $this->custom_fields->getJOIN (); $query = "SELECT "; $query .= "ecmagreements.* ,users.user_name as assigned_user_name"; if ($custom_join) { $query .= $custom_join ['select']; } $query .= " FROM ecmagreements LEFT JOIN users ON ecmagreements.assigned_user_id=users.id"; $query .= " "; if ($custom_join) { $query .= $custom_join ['join']; } $where_auto = '1=1'; if ($show_deleted == 0) { $where_auto = " $this->table_name.deleted=0 "; } else if ($show_deleted == 1) { $where_auto = " $this->table_name.deleted=1 "; } if ($where != "") $query .= "where $where AND " . $where_auto; else $query .= "where " . $where_auto; if (substr_count ( $order_by, '.' ) > 0) { $query .= " ORDER BY $order_by"; } else if ($order_by != "") $query .= " ORDER BY $order_by"; else $query .= " ORDER BY ecmagreements.name"; return $query; } function create_export_query($order_by, $where) { $custom_join = $this->custom_fields->getJOIN (); $query = "SELECT ecmagreements.*, users.user_name assigned_user_name"; if ($custom_join) { $query .= $custom_join ['select']; } $query .= " FROM ecmagreements "; $query .= " LEFT JOIN users ON ecmagreements.assigned_user_id=users.id"; if ($custom_join) { $query .= $custom_join ['join']; } $query .= ""; $where_auto = " ecmagreements.deleted=0 "; if ($where != "") $query .= " where $where AND " . $where_auto; else $query .= " where " . $where_auto; if ($order_by != "") $query .= " ORDER BY $order_by"; else $query .= " ORDER BY ecmagreements.name"; return $query; } function fill_in_additional_list_fields() { } function fill_in_additional_detail_fields() { // FILL IN THE ASSIGNED_USER_NAME $this->assigned_user_name = get_assigned_user_name ( $this->assigned_user_id ); $this->created_by_name = get_assigned_user_name ( $this->created_by ); $this->modified_by_name = get_assigned_user_name ( $this->modified_user_id ); /* $result = $this->db->query ( "SELECT status, parent_id, contact_id, template_id, assigned_user_id FROM ecmagreements WHERE id='$this->id'" ); if (is_resource ( $result )) { $row = $this->db->fetchByAssoc ( $result ); if ($row) { $this->status = $row ['status']; $this->parent_id = $row ['parent_id']; $this->contact_id = $row ['contact_id']; $this->template_id = $row ['template_id']; $this->assigned_user_id = $row ['assigned_user_id']; } } */ /* * $query = "select `number`, `template_id` from `ecmagreements` where `id`='$this->id' limit 1"; $r = $this->db->query($query); if($r) { $r = $this->db->fetchByAssoc($r); $this->template_id = $r['template_id']; $this->number = $r['number']; $this->setTemplate(); $this->document_no = $this->formatNumber(); } */ } function get_list_view_data() { global $current_language; $this->fill_in_additional_detail_fields (); $app_list_strings = return_app_list_strings_language ( $current_language ); $mod_strings = return_module_language ( $current_language, 'EcmAgreements' ); $the_array = parent::get_list_view_data (); // THE NEW LISTVIEW CODE ONLY FETCHES COLUMNS THAT WE'RE DISPLAYING AND NOT ALL // THE COLUMNS SO WE NEED THESE CHECKS. $this->retrieve($this->id); $the_array ['NAME'] = (($this->name == "") ? "blank" : $this->name); $the_array ['PARENT_NAME']=''.$this->parent_name.''; //$the_array ['TOTAL'] = format_number ( $this->total_netto ); //create image options $the_array['TOTAL_TOTAL']=number_format($this->total_total,2,",","."); $op = ''; $the_array['OPTIONS'] = $op; return $the_array; } function getStatusMenuInfo($inJSON = true) { global $app_list_strings; $arr = array (); foreach ( $app_list_strings ['ecmagreements_status_dom'] as $key => $value ) { $arr [$key] = array ( 'enabled' => '
' . $value . '
', 'disabled' => '
' . $value . '
' ); } $json = getJSONobj (); if ($inJSON) return str_replace ( '"', '\"', $json->encode ( $arr ) ); else return $arr; } function create_new_list_query($order_by, $where, $filter = array(), $params = array(), $show_deleted = 0, $join_type = '', $return_array = false, $parentbean, $singleSelect = false) { echo ''; echo ''; echo ''; echo ''; return parent::create_new_list_query ( $order_by, $where, $filter, $params, $show_deleted, $join_type, $return_array, $parentbean, $singleSelect ); } static function CreateImgStatus($id, $status) { global $app_list_strings; return ''; } /** * BUILDS A GENERIC SEARCH BASED ON THE QUERY STRING USING OR. * DO NOT INCLUDE ANY $THIS-> BECAUSE THIS IS CALLED ON WITHOUT HAVING THE CLASS INSTANTIATED. */ function build_generic_where_clause($the_query_string) { $where_clauses = Array (); $the_query_string = PearDatabase::quote ( from_html ( $the_query_string ) ); array_push ( $where_clauses, "ecmagreements.name like '$the_query_string%'" ); $the_where = ""; foreach ( $where_clauses as $clause ) { if ($the_where != "") $the_where .= " or "; $the_where .= $clause; } return $the_where; } function set_notification_body($xtpl, $simplemodule) { global $mod_strings, $app_list_strings; $xtpl->assign ( "NAME", $simplemodule->name ); $xtpl->assign ( "DESCRIPTION", $simplemodule->description ); return $xtpl; } function bean_implements($interface) { switch ($interface) { case 'ACL' : return true; } return false; } function getWithdraw($array = false){ if (isset($this->id) && $this->id != '') { $query = "SELECT * FROM ecmagreement_withdraws WHERE ecmagreement_id='" . $this->id . "'"; $r = $this->db->query($query); $return_array = array(); if ($r) { while ($w = $this->db->fetchByAssoc($r)) { $return_array [] = $w; } $json = getJSONobj(); return $array ? $return_array : $json->encode($return_array); } } return $array ? false : '[]'; } function saveWithdraw($pl) { global $current_user; $exists = array(); if ($this->id != '') { $GLOBALS['db']->query("delete FROM ecmagreement_withdraws WHERE ecmagreement_id='" . $this->id . "'"); } $positon = 0; foreach ($pl as $p) { //insert new record $id = create_guid(); $t = array( $id, $this->id, addslashes($p['date']), addslashes($p['amount']), addslashes($p['forma']), addslashes($p['number']), ); $q = "INSERT INTO ecmagreement_withdraws VALUES ('" . implode("','", $t) . "')"; $positon++; $GLOBALS['db']->query($q); $exists[] = $id; } //delete old // $GLOBALS['db']->query("UPDATE accounts_websites SET deleted='1', modified_user_id='".$current_user->id."',date_modified = '".date("Y-m-d H:i:s")."' WHERE account_id='".$this->id."' AND id NOT IN ('".implode("','",$exists)."')"); } function save($check_notify = FALSE) { global $current_user; require_once('modules/EcmSysInfos/EcmSysInfo.php'); $EcmSysInfo = new EcmSysInfo(); $template = $EcmSysInfo->getFormatNumberForModule('EcmAgreements'); $this->type='normal'; unset($EcmSysInfo); if (! $this->id || $this->id == '') { // generate number if ($template != "") { require_once('include/ECM/EcmDocumentNumberGenerator/EcmDocumentNumberGenerator.inc.php'); $dng = new EcmDocumentNumberGenerator('EcmAgreements'); $this->document_no= $dng->parseNormalNumber($template, $this->stock_id); } } if ($_REQUEST ['is_correct'] != '') { if ($template != "") { require_once('include/ECM/EcmDocumentNumberGenerator/EcmDocumentNumberGenerator.inc.php'); $dng = new EcmDocumentNumberGenerator('EcmAgreements'); $this->document_no = $dng->parseCorrectNumber($template); } } $wplatyID = explode(',', $_POST['formaWplatyTable_rowOrder']); $wplaty = array(); foreach ($wplatyID as $value) { $wplaty[$value]['date'] =date("Y-m-d", strtotime($_POST['formaWplatyTable_date_' . $value.'_date'])); $wplaty[$value]['amount'] = $_POST['formaWplatyTable_amount_' . $value]; $wplaty[$value]['forma'] = $_POST['formaWplatyTable_forma_' . $value]; $wplaty[$value]['number'] = $_POST['formaWplatyTable_number_' . $value]; } if (!$this->id || $this->id=='') { // generate number $this->number = $this->generateNumber(); //$this->document_no = $this->formatNumber($this->number); } if($_REQUEST['is_correct']!=''){ $this->number = $this->generateNumberCorrect(); $this->document_no = $this->formatNumberCorrect($this->number); $this->ecmagreement_id=$this->id; $r = $this->db->query ( "select document_no from ecmagreements where id='".$this->id."'" ); $w = $this->db->fetchByAssoc ( $r ); $this->ecmagreement_name=$w['document_no']; $this->id=null; } $this->vats_summary = htmlspecialchars($this->vats_summary); $return_id = parent::save ( $check_notify ); $this->saveWithdraw($wplaty); $this->savePositions($return_id); return $return_id; } function calculateCorrectTotals($id){ $vats_summary=''; $total_netto=0; $total_brutto=0; $total_vat=0; $res= $GLOBALS ['db']->query ("select ROUND(sum(total_netto_corrected),2) AS total_netto,ROUND(sum((total_netto_corrected*ecmvat_value)/100),2) AS total_vat, ROUND(sum(((total_netto_corrected*ecmvat_value)/100)+total_netto_corrected),2) AS total_brutto,ecmvat_value from ecmagreementitems where ecmagreement_id='".$id."' group by ecmvat_id"); while($cc = $GLOBALS ['db']->fetchByAssoc ($res)){ $total_netto+=$cc['total_netto']; $total_brutto+=$cc['total_brutto']; $total_vat+=$cc['total_vat']; $vats_summary.=$cc['ecmvat_value'].'%:'.$cc['total_netto'].':'.$cc['total_vat'].':'.$cc['total_brutto'].','; } $res= $GLOBALS ['db']->query ("update ecmagreements set vats_summary='".$vats_summary."',total_netto='".$total_netto."',total_vat='".$total_vat."', total_brutto='".$total_brutto."' where id='".$id."'"); } function calculateTotals($id){ $vats_summary=''; $total_netto=0; $total_brutto=0; $total_vat=0; $res= $GLOBALS ['db']->query ("select ROUND(sum(total_netto),2) AS total_netto,ROUND(sum((total_netto*ecmvat_value)/100),2) AS total_vat, ROUND(sum(((total_netto*ecmvat_value)/100)+total_netto),2) AS total_brutto,ecmvat_value from ecmagreementitems where ecmagreement_id='".$id."' group by ecmvat_id"); while($cc = $GLOBALS ['db']->fetchByAssoc ($res)){ $total_netto+=$cc['total_netto']; $total_brutto+=$cc['total_brutto']; $total_vat+=$cc['total_vat']; $vats_summary.=$cc['ecmvat_value'].'%:'.$cc['total_netto'].':'.$cc['total_vat'].':'.$cc['total_brutto'].','; } $res= $GLOBALS ['db']->query ("update ecmagreements set vats_summary='".$vats_summary."',total_netto='".$total_netto."',total_vat='".$total_vat."', total_brutto='".$total_brutto."' where id='".$id."'"); } // ***************************Start Managing Positions*************************// function constructInsertQuery($data, $table = '') { if ($table == '' && isset ( $this->object_name ) && $this->object_name != '') { $table = strtolower ( $this->object_name ) . "items"; } else return ""; $keys = array (); $values = array (); foreach ( $data as $key => $value ) { $keys [] = $key; if (is_array ( $value )) $values [] = $value [1] . str_replace ( "'", "\'", $value [0] ) . $value [1]; else $values [] = "'" . str_replace ( "'", "\'", $value ) . "'"; } $q = "insert into `$table` (`"; $q .= implode ( '`, `', $keys ); $q .= "`) values ("; $q .= implode ( ", ", $values ); $q .= ");"; return $q; } function savePositions($id = null, $position_list = null) { global $current_user, $timedate; if ($position_list == null) $position_list = $this->position_list; if ($id == null) $id = $this->id; if (count ( $position_list ) > 0) $this->deleteAssignedPositions ( $id ); $arr = array (); $position = 0; $counter=0; for($i = 0; $i < count ( $position_list ); $i ++) { if ($position_list [$i] ['payment_date'] == '') continue; $p = $position_list [$i]; $arr = array ( 'id' => create_guid (), 'date_entered' => array ( 'NOW()', '' ), 'date_modified' => array ( 'NOW()', '' ), 'modified_user_id' => $current_user->id, 'assigned_user_id' => $current_user->id, 'created_by' => $current_user->id, 'deleted' => '0', strtolower ( $this->object_name ) . '_id' => $id, 'position' => $counter, 'payment_date' => date("Y-m-d",strtotime($p ['payment_date'])), 'saldo' => $p ['saldo'], 'principal_value' => ((empty ( $p ['principal_value'] ) || $p ['principal_value'] == '') ? 0 : $p ['principal_value']), 'interest_rate' => ((empty ( $p ['interest_rate'] ) || $p ['interest_rate'] == '') ? 0 : $p ['interest_rate']), 'rate_of_commission' => ((empty ( $p ['rate_of_commission'] ) || $p ['rate_of_commission'] == '') ? 0 : $p ['rate_of_commission']), 'total' => ((empty ( $p ['total'] ) || $p ['total'] == '') ? 0 : $p ['total']), ); // odsetki if($p['interest_rate']>0){ $this->saveTransaction($this->id,$p['interest_rate'],$p ['payment_date'],'Odsetki do umowy: '); } if($p['principal_value']>0){ $this->saveTransaction($this->id,$p['principal_value'],$p ['payment_date'],'Rata kapitałowa do umowy: '); } if($p['rate_of_commission']>0){ $this->saveTransaction($this->id,$p['rate_of_commission'],$p ['payment_date'],'Prowizja do umowy: '); } $this->db->query ( $this->constructInsertQuery ( $arr ) ); $counter ++; } } function saveTransaction($id,$total_brutto,$payment_date,$title) { global $current_user; $t = new EcmTransaction (); $t->name = $title.' '.$this->document_no; $t->record_type = 'EcmAgreements'; $t->record_id=$id; $t->created_by = $current_user->id; $t->deleted = 0; $t->assigned_user_id = $this->assigned_user_id; $t->parent_name = $this->parent_name; $t->parent_id = $this->parent_id; $t->payment_date =$payment_date; $t->type = 0; $t->register_date = $this->register_date; $t->currency_id = 'PLN'; $t->currency_value = $this->currency_value; $t->value = $total_brutto; $t->save (true); } function getCorrectedPosition($position,$type) { $query = "SELECT * FROM `" . strtolower ( $this->object_name ) . "items` WHERE `id`='" . $position. "' order by position asc"; $r = $this->db->query ( $query ); $return_array = array (); if ($r) { while ( $position = $this->db->fetchByAssoc ( $r ) ) { if (! is_array ( $position )) return ''; global $timedate; $return_array = array (); $return_array ['product_id'] = $position ['ecmproduct_id']; $return_array ['position'] = $position ['position']; $return_array ['product_code'] = $position ['code']; $return_array ['name'] = $position ['name']; $return_array ['quantity'] = $position ['quantity']; $return_array ['price_start'] = $position ['price_start']; $return_array ['price_netto'] = $position ['price_netto']; $return_array ['discount'] = $position ['discount']; $return_array ['total_netto'] = $position ['total_netto']; $return_array ['unit_id'] = $position ['dd_unit_id']; $return_array ['unit_name'] = $position ['dd_unit_name']; $return_array ['ecmvat_id'] = $position ['ecmvat_id']; $return_array ['ecmvat_name'] = $position ['ecmvat_name']; $return_array ['ecmvat_value'] = $position ['ecmvat_value']; $return_array ['recipient_code'] = $position ['recipient_code']; $return_array ['remarks'] = $position ['remarks']; $return_array['old_ecmagreementitem_id'] = $position['old_ecmagreementitem_id']; $return_array ['old_total_netto'] = $position ['old_total_netto']; $return_array ['old_total_brutto'] = $position ['old_total_brutto']; $return_array ['old_quantity'] = $position ['old_quantity']; $return_array ['old_total_vat'] = $position ['old_total_vat']; $return_array ['ecmagreementitem_id'] = $position ['ecmagreementitem_id']; $return_array ['total_vat']=$position['total_vat']; $return_array ['total_brutto']=$position['total_brutto']; if ($type == "true") { $return_array ['product_item_id'] = $position ['id']; $return_array ['product_item'] = "true"; // get values from previous corrects $cc = $GLOBALS ['db']->fetchByAssoc ( $GLOBALS ['db']->query ( "SELECT ii.id,ii.price_start, ii.price_netto, ii.quantity, ii.discount, ii.ecmvat_value, ii.ecmvat_id, ii.ecmvat_name FROM ecmagreementitems as ii INNER JOIN ecmagreements AS i ON i.id=ii.ecmagreement_id WHERE i.canceled is null and ii.ecmagreementitem_id='" . $position ['id'] . "' ORDER BY ii.date_entered DESC LIMIT 0,1" ) ); if ($cc ['price_netto']) { $return_array ['price_start'] = $cc ['price_start']; $return_array ['price_netto'] = $cc ['price_netto']; $return_array ['quantity'] = $cc ['quantity']; $return_array ['discount'] = $cc ['discount']; $return_array ['ecmvat_value'] = $cc ['ecmvat_value']; $return_array ['ecmvat_id'] = $cc ['ecmvat_id']; $return_array ['ecmvat_name'] = $cc ['ecmvat_name']; $return_array ['product_itemold_id'] = $cc ['id']; } } else { $return_array ['product_item_id'] = $position ['ecmagreementitem_id']; } if ($type == "1") { $return_array ['product_item_id'] = $position ['id']; $return_array ['product_item'] = "false"; // get values from previous corrects $cc = $GLOBALS ['db']->fetchByAssoc ( $GLOBALS ['db']->query ( "SELECT ii.id,ii.price_start, ii.price_netto, ii.quantity, ii.discount, ii.ecmvat_value, ii.ecmvat_id, ii.ecmvat_name FROM ecmagreementitems as ii INNER JOIN ecmagreements AS i ON i.id=ii.ecmagreement_id WHERE i.canceled is null and ii.ecmagreementitem_id='" . $position ['id'] . "' ORDER BY ii.date_entered DESC LIMIT 0,1" ) ); if ($cc ['price_netto']) { $return_array ['price_start'] = $cc ['price_start']; $return_array ['price_netto'] = $cc ['price_netto']; $return_array ['quantity'] = $cc ['quantity']; $return_array ['discount'] = $cc ['discount']; $return_array ['ecmvat_value'] = $cc ['ecmvat_value']; $return_array ['ecmvat_id'] = $cc ['ecmvat_id']; $return_array ['ecmvat_name'] = $cc ['ecmvat_name']; $return_array ['product_itemold_id'] = $cc ['id']; } } else { $return_array ['product_item_id'] = $position ['ecmagreementitem_id']; } } } return $return_array; } function getPosition($position,$type) { if (! is_array ( $position )) return ''; global $timedate; $return_array = array (); $return_array ['position'] = $position ['position']; $return_array ['payment_date'] = $position ['payment_date']; $return_array ['saldo'] = $position ['saldo']; $return_array ['total'] = $position ['total']; $return_array ['interest_rate'] = $position ['interest_rate']; $return_array ['rate_of_commission'] = $position ['rate_of_commission']; $return_array ['principal_value'] = $position ['principal_value']; return $return_array; } function getPositionList($array = false,$type = "no") { if (isset ( $this->id ) && $this->id != '') { $query = "SELECT * FROM `" . strtolower ( $this->object_name ) . "items` WHERE `" . strtolower ( $this->object_name ) . "_id`='" . $this->id . "' order by position asc"; $r = $this->db->query ( $query ); $return_array = array (); if ($r) { while ( $w = $this->db->fetchByAssoc ( $r ) ) { $return_array [] = $this->getPosition ( $w,$type ); } $json = getJSONobj (); return $array ? $return_array : $json->encode ( $return_array ); } } return $array ? false : '[]'; } function deleteAssignedPositions() { if (isset ( $this->id ) && $this->id != '') { $query = "DELETE FROM `" . strtolower ( $this->object_name ) . "items` WHERE `" . strtolower ( $this->object_name ) . "_id`='" . $this->id . "'"; $r = $this->db->query ( $query ); if ($r) return true; } return false; } function formatPositions($position_list) { return; if (! is_array ( $position_list ) || count ( $position_list ) == 0) return false; global $app_list_strings; require_once ('modules/Currencies/Currency.php'); foreach ( $position_list as $key => $value ) { $position_list [$key] ['unit_id'] = $app_list_strings ['ecmproducts_unit_dom'] [$value ['unit_id']]; $position_list [$key] ['category_id'] = $app_list_strings ['ecmproducts_category_dom'] [$value ['category_id']]; // $position_list[$key]['vat_id'] = format_number($value['vat_id']).'%'; $position_list [$key] ['discount'] = format_number ( $value ['discount'] ) . '%'; if (isset ( $currency ) && ($currency->id == $this->currency_id)) { } else { $currency = new Currency (); $currency->retrieve ( $this->currency_id ); } $position_list [$key] ['price'] = format_number ( $value ['price'] ) . ' ' . $currency->iso4217; $position_list [$key] ['total'] = format_number ( $value ['total'] ) . ' ' . $currency->iso4217; // $position_list[$key]['price'] = format_number($value['price']).' PLN'; // $position_list[$key]['total'] = format_number($value['total']).' PLN'; $this->currency_symbol = $currency->iso4217; } return $position_list; } // ***************************End Managing Positions*************************// function ACLAccess($view, $is_owner = 'not_set') { global $current_user; $file = 'modules/EcmGroupSales/EcmGroupSale.php'; if (file_exists ( $file )) { require_once ($file); $cc = EcmGroupSale::loadSettings ( true ); } else return true; if (is_admin ( $current_user )) { switch ($view) { case 'confirming' : return ($this->status == "s20"); case 'send_to_confirm' : return ($this->status == "s10"); case 'pdf_toolbar' : return ($this->status != "s10" && $this->status != "s20" && $this->status != "s40"); } return true; } if ($is_owner == 'not_set') { $is_owner = $this->isOwner ( $current_user->id ); } // if we don't implent acls return true if (! $this->bean_implements ( 'ACL' )) return true; $view = strtolower ( $view ); if ($cc ['user_manager_role']) { // Manager switch ($view) { case 'list' : case 'index' : case 'listview' : return ACLController::checkAccess ( $this->module_dir, 'list', true ); case 'edit' : case 'save' : case 'popupeditview' : case 'editview' : return (ACLController::checkAccess ( $this->module_dir, 'edit', $is_owner )); case 'view' : case 'detail' : case 'detailview' : return ACLController::checkAccess ( $this->module_dir, 'view', $is_owner ); case 'delete' : return ACLController::checkAccess ( $this->module_dir, 'delete', $is_owner ); case 'export' : return ACLController::checkAccess ( $this->module_dir, 'export', $is_owner ); case 'import' : return ACLController::checkAccess ( $this->module_dir, 'import', true ); case 'send_to_confirm' : return ($this->status == "s10"); case 'can_commit' : return true; case 'confirming' : return ($this->status == "s20"); case 'auto_commiting' : return true; case 'pdf_toolbar' : return ($this->status != "s10" && $this->status != "s20" && $this->status != "s40"); } } else if ($cc ['user_representative_extra_role']) { // Representative Extra switch ($view) { case 'list' : case 'index' : case 'listview' : return ACLController::checkAccess ( $this->module_dir, 'list', true ); case 'edit' : return (ACLController::checkAccess ( $this->module_dir, 'edit', $is_owner ) && ($this->status == "s10" || $this->status == "s40")); case 'save' : case 'popupeditview' : case 'editview' : return (ACLController::checkAccess ( $this->module_dir, 'edit', $is_owner )); case 'view' : case 'detail' : case 'detailview' : return ACLController::checkAccess ( $this->module_dir, 'view', $is_owner ); case 'delete' : return (ACLController::checkAccess ( $this->module_dir, 'delete', $is_owner ) && $this->status == "s10"); case 'export' : return ACLController::checkAccess ( $this->module_dir, 'export', $is_owner ); case 'import' : return ACLController::checkAccess ( $this->module_dir, 'import', true ); case 'quote_to_sale' : case 'quote_to_invoice' : return ($this->status != "s10" && $this->status != "s20" && $this->status != "s40" && $this->status != "s60"); case 'send_to_confirm' : return ($this->status == "s10"); case 'send_email' : return ($this->status != "s10" && $this->status != "s20" && $this->status != "s40"); case 'can_commit' : return true; case 'confirming' : return false; case 'auto_commiting' : return true; case 'pdf_toolbar' : return ($this->status != "s10" && $this->status != "s20" && $this->status != "s40"); } } else if ($cc ['user_representative_role']) { // Representative switch ($view) { case 'list' : case 'index' : case 'listview' : return ACLController::checkAccess ( $this->module_dir, 'list', true ); case 'edit' : return (ACLController::checkAccess ( $this->module_dir, 'edit', $is_owner ) && ($this->status == "s10" || $this->status == "s40")); case 'save' : case 'popupeditview' : case 'editview' : return (ACLController::checkAccess ( $this->module_dir, 'edit', $is_owner )); case 'view' : case 'detail' : case 'detailview' : return ACLController::checkAccess ( $this->module_dir, 'view', $is_owner ); case 'delete' : return (ACLController::checkAccess ( $this->module_dir, 'delete', $is_owner ) && $this->status == "s10"); case 'export' : return ACLController::checkAccess ( $this->module_dir, 'export', $is_owner ); case 'import' : return ACLController::checkAccess ( $this->module_dir, 'import', true ); case 'quote_to_sale' : case 'quote_to_invoice' : return ($this->status != "s10" && $this->status != "s20" && $this->status != "s40" && $this->status != "s60"); case 'send_to_confirm' : return ($this->status == "s10"); case 'send_email' : return ($this->status != "s10" && $this->status != "s20" && $this->status != "s40"); case 'can_commit' : return false; case 'confirming' : return false; case 'auto_commiting' : return false; case 'pdf_toolbar' : return ($this->status != "s10" && $this->status != "s20" && $this->status != "s40"); } } // if it is not one of the above views then it should be implemented on the page level return true; } //mz generate number function generateNumber($stock_id) { $db = $GLOBALS['db']; $r = $db->fetchByAssoc($db->query("SELECT count(id) as c FROM ecmagreements WHERE deleted='0' AND YEAR(register_date)='".date('Y')."'")); if (!$r || !$r['c'] || $r['c']=='') $count = 0; else $count = intval($r['c']); $count++; //has 5 digits? $tmp = strval($count); while (strlen($tmp) < 5) $tmp = '0'.$tmp; return date("Ymd").$tmp; } function generateNumberCorrect() { $db = $GLOBALS['db']; $r = $db->fetchByAssoc($db->query("SELECT count(id) as c FROM ecmagreements WHERE deleted='0' AND YEAR(register_date)='".date('Y')."' and type='correct'")); if (!$r || !$r['c'] || $r['c']=='') $count = 0; else $count = intval($r['c']); $count++; //has 5 digits? $tmp = strval($count); while (strlen($tmp) < 5) $tmp = '0'.$tmp; return date("Ymd").$tmp; } function formatNumber($number,$stock_id) { $db = $GLOBALS['db']; $n = intval(substr($number, 8,5)); $y = substr($number,0,4); //has 3 digits? while (strlen($n) < 3) $n = '0'.$n; return ''.$n.'/'.$y; } function formatNumberCorrect($number) { $n = intval(substr($number, 8,5)); $y = substr($number,0,4); //has 3 digits? while (strlen($n) < 3) $n = '0'.$n; return 'FKKOR '.$n.'/'.$y; } public static function get_parse_fields_for_pdf(){ global $mod_strings; $parser_fields = array( 'document_no' => $mod_strings['LBL_DOCUMENT_NO'], 'parent_name' => $mod_strings['LBL_PARENT_NAME'], 'register_date' => $mod_strings['LBL_REGISTER_DATE'], 'parent_address_street' => $mod_strings['LBL_PARENT_ADDRESS_STREET'], 'parent_address_city' => $mod_strings['LBL_PARENT_ADDRESS_CITY_SS'], 'parent_address_postalcode' => $mod_strings['LBL_PARENT_ADDRESS_POSTALCODE'], 'parent_address_country' => $mod_strings['LBL_PARENT_ADDRESS_COUNTRY'], 'parent_nip' => $mod_strings['LBL_PARENT_NIP'], 'parent_regon' => $mod_strings['LBL_PARENT_REGON'], 'number_of_installments' => $mod_strings['LBL_NUMBER_OF_INSTALLMENTS'], 'date_end' => $mod_strings['LBL_DATE_END'], 'pagebreak' => 'Wstaw stronę PDF', ); return $parser_fields; } } ?>