fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [9265] bkbooking: added log file to aggresso export


From: Kjell Arne Espedal
Subject: [Fmsystem-commits] [9265] bkbooking: added log file to aggresso export
Date: Wed, 02 May 2012 14:00:46 +0000

Revision: 9265
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=9265
Author:   kjell
Date:     2012-05-02 14:00:34 +0000 (Wed, 02 May 2012)
Log Message:
-----------
bkbooking: added log file to aggresso export

Modified Paths:
--------------
    trunk/booking/inc/class.socompleted_reservation_export.inc.php
    trunk/booking/inc/class.socompleted_reservation_export_file.inc.php
    trunk/booking/inc/class.uicompleted_reservation_export_file.inc.php
    trunk/booking/setup/phpgw_no.lang
    trunk/booking/setup/setup.inc.php
    trunk/booking/setup/tables_current.inc.php
    trunk/booking/setup/tables_update.inc.php

Modified: trunk/booking/inc/class.socompleted_reservation_export.inc.php
===================================================================
--- trunk/booking/inc/class.socompleted_reservation_export.inc.php      
2012-05-02 10:40:21 UTC (rev 9264)
+++ trunk/booking/inc/class.socompleted_reservation_export.inc.php      
2012-05-02 14:00:34 UTC (rev 9265)
@@ -13,6 +13,11 @@
                
                function __construct()
                {
+                       $this->event_so = CreateObject('booking.soevent');
+                       $this->allocation_bo = 
CreateObject('booking.boallocation');
+                       $this->booking_bo = CreateObject('booking.bobooking');
+                       $this->event_bo = CreateObject('booking.boevent');
+                       $this->organization_bo = 
CreateObject('booking.boorganization');
                        $this->customer_id = 
CreateObject('booking.customer_identifier');
                        $this->completed_reservation_so = 
CreateObject('booking.socompleted_reservation');
                        $this->completed_reservation_bo = 
CreateObject('booking.bocompleted_reservation');
@@ -596,7 +601,10 @@
                        //$orders = array();
                        $export_info = array();
                        $output = array();
+                       $log = array();
 
+                       $log[] = 'Ordrenr;Kunde navn - Nummer;Varelinjer med 
dato;Bygg;Beløp';
+
                        /* NOTE: The specification states that values of type 
date
                         * should be left padded with spaces. The example file,
                         * however, is right padded with spaces.
@@ -640,13 +648,22 @@
                        $stored_header = array();                       
                        $line_no = 0;
             $header_count = 0;
+                       $log_order_id = '';
+                       $log_customer_name = '';
+                       $log_customer_nr = '';
+                       $log_buidling = '';
+                       
+                       $internal = false;
+
                        foreach($reservations as &$reservation) {
+
                                if ($this->get_cost_value($reservation['cost']) 
<= 0) {
                                        continue; //Don't export costless rows
                                }
+
                                $type = $reservation['customer_type'];
-
-                               if (($stored_header == array()) || 
($stored_header['tekst2'] != 
$this->get_customer_identifier_value_for($reservation)))
+       
+                               if ($stored_header == array() || 
$stored_header['tekst2'] != 
$this->get_customer_identifier_value_for($reservation))
                                {
                                        $order_id = 
$sequential_number_generator->increment()->get_current();
                                        $export_info[] = 
$this->create_export_item_info($reservation, $order_id);
@@ -682,13 +699,13 @@
                                        }
                                
                                        //Nøkkelfelt, kundens personnr/orgnr.
+                                       $stored_header['tekst2'] = 
$this->get_customer_identifier_value_for($reservation);
+
                            if ($type == 'internal') {
                                                $header['tekst2'] = 
str_pad(substr($config->config_data['organization_value'], 0, 12), 12, ' ');
-                                               $stored_header['tekst2'] = 
$config->config_data['organization_value'];
                                                $header['ext_ord_ref'] = 
str_pad(substr($this->get_customer_identifier_value_for($reservation), 0, 15), 
15, ' ');
                            } else {
                                                $header['tekst2'] = 
str_pad(substr($this->get_customer_identifier_value_for($reservation), 0, 12), 
12, ' ');
-                                               $stored_header['tekst2'] = 
$this->get_customer_identifier_value_for($reservation);
                            }
 
                                        $header['line_no'] = '0000'; //Nothing 
here according to example file but spec. says so
@@ -793,6 +810,39 @@
                                        $output[] = implode('', 
str_replace(array("\n", "\r"), '', $item));
                                        $output[] = implode('', 
str_replace(array("\n", "\r"), '', $text));
 
+                                       $log_order_id = $order_id;
+
+                           if ($type == 'internal') {
+                                               $log_customer_nr = 
$header['tekst2'].' '.$header['ext_ord_ref'];
+                                       } else {
+                                               $log_customer_nr = 
$header['tekst2'];
+                                       }
+                                       
if(!empty($reservation['organization_id'])) {
+                                               $org = 
$this->organization_bo->read_single($reservation['organization_id']);           
                 
+                                               $log_customer_name = 
$org['name'];
+                                       } else {
+                                               $data = 
$this->event_so->get_org($reservation['customer_organization_number']);
+                                               if(!empty($data['id'])) {
+                                                       $log_customer_name = 
$data['name'];
+                                               } else {
+                                                       
if($reservation['reservation_type'] == 'event') {
+                                                               $data = 
$this->event_bo->read_single($reservation['reservation_id']);
+                                                               
$log_customer_name = $data['contact_name'];
+#                                                      } elseif 
($reservation['reservation_type'] == 'booking') {
+#                                                              $data = 
$this->booking_bo->read_single($reservation['reservation_id']);
+#                                                              
error_log('b'.$data['id']." ".$data['group_id']);
+#                                                      } else {
+#                                                              $data = 
$this->allocation_bo->read_single($reservation['reservation_id']);
+#                                                              
error_log('a'.$data['id']." ".$data['organization_id']);
+                                                       }
+                                               }
+                                       }
+
+                                       $log_buidling = 
$reservation['building_name'];
+                                       $log_cost = $reservation['cost'];
+                                       $log_varelinjer_med_dato = 
$reservation['article_description'].' - '.$reservation['description'];
+
+                                       $log[] = 
$log_order_id.';'.$log_customer_name.' - 
'.$log_customer_nr.';'.$log_varelinjer_med_dato.';'.$log_buidling.';'.$log_cost;
                                } else {
 
                                        //item level
@@ -872,6 +922,12 @@
                                        //$orders[] = array('header' => 
$header, 'items' => array('item' => $item, 'text' => $text));
                                        $output[] = implode('', 
str_replace(array("\n", "\r"), '', $item));
                                        $output[] = implode('', 
str_replace(array("\n", "\r"), '', $text));
+
+                                       $log_cost = $reservation['cost'];
+                                       $log_varelinjer_med_dato = 
$reservation['article_description'].' - '.$reservation['description'];
+
+                                       $log[] = 
$log_order_id.';'.$log_customer_name.' - 
'.$log_customer_nr.';'.$log_varelinjer_med_dato.';'.$log_buidling.';'.$log_cost;
+
                                }
                        }
                        
@@ -879,7 +935,7 @@
                                return null;
                        }
                
-                       return array('data' => implode("\n", $output), 'info' 
=> $export_info, 'header_count' => $header_count);
+                       return array('data' => implode("\n", $output), 
'data_log' => implode("\n", $log), 'info' => $export_info, 'header_count' => 
$header_count);
                }
                
                protected function get_agresso_row_template() {

Modified: trunk/booking/inc/class.socompleted_reservation_export_file.inc.php
===================================================================
--- trunk/booking/inc/class.socompleted_reservation_export_file.inc.php 
2012-05-02 10:40:21 UTC (rev 9264)
+++ trunk/booking/inc/class.socompleted_reservation_export_file.inc.php 
2012-05-02 14:00:34 UTC (rev 9265)
@@ -24,6 +24,7 @@
                                        'id'                            => 
array('type' => 'int'),
                                        'type'                  => array('type' 
=> 'string', 'required' => true, 'query' => true),
                                        'filename'              => array('type' 
=> 'string'),
+                                       'log_filename'          => array('type' 
=> 'string'),
                                        'total_cost'    => array('type' => 
'decimal', 'required' => true),
                                        'total_items'   => array('type' => 
'int', 'required' => true),
                                        key(booking_socommon::$AUTO_CREATED_ON) 
=> current(booking_socommon::$AUTO_CREATED_ON),
@@ -71,6 +72,14 @@
                        
                        return null;
                }
+
+               public function get_logfile($entity_file) {
+                       if (isset($entity_file['log_filename']) && 
!empty($entity_file['log_filename'])) {
+                               return 
$this->file_storage->get($entity_file['log_filename']);
+                       }
+                       
+                       return null;
+               }
                
                public function 
associate_reservation_with_export_file($reservation_id, $export_file_id, 
$invoice_order_id) {
                        
$this->so_completed_reservation->associate_with_export_file($reservation_id, 
$export_file_id, $invoice_order_id);
@@ -121,15 +130,16 @@
                                                if 
(!is_null($export_result['export'])) {
                                                        
$export_infos[$export_type][] = $export_result['export']['info'];       
                                                }
+
                         if ($export_type == 'external') {
                                                        
$export_result['total_items'] = $export_result['export']['header_count'];       
+                                                       $export_log = 
$export_result['export']['data_log'];     
                         }
                                                
                                                
$export_configurations[$export_type][$export['id']] = $conf;
                                                $total_items[$export_type] += 
$export_result['total_items'];
                                                $total_cost[$export_type] += 
$export_result['total_cost'];
                                        }
-                                       
                                        $export_data[$export_type] = 
$this->combine_export_result_data($export_results[$export_type]);
                                }
                                
@@ -147,23 +157,29 @@
                                        $entity_export_file['id'] = 
$receipt['id'];
                                
                                        $entity_export_file['filename'] = 
'export_'.$export_type.'_'.$entity_export_file['id'].'.'.$this->file_type_for_export_type($export_type);
-                               
                                        $export_file = new 
booking_storage_object($entity_export_file['filename']);
                                        $export_files[] = $export_file;
                                        
                                        
$export_file->set_data($export_data[$export_type]);
-                                       
+                       
                                        
$this->file_storage->attach($export_file)->persist();
-
+                                            
+                    if ($export_type == 'external') {
+                                       $entity_export_file['log_filename'] = 
'log_'.$export_type.'_'.$entity_export_file['id'].'.csv';
+                                       $log_export_file = new 
booking_storage_object($entity_export_file['log_filename']);
+                                       $log_export_files[] = $log_export_file;
+                                       $log_export_file->set_data($export_log);
+                                       
$this->file_storage->attach($log_export_file)->persist();
+                    }
                                        $this->update($entity_export_file); 
//Save the generated file name
                                        
$entity_export_files[$entity_export_file['id']] = $entity_export_file;
                                
                                        
foreach($export_configurations[$export_type] as $export_id => $conf) {
-                                               $export_conf_updates[] = 
sprintf(
-                                                       "UPDATE 
bb_completed_reservation_export_configuration SET export_file_id=%s WHERE 
id=%s",
-                                                       
$entity_export_file['id'],
-                                                       $conf['id']
-                                               );
+                                       $export_conf_updates[] = sprintf(
+                                               "UPDATE 
bb_completed_reservation_export_configuration SET export_file_id=%s WHERE 
id=%s",
+                                               $entity_export_file['id'],
+                                               $conf['id']
+                                       );
                                        }
                                        
                                        $associated_reservation_count = 0;

Modified: trunk/booking/inc/class.uicompleted_reservation_export_file.inc.php
===================================================================
--- trunk/booking/inc/class.uicompleted_reservation_export_file.inc.php 
2012-05-02 10:40:21 UTC (rev 9264)
+++ trunk/booking/inc/class.uicompleted_reservation_export_file.inc.php 
2012-05-02 14:00:34 UTC (rev 9265)
@@ -9,6 +9,7 @@
                        'show'                  =>      true,
                        'add'                           => true,
                        'download'      => true,
+                       'log'   => true,
                        'upload'        => true,
                );
 
@@ -52,6 +53,7 @@
                        $export_file['created_on'] = 
pretty_timestamp($export_file['created_on']);
                        $export_file['index_link'] = $this->link_to('index');
                        $export_file['download_link'] = 
$this->link_to('download', array('id' => $export_file['id']));
+                       $export_file['log_link'] = $this->link_to('log', 
array('id' => $export_file['id']));
                }
                
                public function index()
@@ -121,6 +123,12 @@
                                                        'sortable' => false,
                                                ),
                                                array(
+                                                       'key' => 'log',
+                                                       'label' => 
lang('Logfile'),
+                                                       'formatter' => 
'YAHOO.booking.formatGenericLink()',
+                                                       'sortable' => false,
+                                               ),
+                                               array(
                                                        'key' => 'link',
                                                        'hidden' => true
                                                ),
@@ -147,6 +155,17 @@
                                        'label' => lang('Download'), 
                                        'href' => $this->link_to('download', 
array('id' => $export_file['id']))
                                );
+                if ($export_file['total_items'] > 0 and $export_file['id'] > 
$config->config_data['invoice_last_id'] and 
!empty($export_file['log_filename'])) {
+                               $export_file['log'] = array(
+                                       'label' => lang('log'), 
+                                       'href' => $this->link_to('log', 
array('id' => $export_file['id']))
+                               );
+                } else {
+                                       $export_file['log'] = array(
+                                               'label' => ' ', 
+                                               'href' => '#'
+                                       );
+                }
                                if ($export_file['total_items'] > 0 and 
$export_file['id'] > $config->config_data['invoice_last_id'])
                                {
                                        $export_file['upload'] = array(
@@ -189,6 +208,17 @@
                        
                        $this->send_file($file->get_system_identifier(), 
array('filename' => $file->get_identifier()));
                }
+               public function log() {
+                       $export_file = 
$this->bo->read_single(phpgw::get_var('id', 'GET'));
+                       
+                       if (!is_array($export_file)) {
+                               $this->redirect_to('index');
+                       }
+                       
+                       $file = $this->bo->get_logfile($export_file);
+                       
+                       $this->send_file($file->get_system_identifier(), 
array('filename' => $file->get_identifier()));
+               }
                public function upload() {
                        $id = phpgw::get_var('id', 'GET');
                        $export_file = 
$this->bo->read_single(phpgw::get_var('id', 'GET'));

Modified: trunk/booking/setup/phpgw_no.lang
===================================================================
--- trunk/booking/setup/phpgw_no.lang   2012-05-02 10:40:21 UTC (rev 9264)
+++ trunk/booking/setup/phpgw_no.lang   2012-05-02 14:00:34 UTC (rev 9265)
@@ -550,3 +550,5 @@
 Billing sequence numbers       booking no      Sekvensnummer for fakturering
 Do not change these values unless you know what they are.      booking no      
Ikke endre disse verdiene med mindre du vet hva de er.
 Organization is missing booking charge booking no      Organisasjonen mangler 
bookingansvarlig
+Logfile        booking no      Logfil
+log    booking no      Last ned

Modified: trunk/booking/setup/setup.inc.php
===================================================================
--- trunk/booking/setup/setup.inc.php   2012-05-02 10:40:21 UTC (rev 9264)
+++ trunk/booking/setup/setup.inc.php   2012-05-02 14:00:34 UTC (rev 9265)
@@ -1,6 +1,6 @@
 <?php
        $setup_info['booking']['name'] = 'booking';
-       $setup_info['booking']['version'] = '0.2.08';
+       $setup_info['booking']['version'] = '0.2.09';
        $setup_info['booking']['app_order'] = 9;
        $setup_info['booking']['enable'] = 1;
        $setup_info['booking']['app_group'] = 'office';

Modified: trunk/booking/setup/tables_current.inc.php
===================================================================
--- trunk/booking/setup/tables_current.inc.php  2012-05-02 10:40:21 UTC (rev 
9264)
+++ trunk/booking/setup/tables_current.inc.php  2012-05-02 14:00:34 UTC (rev 
9265)
@@ -640,6 +640,7 @@
                        'fd' => array(
                                'id'                                            
        => array('type' => 'auto', 'nullable' => False),
                                'filename'                                      
=> array('type' => 'text'),
+                               'log_filename'                                  
=> array('type' => 'text'),
                                'type'                                  => 
array('type' => 'text', 'nullable' => False),
                                'total_cost'                            => 
array('type' => 'decimal','precision' => '10', 'scale'=>'2', 'nullable' => 
False),
                                'total_items'                           => 
array('type' => 'int','precision' => '4','nullable' => False),

Modified: trunk/booking/setup/tables_update.inc.php
===================================================================
--- trunk/booking/setup/tables_update.inc.php   2012-05-02 10:40:21 UTC (rev 
9264)
+++ trunk/booking/setup/tables_update.inc.php   2012-05-02 14:00:34 UTC (rev 
9265)
@@ -2615,5 +2615,23 @@
                }
        }
 
+       $test[] = '0.2.08';
+       /**
+       * Update booking version from 0.2.08 to 0.2.09
+       * add log file name to completed_reservation_export_file
+       * 
+       */
+       function booking_upgrade0_2_08()
+       {
+               $GLOBALS['phpgw_setup']->oProc->m_odb->transaction_begin();
 
+               $GLOBALS['phpgw_setup']->oProc->m_odb->query("ALTER TABLE 
bb_completed_reservation_export_file ADD COLUMN log_filename text");
+       
+               if($GLOBALS['phpgw_setup']->oProc->m_odb->transaction_commit())
+               {
+                       $GLOBALS['setup_info']['booking']['currentver'] = 
'0.2.09';
+                       return $GLOBALS['setup_info']['booking']['currentver'];
+               }
+       }
 
+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]